kubectl
kubectl
(pronounced “cube control”, “kube cuddle”, or “kube C-T-L”) is the command-line tool used to interact with a Kubernetes cluster.
It allows you to deploy, manage, inspect, and troubleshoot applications and resources in Kubernetes.
Common Commands
Command | Description |
---|---|
kubectl get pods | List all pods in the current namespace |
kubectl get svc | List all services |
kubectl get nodes | List all nodes in the cluster |
kubectl describe pod <name> | Show detailed info about a specific pod |
kubectl logs <pod> | Show logs from a pod |
kubectl apply -f <file.yaml> | Apply configuration from a YAML file |
kubectl delete -f <file.yaml> | Delete resources defined in a YAML file |
kubectl exec -it <pod> -- bash | Open a shell inside a running pod |
kubectl scale deployment <name> --replicas=3 | Scale a deployment |
Common Flags
Flag | Usage Example | Purpose |
---|---|---|
-n or --namespace | kubectl get pods -n kube-system | Target a specific namespace |
-o | kubectl get pods -o wide | Output format (e.g., json , yaml , wide ) |
--watch | kubectl get pods --watch | Continuously watch for changes |
-f | kubectl apply -f config.yaml | Use a file (YAML or JSON) |
Example: Deploy an App
kubectl apply -f deployment.yaml
This might deploy a Deployment
and Service
defined in the YAML file.
Pro Tips
-
Use
kubectl explain <resource>
to learn what a resource is and its fields:kubectl explain pod.spec.containers
-
Use
kubectl get all
to get everything (pods, services, deployments, etc.).
Last updated on