Important K8S Commands
Senior DevOps Engineer with a strong background in configuration management and production support, experienced in AWS, Docker, Kubernetes, Terraform, Git, and Ansible. Skilled in automating workflows, optimizing system performance, and building scalable, secure cloud-based infrastructures
------Cluster Management------
# Switch cluster context
—>kubectl config use-context
# List all nodes
—>kubectl get nodes
# Mark node as unschedulable
—>kubectl cordon
# Safely evict all pods from a node
—>kubectl drain --ignore-daemonsets
# Mark node as schedulable again
—>kubectl uncordon
# Display CPU/memory usage for nodes
—>kubectl top nodes
# Show detailed node info
—>kubectl describe node
# Check control plane health
—>kubectl get componentstatus
-----Pod Management----
# List all pods
—>kubectl get pods
# List pods in a specific namespace
—>kubectl get pods -n
# Get detailed pod info
—>kubectl describe pod
# View logs of a pod
—>kubectl logs
# Stream logs (like tail -f)
—>kubectl logs -f
# Access pod shell (busybox/alpine)
—>kubectl exec -it -- sh
# Delete a pod
—>kubectl delete pod
# Show pod resource usage
—>kubectl top pod
# Restart all pods in deployment
—>kubectl rollout restart deployment
# View cluster-wide events
—>kubectl get events
----Deployments & Services------
# List deployments
—>kubectl get deployments
# Describe a deployment
—>kubectl describe deployment
# Scale deployment
—>kubectl scale deployment --replicas=3
# Check rollout status
—>kubectl rollout status deployment
# List all services
—>kubectl get svc
# Show service endpoints
—>kubectl get endpoints
# Detailed service info
—>kubectl describe svc
# Forward service to localhost
—>kubectl port-forward svc/ 8080:80
# Expose as service
—>kubectl expose deployment --type=NodePort --port=80
------PersistentVolume & PVC -------
# List PersistentVolumeClaims
—>kubectl get pvc
# Describe PVC details
—>kubectl describe pvc
# Delete PVC
—>kubectl delete pvc
# List PersistentVolumes
—>kubectl get pv
# Resize PVC
—>kubectl patch pvc -p '{"spec":{"resources":{"requests":{"storage":"100Gi"}}}}'
---ConfigMaps & Secrets---
# Create ConfigMap from file
—>kubectl create configmap --from-file=
# List all ConfigMaps
—>kubectl get configmap
# Show ConfigMap details
—>kubectl describe configmap
# Delete ConfigMap
—>kubectl delete configmap
# List all secrets
—>kubectl get secret
# Describe secret (Base64 encoded)
—>kubectl describe secret
# Delete secret
—>kubectl delete secret
----Ingress & Networking-------
# List Ingress resources
—>kubectl get ingress
# Describe Ingress
—>kubectl describe ingress
# Delete Ingress
—>kubectl delete ingress
# List services
—>kubectl get svc
# Show service endpoints
—>kubectl get endpoints
# Deploy a quick NGINX pod
—>kubectl run nginx --image=nginx
# Expose pod as service
—>kubectl expose pod nginx --port=80
------Namespace Management------
# List all namespaces
—>kubectl get namespaces
# Create new namespace
—>kubectl create namespace
# Delete namespace
—>kubectl delete namespace
# Set default namespace
—>kubectl config set-context --current --namespace=
------Debugging & Troubleshooting------
# View events for errors
—>kubectl get events
# Find non-running pods
—>kubectl get pods --field-selector=status.phase!=Running
# Check pod logs
—>kubectl logs
# Detailed pod info
—>kubectl describe pod
# Access pod shell
—>kubectl exec -it -- sh
# List all resources in namespace
—>kubectl get all -n
# Force recreate problematic pod
—>kubectl delete pod
# Debug pod with ephemeral container
—>kubectl debug pod/ --image=busybox