update kubernetes doc
This commit is contained in:
@@ -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
|
### 🔹 Default Namespace
|
||||||
kubectl get pods
|
|
||||||
```
|
|
||||||
|
|
||||||
- **List Pods with Detailed Information (Wide Output)**
|
List all Pods in the **default** namespace:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kubectl get pods -o wide
|
kubectl get pods
|
||||||
```
|
```
|
||||||
|
|
||||||
- **List Pods in a Specific Namespace**
|
### 🔹 Wide Output (More Info)
|
||||||
|
|
||||||
```bash
|
List Pods with extended details (e.g., IP, node, etc.):
|
||||||
kubectl get pods -o wide -n <namespace-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 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 <namespace-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 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
|
```bash
|
||||||
kubectl run <pod-name> --image=<image-name>
|
kubectl run <pod-name> --image=<image-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 🔹 Run a Pod in a Specific Namespace
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kubectl run <pod-name> --image=<image-name> -n <namespace>
|
kubectl run <pod-name> --image=<image-name> -n <namespace>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ❌ Deleting Pods
|
||||||
|
|
||||||
|
### 🔹 Standard Delete
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kubectl delete pod <pod-name> -n <namespace-name>
|
kubectl delete pod <pod-name> -n <namespace-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 🔹 Force Delete
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kubectl delete pod <pod-name> -n <namespace-name> --force
|
kubectl delete pod <pod-name> -n <namespace-name> --force
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 🔹 Immediate Force Delete (No Grace Period)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kubectl delete pod <pod-name> -n <namespace-name> --force --grace-period 0
|
kubectl delete pod <pod-name> -n <namespace-name> --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
|
```bash
|
||||||
kubectl edit pod -n <namepsace> <podname>
|
kubectl edit pod -n <namespace> <pod-name>
|
||||||
```
|
```
|
||||||
Pod Can not been edit (not editable)
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Executing into a Pod
|
||||||
|
|
||||||
|
Use this to start a shell or run commands inside a container:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kubectl exec -it -n <namespace> <podname> -- <command or shell>
|
kubectl exec -it -n <namespace> <pod-name> -- <command>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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
|
```yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
@@ -80,7 +123,7 @@ spec:
|
|||||||
|
|
||||||
- name: ubuntu-c0
|
- name: ubuntu-c0
|
||||||
image: ubuntu
|
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:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
memory: "256Mi"
|
memory: "256Mi"
|
||||||
|
|||||||
@@ -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 <namespace>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔹 List ReplicaSets in a Namespace
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get rs -n <namespace>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✏️ Editing a ReplicaSet
|
||||||
|
|
||||||
|
You can attempt to edit a ReplicaSet:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl edit rs -n <namespace> <replica-set-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
> ⚠️ **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 <label-selector> -n <namespace>
|
||||||
|
```
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|||||||
@@ -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 <namespace>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔹 Edit a Deployment
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl edit deployment.apps -n <namespace> <deployment-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
> 🛠️ **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 <namespace> deployment <deployment-name> --replicas=<number>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔁 Rollout Management
|
||||||
|
|
||||||
|
### 🔹 View Rollout History
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl rollout history deployment -n <namespace> <deployment-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔹 View Specific Revision
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl rollout history deployment -n <namespace> <deployment-name> --revision=<revision-number>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔹 Roll Back to a Previous Revision
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl rollout undo deployment -n <namespace> <deployment-name> --to-revision=<revision-number>
|
||||||
|
```
|
||||||
|
|
||||||
|
> ✅ **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 | ❌ | ❌ | ✅ |
|
||||||
|
|
||||||
Reference in New Issue
Block a user