From 64af745244caa793b7522b6bcae39824a58d3581 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 29 Jun 2025 16:56:28 +0330 Subject: [PATCH] update kuber doc --- .../Kubernetes/components/5-hpa.md | 67 ++++++++++++++++ .../Kubernetes/components/6-DaemonSet.md | 40 ++++++++++ .../Kubernetes/node-manage.md | 77 ++++++++++++------- 3 files changed, 155 insertions(+), 29 deletions(-) create mode 100644 Containerization & Orchestration/Kubernetes/components/5-hpa.md create mode 100644 Containerization & Orchestration/Kubernetes/components/6-DaemonSet.md diff --git a/Containerization & Orchestration/Kubernetes/components/5-hpa.md b/Containerization & Orchestration/Kubernetes/components/5-hpa.md new file mode 100644 index 0000000..ffa1844 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/components/5-hpa.md @@ -0,0 +1,67 @@ +# πŸ“ˆ Horizontal Pod Autoscaler (HPA) + +The Horizontal Pod Autoscaler automatically scales the number of pods in a deployment based on observed CPU utilization (or other select metrics). + +--- + +## βš™οΈ Basic Commands + +### πŸš€ Create an HPA +Create an HPA for a deployment, scaling based on CPU usage: + +```bash +kubectl -n autoscale deployment --cpu-percent=20 --min=4 --max=10 +```` + +### πŸ“Š View Existing HPAs + +List all HPAs in a specific namespace: + +```bash +kubectl get hpa -n +``` + +### ❌ Delete an HPA + +Remove a Horizontal Pod Autoscaler: + +```bash +kubectl delete hpa -n +``` + +### πŸ› οΈ Edit an HPA + +Manually edit an existing HPA configuration: + +```bash +kubectl edit hpa -n +``` + +--- + +## 🧾 Example HPA Manifest + +You can define an HPA using a YAML file for more control: + +```yaml +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: hpa-test + namespace: dev +spec: + minReplicas: 1 + maxReplicas: 10 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 +``` + +> ℹ️ **Note:** The above manifest uses API version `autoscaling/v2` for enhanced metric support. + +--- + diff --git a/Containerization & Orchestration/Kubernetes/components/6-DaemonSet.md b/Containerization & Orchestration/Kubernetes/components/6-DaemonSet.md new file mode 100644 index 0000000..3664ae8 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/components/6-DaemonSet.md @@ -0,0 +1,40 @@ +# 🧩 DaemonSet in Kubernetes + +A **DaemonSet** ensures that a copy of a specific pod runs on **every (or some) node** in the cluster. It’s typically used for background system-level services like log collection, monitoring, or networking tools. + +--- + +## πŸ“Œ Key Characteristics + +- Automatically deploys one pod per worker node. +- Ensures the pod stays on each node as long as the DaemonSet exists. +- Automatically adds pods to new nodes when they join the cluster. + +--- + +## πŸ“„ Example DaemonSet YAML + +Below is a simple DaemonSet example that deploys `nginx` to every node in the `web` namespace: + +```yaml +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: nginx + namespace: web + labels: + app: web-servers +spec: + selector: + matchLabels: + app: web-servers + template: + metadata: + labels: + app: web-servers + spec: + containers: + - name: nginx + image: nginx:1.27 +```` + diff --git a/Containerization & Orchestration/Kubernetes/node-manage.md b/Containerization & Orchestration/Kubernetes/node-manage.md index 2472b09..f877634 100644 --- a/Containerization & Orchestration/Kubernetes/node-manage.md +++ b/Containerization & Orchestration/Kubernetes/node-manage.md @@ -1,44 +1,63 @@ +# 🌐 Node Management with Kubernetes -## Node Management +Efficient management of Kubernetes nodes ensures cluster stability and workload flexibility. Below are key commands for listing and maintaining nodes. -### Listing Nodes +--- -- **Show All Nodes** +## πŸ“‹ Listing Nodes + +### πŸ”Ή Show All Nodes +```bash +kubectl get nodes +```` + +### πŸ”Ή Show Nodes with Labels + +```bash +kubectl get nodes --show-labels +``` + +--- + +## πŸ”§ Node Maintenance (Cordon / Drain) + +### 🚫 Cordon a Node + +Prevent new pods from being scheduled on the node. + +```bash +kubectl cordon +``` + +### βœ… Uncordon a Node + +Mark the node as schedulable again. + +```bash +kubectl uncordon +``` + +### 🧹 Drain a Node + +Evict all pods from the node (excluding those managed by DaemonSets). + +* Forcefully drain the node: ```bash - kubectl get nodes + kubectl drain --ignore-daemonsets --force ``` - - ```bash - kubectl get nodes --show-lables - ``` - -### Node Maintenance (Cordon/Drain) - -- **Cordon a Node** - Prevent new pods from being scheduled on the node. - - ```bash - kubectl cordon - ``` - -- **Uncordon a Node** - Mark the node as schedulable again. - - ```bash - kubectl uncordon - ``` - -- **Drain a Node** - Evict all pods from the node (excluding those managed by DaemonSets). +* Drain and delete local data: ```bash kubectl drain --ignore-daemonsets --delete-local-data ``` - > **Warning:** Draining a node will evict running pods. Ensure that you plan this action to avoid service disruption. +#### πŸ”„ Undo Drain (Uncordon) +```bash +kubectl uncordon +``` ---- +> ⚠️ **Warning:** Draining a node will evict running pods. Ensure that this is planned to avoid service disruption.