update kuber to working
This commit is contained in:
@@ -79,4 +79,5 @@ The **Control Plane** is the core management component of a Kubernetes cluster.
|
|||||||
- **Worker (none)**
|
- **Worker (none)**
|
||||||
These nodes run application workloads and do not participate in control decisions.
|
These nodes run application workloads and do not participate in control decisions.
|
||||||
|
|
||||||
---
|
|
||||||
|
image pull policy in kubernetes:
|
||||||
|
|||||||
@@ -2,34 +2,6 @@
|
|||||||
|
|
||||||
This guide provides a concise reference for common `kubectl` commands used to manage Kubernetes clusters. Whether you’re managing nodes, namespaces, pods, deployments, or autoscaling, the examples below will help you perform everyday tasks with confidence.
|
This guide provides a concise reference for common `kubectl` commands used to manage Kubernetes clusters. Whether you’re managing nodes, namespaces, pods, deployments, or autoscaling, the examples below will help you perform everyday tasks with confidence.
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Table of Contents
|
|
||||||
|
|
||||||
- [Kubernetes Command Reference](#kubernetes-command-reference)
|
|
||||||
- [Table of Contents](#table-of-contents)
|
|
||||||
- [General Commands](#general-commands)
|
|
||||||
- [Node Management](#node-management)
|
|
||||||
- [Listing Nodes](#listing-nodes)
|
|
||||||
- [Labeling Nodes](#labeling-nodes)
|
|
||||||
- [Node Maintenance (Cordon/Drain)](#node-maintenance-cordondrain)
|
|
||||||
- [Namespace Management](#namespace-management)
|
|
||||||
- [Pod Management](#pod-management)
|
|
||||||
- [Listing Pods](#listing-pods)
|
|
||||||
- [Running a Pod](#running-a-pod)
|
|
||||||
- [Deleting a Pod](#deleting-a-pod)
|
|
||||||
- [API Resources \& Documentation](#api-resources--documentation)
|
|
||||||
- [Logs \& Pod Information](#logs--pod-information)
|
|
||||||
- [Applying YAML Files](#applying-yaml-files)
|
|
||||||
- [Viewing Cluster Resources](#viewing-cluster-resources)
|
|
||||||
- [ReplicaSet \& Deployment Management](#replicaset--deployment-management)
|
|
||||||
- [Scaling and Rollouts](#scaling-and-rollouts)
|
|
||||||
- [Autoscaling](#autoscaling)
|
|
||||||
- [Port Forwarding](#port-forwarding)
|
|
||||||
- [Additional Information](#additional-information)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## General Commands
|
## General Commands
|
||||||
|
|
||||||
- **List API Resources**
|
- **List API Resources**
|
||||||
@@ -40,136 +12,6 @@ This guide provides a concise reference for common `kubectl` commands used to ma
|
|||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Node Management
|
|
||||||
|
|
||||||
### Listing Nodes
|
|
||||||
|
|
||||||
- **Show All Nodes**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl get nodes
|
|
||||||
```
|
|
||||||
|
|
||||||
### Labeling Nodes
|
|
||||||
|
|
||||||
- **Set a Custom Label on a Node**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl label node <node-name> kubernetes.io/<label-key>=<label-value>
|
|
||||||
```
|
|
||||||
|
|
||||||
> **Note:** Replace `<node-name>`, `<label-key>`, and `<label-value>` with your desired values.
|
|
||||||
|
|
||||||
### Node Maintenance (Cordon/Drain)
|
|
||||||
|
|
||||||
- **Cordon a Node**
|
|
||||||
Prevent new pods from being scheduled on the node.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl cordon <node-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Uncordon a Node**
|
|
||||||
Mark the node as schedulable again.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl uncordon <node-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Drain a Node**
|
|
||||||
Evict all pods from the node (excluding those managed by DaemonSets).
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl drain <node-name> --ignore-daemonsets --delete-local-data
|
|
||||||
```
|
|
||||||
|
|
||||||
> **Warning:** Draining a node will evict running pods. Ensure that you plan this action to avoid service disruption.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Namespace Management
|
|
||||||
|
|
||||||
- **List All Namespaces**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl get namespaces
|
|
||||||
# Or the shorthand:
|
|
||||||
kubectl get ns
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Create a New Namespace**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl create namespace <namespace-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Pod Management
|
|
||||||
|
|
||||||
### Listing Pods
|
|
||||||
|
|
||||||
- **List Pods in the Default Namespace**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl get pods
|
|
||||||
```
|
|
||||||
|
|
||||||
- **List Pods with Detailed Information (Wide Output)**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl get pods -o wide
|
|
||||||
```
|
|
||||||
|
|
||||||
- **List Pods in a Specific Namespace**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl get pods -o wide -n <namespace-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Running a Pod
|
|
||||||
|
|
||||||
> **Note:** The `kubectl run` command is best suited for running single pods. For more complex deployments, consider using YAML manifests.
|
|
||||||
|
|
||||||
- **Basic Example:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl run <pod-name> --image=<image-name> --port=<port-number> -n <namespace-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Advanced Example with Multiple Options:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl run mypod --image=nginx --port=80 -n mynamespace \
|
|
||||||
--env="ENV_VAR_NAME=VALUE" --command -- nginx -g "daemon off;" \
|
|
||||||
--restart=Always --dry-run=client \
|
|
||||||
--labels="app=myapp,env=prod" \
|
|
||||||
--limits=cpu=100m,memory=256Mi --requests=cpu=50m,memory=128Mi
|
|
||||||
```
|
|
||||||
|
|
||||||
**Common Options Explained:**
|
|
||||||
|
|
||||||
- `--image`: Container image to use.
|
|
||||||
- `--port`: Port exposed by the container.
|
|
||||||
- `-n` or `--namespace`: Namespace in which to run the pod.
|
|
||||||
- `--env`: Set environment variables.
|
|
||||||
- `--command`: Treat the following arguments as the command to run.
|
|
||||||
- `--restart`: Pod restart policy (`Always`, `OnFailure`, or `Never`).
|
|
||||||
- `--labels`: Assign labels to the pod.
|
|
||||||
- `--dry-run`: Validate the command without creating the pod.
|
|
||||||
- `--limits` and `--requests`: Define resource limits and requests for the container.
|
|
||||||
|
|
||||||
### Deleting a Pod
|
|
||||||
|
|
||||||
- **Delete a Pod in a Specific Namespace**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl delete pod <pod-name> -n <namespace-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## API Resources & Documentation
|
## API Resources & Documentation
|
||||||
|
|
||||||
- **Get Detailed Documentation for an API Resource**
|
- **Get Detailed Documentation for an API Resource**
|
||||||
@@ -184,21 +26,10 @@ This guide provides a concise reference for common `kubectl` commands used to ma
|
|||||||
kubectl explain pod
|
kubectl explain pod
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Logs & Pod Information
|
|
||||||
|
|
||||||
- **Stream Logs for a Running Pod**
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kubectl logs -f -n <namespace-name> <pod-name>
|
kubectl explain pod.metadata
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Get Detailed Information About a Pod**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl describe pod <pod-name> -n <namespace-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -296,3 +127,4 @@ kubectl port-forward -n <namespace-name> svc/<service-name> <local-port>:<target
|
|||||||
- **Static Manifest Files**
|
- **Static Manifest Files**
|
||||||
Any YAML files placed in `/etc/kubernetes/manifests/` are automatically loaded when the kubelet starts (for example, after a server reboot).
|
Any YAML files placed in `/etc/kubernetes/manifests/` are automatically loaded when the kubelet starts (for example, after a server reboot).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
Containerization & Orchestration/Kubernetes/4-BasicSetup.md
Normal file
13
Containerization & Orchestration/Kubernetes/4-BasicSetup.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl complation <shell>
|
||||||
|
```
|
||||||
|
|
||||||
|
exapmles:
|
||||||
|
```bash
|
||||||
|
kubectl completion zsh > "${fpath[1]}/_kubectl"
|
||||||
|
```
|
||||||
|
```bash
|
||||||
|
kubectl completion bash > ~/.kube/completion.bash.inc
|
||||||
|
```
|
||||||
|
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
# Kubernetes Namespaces Guide
|
||||||
|
|
||||||
|
Kubernetes **namespaces** allow you to organize and isolate resources within your cluster.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧾 Listing Namespaces
|
||||||
|
|
||||||
|
To list all namespaces:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get namespaces
|
||||||
|
```
|
||||||
|
|
||||||
|
or the shorthand:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get ns
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Creating a Namespace
|
||||||
|
|
||||||
|
Create a new namespace:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl create namespace <namespace-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
or:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl create ns <namespace-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🗑️ Deleting a Namespace
|
||||||
|
|
||||||
|
Delete a namespace:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl delete ns <namespace-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ Best Practices & Notes
|
||||||
|
|
||||||
|
* **Namespaces are isolated**, but they **can still communicate** with each other by default.
|
||||||
|
* It is **not recommended to create namespaces that start with `kube-`**, as those are typically reserved for system components.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📄 Creating a Namespace with a Manifest
|
||||||
|
|
||||||
|
You can define a namespace using a YAML manifest:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: namespace-test
|
||||||
|
```
|
||||||
|
|
||||||
|
Apply it using:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl apply -f namespace.yaml
|
||||||
|
```
|
||||||
|
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
|
||||||
|
## Pod Management
|
||||||
|
|
||||||
|
### Listing Pods
|
||||||
|
|
||||||
|
- **List Pods in the Default Namespace**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get pods
|
||||||
|
```
|
||||||
|
|
||||||
|
- **List Pods with Detailed Information (Wide Output)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get pods -o wide
|
||||||
|
```
|
||||||
|
|
||||||
|
- **List Pods in a Specific Namespace**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get pods -o wide -n <namespace-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running a Pod
|
||||||
|
|
||||||
|
> **Note:** The `kubectl run` command is best suited for running single pods. For more complex deployments, consider using YAML manifests.
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl run <pod-name> --image=<image-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl run <pod-name> --image=<image-name> -n <namespace>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl delete pod <pod-name> -n <namespace-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl delete pod <pod-name> -n <namespace-name> --force
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl delete pod <pod-name> -n <namespace-name> --force --grace-period 0
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl edit pod -n <namepsace> <podname>
|
||||||
|
```
|
||||||
|
Pod Can not been edit (not editable)
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl exec -it -n <namespace> <podname> -- <command or shell>
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
namespace: dev
|
||||||
|
name: pod-1
|
||||||
|
labels:
|
||||||
|
label1: test
|
||||||
|
label2: test2
|
||||||
|
app.kubernetes.io/label3: test3
|
||||||
|
app.kubernetes.io/label4: test4
|
||||||
|
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"]
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: "256Mi"
|
||||||
|
cpu: "250m"
|
||||||
|
requests:
|
||||||
|
memory: "128Mi"
|
||||||
|
cpu: "125m"
|
||||||
|
nodeSelector:
|
||||||
|
hostname: k3s
|
||||||
|
app.kubernetes.io/disk: ssd
|
||||||
|
```
|
||||||
|
|
||||||
9
Containerization & Orchestration/Kubernetes/label.md
Normal file
9
Containerization & Orchestration/Kubernetes/label.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
- **Set a Custom Label on a Node**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl label node <node-name> kubernetes.io/<label-key>=<label-value>
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** Replace `<node-name>`, `<label-key>`, and `<label-value>` with your desired values.
|
||||||
|
|
||||||
|
|
||||||
27
Containerization & Orchestration/Kubernetes/log-debug.md
Normal file
27
Containerization & Orchestration/Kubernetes/log-debug.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
- **Stream Logs for a Running Pod**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl logs -f -n <namespace-name> <pod-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl logs -f -n <namespace-name> <pod-name> -c <container-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
- **Get Detailed Information About a Pod**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl describe pod <pod-name> -n <namespace-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
in log swith the pod need to be up
|
||||||
|
|
||||||
|
but in describe dont need to pod be up
|
||||||
|
|
||||||
|
describe work on all components
|
||||||
44
Containerization & Orchestration/Kubernetes/node-manage.md
Normal file
44
Containerization & Orchestration/Kubernetes/node-manage.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
## Node Management
|
||||||
|
|
||||||
|
### Listing Nodes
|
||||||
|
|
||||||
|
- **Show All Nodes**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```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 <node-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Uncordon a Node**
|
||||||
|
Mark the node as schedulable again.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl uncordon <node-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Drain a Node**
|
||||||
|
Evict all pods from the node (excluding those managed by DaemonSets).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl drain <node-name> --ignore-daemonsets --delete-local-data
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Warning:** Draining a node will evict running pods. Ensure that you plan this action to avoid service disruption.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ A curated collection of scripts, configuration files, and guides for managing an
|
|||||||
|
|
||||||
### 🐳 Containerization & Orchestration
|
### 🐳 Containerization & Orchestration
|
||||||
- [Docker](./Containerization%20&%20Orchestration/Docker)
|
- [Docker](./Containerization%20&%20Orchestration/Docker)
|
||||||
- [Kubernetes](./Containerization%20&%20Orchestration/Kubernetes)
|
- [Kubernetes(On Working)](./Containerization%20&%20Orchestration/Kubernetes)
|
||||||
|
|
||||||
### 🗄️ Databases
|
### 🗄️ Databases
|
||||||
- [Postgresql](./Databases/Postgresql)
|
- [Postgresql](./Databases/Postgresql)
|
||||||
|
|||||||
Reference in New Issue
Block a user