What is kubectl and common commands?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Kubernetes (K8s) basics — a prerequisite for any developer role.

Answer

kubectl is the Kubernetes command-line tool for interacting with Kubernetes clusters. It communicates with the kube-apiserver via REST APIs. Essential commands: kubectl get pods [-n namespace] [-A for all namespaces] [-o wide for more info] kubectl get pods -o yaml # full YAML kubectl get all # all resources in namespace kubectl describe pod my-pod # detailed info including events kubectl logs my-pod [-c container] [-f for follow] [--previous for crashed container] kubectl exec -it my-pod -- /bin/sh # interactive shell kubectl exec my-pod -- env # run command kubectl apply -f deployment.yaml # create/update from file kubectl delete -f deployment.yaml kubectl delete pod my-pod kubectl port-forward pod/my-pod 8080:3000 # local port forwarding kubectl port-forward service/my-service 8080:80 kubectl top nodes # resource usage kubectl top pods kubectl rollout status deployment/my-app kubectl rollout history deployment/my-app kubectl rollout undo deployment/my-app kubectl scale deployment my-app --replicas=5 kubectl set image deployment/my-app my-app=my-app:2.0 kubectl config get-contexts # list cluster contexts kubectl config use-context my-cluster # switch cluster kubectl create secret generic my-secret --from-literal=key=value kubectl create configmap my-config --from-env-file=.env kubectl run debug --image=busybox --rm -it -- /bin/sh # temporary pod kubectl debug pod/my-pod --image=ubuntu -it # ephemeral debug container. kubectl plugins: extend kubectl with plugins (kubectl-neat, kubectl-tree, kubectl-images). krew: kubectl plugin manager.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last Kubernetes (K8s) project, I used this when...' immediately makes your answer more credible and memorable.