Kubernetes Commands For Interviews
Kubernetes Commands For Interviews
Command:
Explanation:
Command:
Explanation:
Example:
kubectl get pods -n kube-system
Command:
Explanation:
Example:
kubectl describe pod nginx-pod -n default
Command:
Explanation:
Example:
kubectl logs nginx-pod -n default
Command:
Explanation:
Command:
kubectl expose deployment <deployment-name>
--type=<service-type> --port=<port>
Explanation:
Example:
kubectl expose deployment nginx-deployment --type=NodePort
--port=80
Command:
Explanation:
Example:
kubectl scale deployment nginx-deployment --replicas=5
Command:
Explanation:
Example:
kubectl apply -f deployment.yaml
Command:
Explanation:
Example:
kubectl delete pod nginx-pod
Command:
Explanation:
Example:
NAME STATUS ROLES AGE VERSION
ip-192-168-1-1 Ready master 30d v1.23.3
Commands:
Explanation:
Command:
kubectl top nodes
kubectl top pods
Explanation:
Example:
kubectl top pods -n default
Command:
Explanation:
Command:
Explanation:
Example:
kubectl edit deployment nginx-deployment
Command:
Explanation:
Example:
kubectl get pod nginx-pod -o yaml
Command:
Explanation:
Example:
kubectl create namespace dev
Command:
kubectl delete namespace <namespace-name>
Explanation:
Example:
kubectl delete namespace dev
Command:
Explanation:
Example:
kubectl rollout restart deployment nginx-deployment
Command:
Explanation:
Example:
kubectl rollout status deployment nginx-deployment
Command:
Explanation:
Example:
kubectl rollout undo deployment nginx-deployment
Command:
Explanation:
Example:
kubectl rollout history deployment nginx-deployment
Command:
Explanation:
Example:
kubectl port-forward pod/nginx-pod 8080:80
Command:
kubectl proxy
Explanation:
Command:
Explanation:
Example:
kubectl create configmap app-config
--from-literal=environment=dev
Command:
Explanation:
Example:
kubectl create secret generic db-secret
--from-literal=username=admin
--from-literal=password=securepass
yaml
envFrom:
- configMapRef:
name: <configmap-name>
- secretRef:
name: <secret-name>
Explanation:
Example:
yaml
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: app-container
image: nginx
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: db-secret
Command:
Explanation:
● Evicts all pods from the node to make it ready for maintenance.
● The --ignore-daemonsets flag skips DaemonSets.
Example:
kubectl drain worker-node-1 --ignore-daemonsets
--delete-emptydir-data
Command:
Explanation:
Example:
kubectl uncordon worker-node-1
Commands:
# View logs
kubectl logs <pod-name>
# Describe the pod
kubectl describe pod <pod-name>
# Check the events
kubectl get events -n <namespace>
Explanation:
● CrashLoopBackOff indicates the container is repeatedly failing.
● Use logs and events to identify the root cause (e.g., missing ConfigMap, secret,
or incorrect image).
Command:
Explanation:
Example:
kubectl get endpoints nginx-service