From 9f661b1335958abc55789732750138bc546204ba Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Jun 2025 22:56:20 +0330 Subject: [PATCH] update kubernetes doc --- .../Kubernetes/components/2-Pod.md | 87 ++++++++++---- .../Kubernetes/components/3-Replicaset.md | 80 +++++++++++++ .../Kubernetes/components/4-Deployment.md | 107 ++++++++++++++++++ 3 files changed, 252 insertions(+), 22 deletions(-) create mode 100644 Containerization & Orchestration/Kubernetes/components/4-Deployment.md diff --git a/Containerization & Orchestration/Kubernetes/components/2-Pod.md b/Containerization & Orchestration/Kubernetes/components/2-Pod.md index 6b77500..f5c0bf9 100644 --- a/Containerization & Orchestration/Kubernetes/components/2-Pod.md +++ b/Containerization & Orchestration/Kubernetes/components/2-Pod.md @@ -1,64 +1,107 @@ +# ๐ŸŒ Kubernetes Pod Management Guide -## Pod Management +A concise guide for managing Kubernetes Pods using `kubectl` and YAML manifests. -### Listing Pods +--- -- **List Pods in the Default Namespace** +## ๐Ÿ“‹ Listing Pods - ```bash - kubectl get pods - ``` +### ๐Ÿ”น Default Namespace -- **List Pods with Detailed Information (Wide Output)** +List all Pods in the **default** namespace: - ```bash - kubectl get pods -o wide - ``` +```bash +kubectl get pods +``` -- **List Pods in a Specific Namespace** +### ๐Ÿ”น Wide Output (More Info) - ```bash - kubectl get pods -o wide -n - ``` +List Pods with extended details (e.g., IP, node, etc.): -### Running a Pod +```bash +kubectl get pods -o wide +``` -> **Note:** The `kubectl run` command is best suited for running single pods. For more complex deployments, consider using YAML manifests. +### ๐Ÿ”น Specific Namespace +List Pods in a specific namespace: + +```bash +kubectl get pods -o wide -n +``` + +--- + +## ๐Ÿš€ Running a Pod + +> **Note:** `kubectl run` is ideal for quick tests or running **single** Pods. For production workloads, use **YAML manifests** or **Deployments**. + +### ๐Ÿ”น Run a Pod in Default Namespace ```bash kubectl run --image= ``` +### ๐Ÿ”น Run a Pod in a Specific Namespace + ```bash kubectl run --image= -n ``` +--- + +## โŒ Deleting Pods + +### ๐Ÿ”น Standard Delete ```bash kubectl delete pod -n ``` +### ๐Ÿ”น Force Delete ```bash kubectl delete pod -n --force ``` +### ๐Ÿ”น Immediate Force Delete (No Grace Period) ```bash -kubectl delete pod -n --force --grace-period 0 +kubectl delete pod -n --force --grace-period=0 ``` +--- + +## โœ๏ธ Editing a Pod + +> **Warning:** Pods are **not directly editable**. Attempting to edit a running pod will result in a temporary patch but not persistent changes. + ```bash -kubectl edit pod -n +kubectl edit pod -n ``` -Pod Can not been edit (not editable) +--- + +## ๐Ÿ”ง Executing into a Pod + +Use this to start a shell or run commands inside a container: ```bash -kubectl exec -it -n -- +kubectl exec -it -n -- ``` +Example for a shell: + +```bash +kubectl exec -it -n dev my-pod -- /bin/bash +``` + +--- + +## ๐Ÿงพ Example Pod YAML Manifest + +A multi-container Pod with resource limits and node selector: + ```yaml apiVersion: v1 kind: Pod @@ -74,13 +117,13 @@ spec: containers: - name: nginx-server image: nginx - + - name: nginx-exporter image: nginx-exporter - name: ubuntu-c0 image: ubuntu - command: ["/bin/bash","-c","while true; do echo hello-world; sleep 5; done"] + command: ["/bin/bash", "-c", "while true; do echo hello-world; sleep 5; done"] resources: limits: memory: "256Mi" diff --git a/Containerization & Orchestration/Kubernetes/components/3-Replicaset.md b/Containerization & Orchestration/Kubernetes/components/3-Replicaset.md index e69de29..13f8bbd 100644 --- a/Containerization & Orchestration/Kubernetes/components/3-Replicaset.md +++ b/Containerization & Orchestration/Kubernetes/components/3-Replicaset.md @@ -0,0 +1,80 @@ +# ๐Ÿงฉ Kubernetes ReplicaSet Management + +A guide to working with **ReplicaSets** in Kubernetes, including inspection, editing behavior, and configuration examples. + +--- + +## ๐Ÿ“ฆ Listing Pods and ReplicaSets + +### ๐Ÿ”น List Pods in a Namespace + +```bash +kubectl get pod -n +``` + +### ๐Ÿ”น List ReplicaSets in a Namespace + +```bash +kubectl get rs -n +``` + +--- + +## โœ๏ธ Editing a ReplicaSet + +You can attempt to edit a ReplicaSet: + +```bash +kubectl edit rs -n +``` + +> โš ๏ธ **Note:** +> Editing the **image** in a ReplicaSet directly will not automatically update existing Pods. +> This is because ReplicaSets do not perform **rolling updates**. +> Pods will only use the new image **after the old ones are deleted and new ones are created**. + +**To apply image changes effectively:** + +1. **Delete existing Pods** manually: + + ```bash + kubectl delete pod -l -n + ``` + +2. **Or**, use a higher-level controller like a **Deployment** for image updates and rolling behavior. + +--- + +## ๐Ÿงพ Example ReplicaSet YAML + +Below is a minimal and clear ReplicaSet configuration: + +```yaml +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: app-1 + namespace: dev + labels: + label1: test1 + app.kubernetes.io/label2: test2 +spec: + replicas: 3 + selector: + matchLabels: + app.kubernetes.io/label2: test2 + template: + metadata: + labels: + app.kubernetes.io/label2: test2 + os: linux + spec: + containers: + - name: nginx + image: nginx +``` + +> โœ… **Tip:** +> Ensure that the `template.metadata.labels` **matches exactly** with `spec.selector.matchLabels`. +> This is critical for proper ReplicaSet Pod matching. + diff --git a/Containerization & Orchestration/Kubernetes/components/4-Deployment.md b/Containerization & Orchestration/Kubernetes/components/4-Deployment.md new file mode 100644 index 0000000..3654a78 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/components/4-Deployment.md @@ -0,0 +1,107 @@ +# ๐Ÿš€ Kubernetes Deployment Management + +A guide to managing **Deployments** in Kubernetes, including listing, editing, scaling, rollbacks, and version history. + +--- + +## ๐Ÿ“‹ Listing & Editing Deployments + +### ๐Ÿ”น List Deployments in a Namespace + +```bash +kubectl get deploy -n +``` + +### ๐Ÿ”น Edit a Deployment + +```bash +kubectl edit deployment.apps -n +``` + +> ๐Ÿ› ๏ธ **Note:** +> Unlike ReplicaSets, Deployments **automatically update** existing Pods when the image or spec is changed. This makes Deployments ideal for rolling updates and version control. + +--- + +## ๐Ÿ“ˆ Scaling a Deployment + +Scale the number of replicas (Pods) for a Deployment: + +```bash +kubectl scale -n deployment --replicas= +``` + +--- + +## ๐Ÿ” Rollout Management + +### ๐Ÿ”น View Rollout History + +```bash +kubectl rollout history deployment -n +``` + +### ๐Ÿ”น View Specific Revision + +```bash +kubectl rollout history deployment -n --revision= +``` + +### ๐Ÿ”น Roll Back to a Previous Revision + +```bash +kubectl rollout undo deployment -n --to-revision= +``` + +> โœ… **Tip:** +> Deployments maintain revision history. This allows you to **roll back to a previous working version** in case of failure. + +--- + +## ๐Ÿงพ Example Deployment YAML + +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-1 + namespace: dev + labels: + label1: test1 + app.kubernetes.io/label2: test2 +spec: + replicas: 3 + selector: + matchLabels: + app.kubernetes.io/label2: test2 + template: + metadata: + labels: + app.kubernetes.io/label2: test2 + os: linux + spec: + containers: + - name: nginx + image: nginx +``` + +> ๐ŸŽฏ **Why use Deployments?** +> They offer: + +* Rolling updates +* Rollbacks +* Declarative Pod management +* History tracking + +--- + +## โœ… Summary + +| Feature | Pod | ReplicaSet | Deployment | +| ---------------- | --- | ---------- | ---------- | +| Manual creation | โœ… | ๐Ÿšซ | ๐Ÿšซ | +| Scales Pods | โŒ | โœ… | โœ… | +| Self-healing | โŒ | โœ… | โœ… | +| Rolling updates | โŒ | โŒ | โœ… | +| Revision history | โŒ | โŒ | โœ… | +