Kubernetes
Kubernetes container orchestration platform basics and concepts
Overview
Kubernetes is an open-source container orchestration platform for automating deployment, scaling, and management of containerized applications.
Basic Concepts
| Concept | Description |
|---|
| Pod | Smallest deployable unit that can contain one or more containers |
| Node | Worker machine in the Kubernetes cluster |
| Cluster | Set of nodes that run containerized applications |
| Deployment | Manages the desired state for Pods and ReplicaSets |
| Service | Defines a logical set of Pods and a policy to access them |
| Namespace | Virtual cluster within a physical cluster |
Common Commands
| Command | Description |
|---|
kubectl get pods | List all pods in the current namespace |
kubectl apply -f file.yaml | Create or update resources from a file |
kubectl describe pod <pod-name> | Show detailed information about a pod |
kubectl logs <pod-name> | Print the logs from a container in a pod |
kubectl exec -it <pod-name> -- /bin/bash | Execute a command in a container |
1 - Port Forward Kubernetes
Cấu hình port forward tạo kết nối đến ứng dụng triển khai trên Kubernetes cluster
Syntax
NS=<namespace>; kubectl -n $NS port-forward $(kubectl -n $NS get pods -l app=<[production,staging,production-postgres,staging-postgres]> | awk 'NR==2{print$1}') <local_port>:<container_port>
- Ví dụ tạo kết nối đến DB staging của Collector
điền NS=collector-8148254 APP=staging-postgres
lệnh: NS=collector-8148254 APP=staging-postgres; kubectl -n $NS port-forward $(kubectl -n $NS get pods -l app=$APP | awk 'NR==2{print$1}') 5432:5432
- Tạo kết nối đế n ứng dụng collector staging để truy cập bằng localhost:8080
lệnh: NS=collector-8148254 APP=staging; kubectl -n $NS port-forward $(kubectl -n $NS get pods -l app=$APP | awk 'NR==2{print$1}') 8080:5000