modified: README.md
This commit is contained in:
136
README.md
136
README.md
@@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
Kubernetes is an open‑source platform that automates the deployment, scaling, and management of containerized applications. It acts as an orchestrator, ensuring your containers run reliably across clusters of machines, handling networking, storage, and updates without downtime.
|
Kubernetes is an open‑source platform that automates the deployment, scaling, and management of containerized applications. It acts as an orchestrator, ensuring your containers run reliably across clusters of machines, handling networking, storage, and updates without downtime.
|
||||||
|
|
||||||
- [kubectl](#kubectl)
|
- [Namespaces](#namespaces)
|
||||||
- [Run a command inside a running Pod](#run-a-command-inside-a-running-pod)
|
- [Create namespace](#create-namespace)
|
||||||
|
- [Pods](#pods)
|
||||||
|
- [Create an pod](#create-an-pod)
|
||||||
- [Get Pod](#get-pod)
|
- [Get Pod](#get-pod)
|
||||||
- [Pod delete](#pod-delete)
|
- [delete Pod](#delete-pod)
|
||||||
- [OOMKilled](#oomkilled)
|
- [OOMKilled](#oomkilled)
|
||||||
- [Custom Resource Definitions](#custom-resource-definitions)
|
- [Attach to an pod](#attach-to-an-pod)
|
||||||
|
- [Run command on pod](#run-command-on-pod)
|
||||||
|
- [kubectl](#kubectl)
|
||||||
- [Helper pods](#helper-pods)
|
- [Helper pods](#helper-pods)
|
||||||
- [network testing](#network-testing)
|
- [network testing](#network-testing)
|
||||||
- [Set Replicas](#set-replicas)
|
- [Set Replicas](#set-replicas)
|
||||||
@@ -16,7 +20,6 @@ Kubernetes is an open‑source platform that automates the deployment, scaling,
|
|||||||
- [Resources](#resources)
|
- [Resources](#resources)
|
||||||
- [Persistent volumes claims](#persistent-volumes-claims)
|
- [Persistent volumes claims](#persistent-volumes-claims)
|
||||||
- [Services Accounts](#services-accounts)
|
- [Services Accounts](#services-accounts)
|
||||||
- [Namespaces](#namespaces)
|
|
||||||
- [Secrets](#secrets)
|
- [Secrets](#secrets)
|
||||||
- [Manifest - Opaque / Base64](#manifest---opaque--base64)
|
- [Manifest - Opaque / Base64](#manifest---opaque--base64)
|
||||||
- [Manifest - StringData](#manifest---stringdata)
|
- [Manifest - StringData](#manifest---stringdata)
|
||||||
@@ -32,6 +35,7 @@ Kubernetes is an open‑source platform that automates the deployment, scaling,
|
|||||||
- [service accounts](#service-accounts)
|
- [service accounts](#service-accounts)
|
||||||
- [core-dns](#core-dns)
|
- [core-dns](#core-dns)
|
||||||
- [Services DNS Name](#services-dns-name)
|
- [Services DNS Name](#services-dns-name)
|
||||||
|
- [Custom Resource Definitions](#custom-resource-definitions)
|
||||||
- [k3s](#k3s)
|
- [k3s](#k3s)
|
||||||
- [Install / Setup](#install--setup)
|
- [Install / Setup](#install--setup)
|
||||||
- [prune old images](#prune-old-images)
|
- [prune old images](#prune-old-images)
|
||||||
@@ -41,24 +45,51 @@ Kubernetes is an open‑source platform that automates the deployment, scaling,
|
|||||||
- [klipper-lb](#klipper-lb)
|
- [klipper-lb](#klipper-lb)
|
||||||
- [troubleshooting](#troubleshooting)
|
- [troubleshooting](#troubleshooting)
|
||||||
|
|
||||||
## kubectl
|
## Namespaces
|
||||||
|
|
||||||
kubectl is the command‑line tool used to interact with Kubernetes clusters. Think of it as the “remote control” for Kubernetes: it lets you deploy applications, inspect resources, and manage cluster operations directly from your terminal.
|
### Create namespace
|
||||||
|
|
||||||
**Create namespace:**
|
Using cli
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
kubectl create namespace tests
|
kubectl create namespace tests
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run a command inside a running Pod
|
Or using yaml
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: namespace-name
|
||||||
|
labels:
|
||||||
|
name: namespace-name
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pods
|
||||||
|
|
||||||
|
### Create an pod
|
||||||
|
|
||||||
|
Create an ubuntu pod for tty access example:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
# sh
|
apiVersion: v1
|
||||||
kubectl exec -it ${POD_NAME} -- sh
|
kind: Pod
|
||||||
|
metadata:
|
||||||
# bash
|
name: ubuntu-test
|
||||||
kubectl exec -it ${POD_NAME} -- bash
|
namespace: tests
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: ubuntu-test
|
||||||
|
image: ubuntu
|
||||||
|
# In Kubernetes, the pod stays alive as long as PID 1 is running.
|
||||||
|
# so with this options:
|
||||||
|
# - It does not exit automatically.
|
||||||
|
# - It waits for user input forever.
|
||||||
|
# - It behaves like an interactive shell session.
|
||||||
|
command: ["sh"] # PID 1 = interactive shell
|
||||||
|
stdin: true # keep STDIN open
|
||||||
|
tty: true # allocate a terminal
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get Pod
|
### Get Pod
|
||||||
@@ -66,8 +97,7 @@ kubectl exec -it ${POD_NAME} -- bash
|
|||||||
**Get pod name by label ap:**
|
**Get pod name by label ap:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
POD_NAME=$(kubectl get pod -l app=borg-backup-sidekick -n git-limbosolutions-com -o jsonpath='{.items[0].metadata.name}')
|
POD_NAME=$(kubectl get pod -l app=myAppName -n appNamespace -o jsonpath='{.items[0].metadata.name}')
|
||||||
|
|
||||||
echo $POD_NAME
|
echo $POD_NAME
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -77,12 +107,10 @@ echo $POD_NAME
|
|||||||
kubectl get pods -A -o wide | grep 10.0.3.224
|
kubectl get pods -A -o wide | grep 10.0.3.224
|
||||||
```
|
```
|
||||||
|
|
||||||
### Pod delete
|
### delete Pod
|
||||||
|
|
||||||
**Restart local Path Provisioner:**
|
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
kubectl delete pod -n kube-system -l app=local-path-provisioner
|
kubectl delete pod -n appNamespace -l app=myAppName
|
||||||
```
|
```
|
||||||
|
|
||||||
### OOMKilled
|
### OOMKilled
|
||||||
@@ -99,20 +127,48 @@ kubectl get pods --all-namespaces \
|
|||||||
| grep OOMKilled
|
| grep OOMKilled
|
||||||
```
|
```
|
||||||
|
|
||||||
### Custom Resource Definitions
|
### Attach to an pod
|
||||||
|
|
||||||
- **Definition:** A Custom Resource Definition (CRD) is an extension of the Kubernetes API.
|
Attach connects your terminal to the main process of the container (PID 1), or another running process if specified.
|
||||||
|
|
||||||
- **Purpose:** They allow you to define new resource kinds (e.g., Database, Backup, FooBar) that behave like native Kubernetes objects.
|
Use it when you want to:
|
||||||
|
|
||||||
- **Analogy:** By default, Kubernetes understands objects like Pods and Services. With CRDs, you can add your own object types and manage them with kubectl just like built‑in resources
|
- see the raw output of the main process
|
||||||
|
- want to send input directly to the main process
|
||||||
**List traefik CRDS:**
|
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
kubectl get crds | grep traefik
|
kubectl attach -it myPodName -n appNamespace
|
||||||
```
|
```
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
POD_NAME=$(kubectl get pod -l app=myAppName -n appNamespace -o jsonpath='{.items[0].metadata.name}')
|
||||||
|
kubectl attach -it ${POD_NAME} -n appNamespace
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run command on pod
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# sh
|
||||||
|
POD_NAME=$(kubectl get pod -l app=myAppName -n appNamespace -o jsonpath='{.items[0].metadata.name}')
|
||||||
|
kubectl exec -it ${POD_NAME} -- sh
|
||||||
|
```
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# bash
|
||||||
|
POD_NAME=$(kubectl get pod -l app=myAppName -n appNamespace -o jsonpath='{.items[0].metadata.name}')
|
||||||
|
kubectl exec -it ${POD_NAME} -- bash
|
||||||
|
```
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# execute an command like ls
|
||||||
|
POD_NAME=$(kubectl get pod -l app=myAppName -n appNamespace -o jsonpath='{.items[0].metadata.name}')
|
||||||
|
kubectl exec -it ${POD_NAME} -- ls /
|
||||||
|
```
|
||||||
|
|
||||||
|
## kubectl
|
||||||
|
|
||||||
|
kubectl is the command‑line tool used to interact with Kubernetes clusters. Think of it as the “remote control” for Kubernetes: it lets you deploy applications, inspect resources, and manage cluster operations directly from your terminal.
|
||||||
|
|
||||||
### Helper pods
|
### Helper pods
|
||||||
|
|
||||||
#### network testing
|
#### network testing
|
||||||
@@ -237,17 +293,6 @@ kubectl get secret <secret_name> -o jsonpath='{.data.token}' | base64 -d > ./ser
|
|||||||
kubectl config view --raw -o jsonpath='{.clusters[0].cluster.certificate-authority-data}'
|
kubectl config view --raw -o jsonpath='{.clusters[0].cluster.certificate-authority-data}'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Namespaces
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Namespace
|
|
||||||
metadata:
|
|
||||||
name: namespace-name
|
|
||||||
labels:
|
|
||||||
name: namespace-name
|
|
||||||
```
|
|
||||||
|
|
||||||
## Secrets
|
## Secrets
|
||||||
|
|
||||||
### Manifest - Opaque / Base64
|
### Manifest - Opaque / Base64
|
||||||
@@ -418,6 +463,21 @@ data:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Custom Resource Definitions
|
||||||
|
|
||||||
|
- **Definition:** A Custom Resource Definition (CRD) is an extension of the Kubernetes API.
|
||||||
|
|
||||||
|
- **Purpose:** They allow you to define new resource kinds (e.g., Database, Backup, FooBar) that behave like native Kubernetes objects.
|
||||||
|
|
||||||
|
- **Analogy:** By default, Kubernetes understands objects like Pods and Services. With CRDs, you can add your own object types and manage them with kubectl just like built‑in resources
|
||||||
|
|
||||||
|
**List traefik CRDS:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get crds | grep traefik
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## k3s
|
## k3s
|
||||||
|
|
||||||
K3s is a lightweight, certified Kubernetes distribution designed to run in resource‑constrained environments such as edge devices, IoT appliances, and small servers. It simplifies installation and operation by packaging Kubernetes into a single small binary, while still being fully compliant with the Kubernetes API.
|
K3s is a lightweight, certified Kubernetes distribution designed to run in resource‑constrained environments such as edge devices, IoT appliances, and small servers. It simplifies installation and operation by packaging Kubernetes into a single small binary, while still being fully compliant with the Kubernetes API.
|
||||||
|
|||||||
Reference in New Issue
Block a user