Kubernetes Practical Commands for Critical Interview Questions 1. Check Cluster Information kubectl cluster-info kubectl get nodes kubectl get componentstatus kubectl version 2. Check All Resources kubectl get all -A kubectl get pods -A kubectl get svc -A kubectl get deploy -A kubectl get rs -A 3. Pod Troubleshooting Check Pod Status kubectl get pods kubectl get pods -o wide kubectl describe pod pod-name View Logs kubectl logs pod-name kubectl logs -f pod-name kubectl logs pod-name --previous Login Into Pod kubectl exec -it pod-name -- /bin/bash kubectl exec -it pod-name -- sh 4. CrashLoopBackOff Troubleshooting kubectl describe pod pod-name kubectl logs pod-name --previous kubectl get events --sort-by=.metadata.creationTimestamp 5. Pending Pod Troubleshooting Check Events kubectl describe pod pod-name kubectl get events Check Node Resources kubectl top nodes kubectl describe node node-name 6. Deployment Commands Create Deployment kubectl create deployment nginx --image=nginx Scale Deployment kubectl scale deployment nginx --replicas=5 Restart Deployment kubectl rollout restart deployment nginx Check Rollout Status kubectl rollout status deployment nginx Rollback Deployment kubectl rollout undo deployment nginx 7. Namespace Commands kubectl get ns kubectl create ns dev kubectl config set-context --current --namespace=dev 8. Service Commands Expose Deployment kubectl expose deployment nginx --port=80 --type=NodePort Check Services kubectl get svc kubectl describe svc nginx 9. Networking Troubleshooting DNS Check kubectl exec -it pod-name -- nslookup kubernetes.default kubectl exec -it pod-name -- ping service-name Check CoreDNS kubectl get pods -n kube-system kubectl logs -n kube-system coredns-pod-name 10. Node Troubleshooting Check Nodes kubectl get nodes kubectl describe node node-name Mark Node Unschedulable kubectl cordon node-name Drain Node kubectl drain node-name --ignore-daemonsets Enable Scheduling Again kubectl uncordon node-name 11. Resource Usage Monitoring kubectl top nodes kubectl top pods 12. ConfigMap Commands Create ConfigMap kubectl create configmap app-config --from-literal=env=prod View ConfigMap kubectl get configmap kubectl describe configmap app-config 13. Secret Commands Create Secret kubectl create secret generic db-secret \ --from-literal=username=admin \ --from-literal=password=admin123 View Secret kubectl get secrets kubectl describe secret db-secret Decode Secret kubectl get secret db-secret -o yaml echo "base64value" | base64 -d 14. Persistent Volume Commands Check Storage kubectl get pv kubectl get pvc kubectl describe pvc pvc-name 15. Autoscaling Commands Create HPA kubectl autoscale deployment nginx --cpu-percent=70 --min=2 --max=10 Check HPA kubectl get hpa 16. Ingress Commands Check Ingress kubectl get ingress kubectl describe ingress ingress-name Check Ingress Controller kubectl get pods -n ingress-nginx 17. ETCD Backup & Restore Backup ETCD ETCDCTL_API=3 etcdctl snapshot save backup.db \ --endpoints=https://127.0.0.1:2379 \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.key Restore ETCD ETCDCTL_API=3 etcdctl snapshot restore backup.db 18. Debugging Networking Issues Check Endpoints kubectl get endpoints Curl Service kubectl exec -it pod-name -- curl service-name 19. DaemonSet Commands kubectl get daemonset kubectl describe daemonset daemonset-name 20. StatefulSet Commands kubectl get statefulset kubectl describe statefulset mysql 21. RBAC Commands Create Role kubectl create role pod-reader --verb=get,list,watch --resource=pods Create RoleBinding kubectl create rolebinding read-pods \ --role=pod-reader \ --serviceaccount=default:default 22. Check Events kubectl get events kubectl get events --sort-by=.metadata.creationTimestamp 23. YAML Validation kubectl apply -f deployment.yaml --dry-run=client kubectl apply -f deployment.yaml --validate=true 24. Generate YAML Quickly kubectl create deployment nginx --image=nginx --dry-run=client -o yaml 25. Multi Container Pod Check kubectl logs pod-name -c container-name 26. Check Kubernetes API Resources kubectl api-resources kubectl api-versions 27. Delete Resources kubectl delete pod pod-name kubectl delete deploy nginx kubectl delete svc nginx 28. Helm Commands Install Helm Chart helm install myapp bitnami/nginx List Releases helm list Upgrade Release helm upgrade myapp bitnami/nginx Rollback Helm helm rollback myapp 1 29. Kubernetes Certificate Check kubeadm certs check-expiration 30. Production Troubleshooting Commands Find High CPU Pods kubectl top pods --sort-by=cpu Find High Memory Pods kubectl top pods --sort-by=memory Describe Everything kubectl describe pod pod-name kubectl describe node node-name kubectl describe deploy deploy-name MOST IMPORTANT INTERVIEW COMMANDS kubectl get pods -A kubectl describe pod pod-name kubectl logs pod-name kubectl exec -it pod-name -- bash kubectl top nodes kubectl top pods kubectl get events kubectl rollout undo deployment/app kubectl cordon node-name kubectl drain node-name kubectl get pvc kubectl get ingress kubectl get svc These are the commands most frequently asked during real-time DevOps & Kubernetes interviews.

Comments

Popular posts from this blog

Linux interview questions

Aws Interview Questions