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=apiExplanation
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
Pod Manifest
Define a standalone Pod with a container, env, and probe.
Deployment & Rollout
Manage a replicated, rolling-updated workload.
Service Types
Expose Pods via ClusterIP, NodePort, and LoadBalancer services.
ConfigMap & Secret
Inject configuration and sensitive data into containers.
Ingress Routing
Route external HTTP traffic to services by host and path.
Labels & Selectors
Tag resources and query them with selectors.