Skip to content
Kubernetes

kubectl Basics

Common kubectl commands for everyday operations.

By EZ4Code Team
kubectlclioperations

Code

# Resources
kubectl get pods,svc,deploy -n default
kubectl get all -o wide

# Inspect
kubectl describe pod api-pod
kubectl explain pod.spec.containers

# Logs and exec
kubectl logs -f deployment/api
kubectl logs api-pod -c sidecar
kubectl exec -it api-pod -- sh

# Apply, scale, and patch
kubectl apply -f deploy.yaml
kubectl scale deployment api --replicas=5
kubectl patch deployment api -p '{"spec":{"replicas":3}}'

# Cleanup
kubectl delete -f deploy.yaml
kubectl delete pod,svc -l app=api

Explanation

kubectl is the primary CLI for talking to the Kubernetes API server. get lists resources, describe shows detailed state and events, and logs/exec interact with running containers. apply, scale, and patch mutate resources declaratively or imperatively.

More Kubernetes Snippets