Managing Pods with Kubectl
Introduction to Kubectl
Kubectl is the primary command-line interface for managing Kubernetes clusters, enabling administrators and developers to interact with and control Kubernetes resources efficiently.
Basic Kubectl Pod Management Commands
graph LR
A[Kubectl Commands] --> B[Create]
A --> C[List]
A --> D[Describe]
A --> E[Delete]
Essential Kubectl Commands for Pod Management
Command |
Function |
Example |
kubectl create |
Create a new Pod |
kubectl create -f pod.yaml |
kubectl get pods |
List running Pods |
kubectl get pods |
kubectl describe pod |
Show detailed Pod information |
kubectl describe pod nginx-pod |
kubectl delete pod |
Remove a specific Pod |
kubectl delete pod nginx-pod |
Creating a Pod with Kubectl
Example Pod creation on Ubuntu 22.04:
## Create a Pod from YAML file
kubectl create -f nginx-pod.yaml
## Create a Pod directly from command line
kubectl run nginx-pod --image=nginx:latest
Viewing Pod Details
## List all Pods in current namespace
kubectl get pods
## List Pods with more details
kubectl get pods -o wide
## Show detailed Pod information
kubectl describe pod nginx-pod
Pod Interaction and Debugging
## Execute commands inside a Pod
kubectl exec nginx-pod -- ls /usr/share/nginx/html
## View Pod logs
kubectl logs nginx-pod
Managing Pod Lifecycle
Kubectl provides comprehensive commands to manage Pod lifecycle, from creation to deletion, ensuring flexible and precise container orchestration in Kubernetes environments.