modified: README.md

This commit is contained in:
2026-02-21 18:11:28 +00:00
parent 91b1f9b160
commit 1e60b6db08

136
README.md
View File

@@ -2,12 +2,16 @@
Kubernetes is an opensource 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)
- [Run a command inside a running Pod](#run-a-command-inside-a-running-pod)
- [Namespaces](#namespaces)
- [Create namespace](#create-namespace)
- [Pods](#pods)
- [Create an pod](#create-an-pod)
- [Get Pod](#get-pod)
- [Pod delete](#pod-delete)
- [delete Pod](#delete-pod)
- [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)
- [network testing](#network-testing)
- [Set Replicas](#set-replicas)
@@ -16,7 +20,6 @@ Kubernetes is an opensource platform that automates the deployment, scaling,
- [Resources](#resources)
- [Persistent volumes claims](#persistent-volumes-claims)
- [Services Accounts](#services-accounts)
- [Namespaces](#namespaces)
- [Secrets](#secrets)
- [Manifest - Opaque / Base64](#manifest---opaque--base64)
- [Manifest - StringData](#manifest---stringdata)
@@ -32,6 +35,7 @@ Kubernetes is an opensource platform that automates the deployment, scaling,
- [service accounts](#service-accounts)
- [core-dns](#core-dns)
- [Services DNS Name](#services-dns-name)
- [Custom Resource Definitions](#custom-resource-definitions)
- [k3s](#k3s)
- [Install / Setup](#install--setup)
- [prune old images](#prune-old-images)
@@ -41,24 +45,51 @@ Kubernetes is an opensource platform that automates the deployment, scaling,
- [klipper-lb](#klipper-lb)
- [troubleshooting](#troubleshooting)
## kubectl
## Namespaces
kubectl is the commandline 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
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
# sh
kubectl exec -it ${POD_NAME} -- sh
# bash
kubectl exec -it ${POD_NAME} -- bash
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-test
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
@@ -66,8 +97,7 @@ kubectl exec -it ${POD_NAME} -- bash
**Get pod name by label ap:**
```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
```
@@ -77,12 +107,10 @@ echo $POD_NAME
kubectl get pods -A -o wide | grep 10.0.3.224
```
### Pod delete
**Restart local Path Provisioner:**
### delete Pod
``` bash
kubectl delete pod -n kube-system -l app=local-path-provisioner
kubectl delete pod -n appNamespace -l app=myAppName
```
### OOMKilled
@@ -99,20 +127,48 @@ kubectl get pods --all-namespaces \
| 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 builtin resources
**List traefik CRDS:**
- see the raw output of the main process
- want to send input directly to the main process
``` 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 commandline 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
#### 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}'
```
## Namespaces
``` yaml
apiVersion: v1
kind: Namespace
metadata:
name: namespace-name
labels:
name: namespace-name
```
## Secrets
### 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 builtin resources
**List traefik CRDS:**
```bash
kubectl get crds | grep traefik
```
## k3s
K3s is a lightweight, certified Kubernetes distribution designed to run in resourceconstrained 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.