Kubernetes Interview Questions
1. Theoretical Questions
1. What is Kubernetes, and why is it used?
Answer: Kubernetes is an open-source container orchestration platform used to
automate deployment, scaling, and management of containerized applications. It
helps manage containerized apps across clusters of hosts.
2. Explain the architecture of Kubernetes.
Answer: Kubernetes consists of:
Master Node: Controls the cluster (APIs, Scheduler, Controller Manager,
etc.)
Worker Nodes: Run containers (Kubelet, Kube Proxy, etc.)
Key Components: Pods, Services, Deployments, ReplicaSets.
3. What is a Pod in Kubernetes?
Answer: A Pod is the smallest deployable unit in Kubernetes. It can contain one or
more containers that share the same network namespace, storage, and specifications.
4. How does Kubernetes manage networking for Pods?
Answer: Kubernetes assigns each Pod a unique IP, making Pods accessible across
the cluster. It uses network plugins (like CNI) to manage communication.
2. Practical Questions
1. Create a Kubernetes deployment YAML file for a web application and explain it.
Sample YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
spec:
replicas: 3
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: nginx:latest
ports:
- containerPort: 80
Explanation: This YAML file creates a deployment called webapp-deployment with 3
replicas of the NGINX container running on port 80.
2. How would you scale a Kubernetes deployment to 5 replicas?
kubectl scale deployment webapp-deployment –replicas=5
Kubernetes Interview Questions and Commands
1. Advanced Theoretical Questions
1. What is a StatefulSet in Kubernetes, and when would you use it?
Answer: StatefulSet is a Kubernetes controller used to manage stateful applications,
where each Pod is unique and requires a persistent identity and storage. It is used
when deploying databases, message queues, or any application where the order and
persistence of Pods are crucial.
2. Explain the role of etcd in a Kubernetes cluster.
Answer: etcd is a distributed key-value store that stores all the data used to manage
the Kubernetes cluster, including the configuration, state of the cluster, and
information about nodes, Pods, and other resources.
3. What are Kubernetes taints and tolerations?
Answer: Taints and tolerations ensure that Pods are not scheduled on inappropriate
nodes. Taints are applied to nodes to repel Pods, and tolerations are added to Pods to
allow them to be scheduled on nodes with matching taints.
2. Additional Practical Commands
1. Retrieve all Pods running in a specific namespace:
1. kubectl get pods -n my-namespace
2. Update an existing deployment’s container image without downtime:
1. kubectl set image deployment/webapp webapp-container=myapp:2.0
3. Check the logs of a running Pod:
1. kubectl logs pod-name
4. Exec into a running Pod to troubleshoot:
1. kubectl exec -it pod-name -- /bin/bash