
Kubernetes Basic Interview Questions
Here are 20 basic Kubernetes interview questions with detailed explanations, the skill/concept being tested
1. Question: What is Kubernetes?
Expected Answer: Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It groups containers into logical units for easy management and discovery.
Technical Explanation: Kubernetes provides an abstraction layer over a cluster of nodes (physical or virtual machines). It automates tasks like scheduling containers onto nodes, scaling applications up or down, managing desired state, and providing self-healing capabilities.
Skill/Concept Tested: Core Kubernetes definition and purpose.
2. Question: What are the key components of a Kubernetes cluster?
Expected Answer: The key components include the Control Plane (API Server, etcd, Scheduler, Controller Manager) and Worker Nodes (Kubelet, Kube-proxy, Container Runtime).
Technical Explanation:
* API Server: The front-end for the Kubernetes control plane, exposing the Kubernetes API.
* etcd: A distributed, reliable key-value store used as Kubernetes’ backing store for all cluster data.
* Scheduler: Responsible for placing pods onto appropriate worker nodes based on resource availability and constraints.
* Controller Manager: Runs various controller processes that regulate the state of the cluster (e.g., node controller, replication controller).
* Kubelet: An agent that runs on each worker node and is responsible for starting and managing containers in pods.
* Kube-proxy: A network proxy that runs on each worker node, implementing Kubernetes Service abstraction and rules for network traffic forwarding.
* Container Runtime: The underlying software used to run containers (e.g., Docker, containerd, CRI-O).
Skill/Concept Tested: Kubernetes architecture and component understanding.
3. Question: What is a Pod in Kubernetes?
Expected Answer: A Pod is the smallest and most basic deployable unit in Kubernetes. It represents a single instance of a running process in the cluster and can contain one or more containers that are tightly coupled and share resources such as network and storage.
Technical Explanation: Containers within a Pod share an IP address, port space, hostname, and can communicate easily with each other via localhost. Pods are ephemeral and are typically managed by higher-level abstractions like Deployments or StatefulSets.
Skill/Concept Tested: Fundamental Kubernetes object – Pod.
4. Question: What is a Kubernetes Deployment?
Expected Answer: A Deployment is a higher-level abstraction that manages ReplicaSets, providing declarative updates for Pods and ReplicaSets. It allows you to describe the desired state for your application, and the Deployment controller works to bring the current state in line with the desired state.
Technical Explanation: Deployments enable features like rolling updates, rollback to previous versions, and scaling of applications without manual intervention on individual Pods.
Skill/Concept Tested: Application management using Deployments.
5. Question: What is a Kubernetes Service? What are the different types of Services?
Expected Answer: A Service provides a stable IP address and DNS name to access a set of Pods. It acts as a load balancer, distributing traffic across the Pods that match its selector. Common Service types include:
* ClusterIP: Exposes the Service on an internal IP in the cluster, only reachable from within the cluster.
* NodePort: Exposes the Service on each Node’s IP at a static port (NodePort). You can contact the NodePort Service from outside the cluster using <NodeIP>:<NodePort>.
* LoadBalancer: Exposes the Service externally using a cloud provider’s load balancer. Traffic from the external load balancer is forwarded to the NodePort and ClusterIP Service.
* ExternalName: Maps the Service to the DNS name of an external service.
Technical Explanation: Services provide service discovery and load balancing for applications running in Kubernetes, decoupling consumers from the underlying Pod IPs which are ephemeral.
Skill/Concept Tested: Service discovery and networking within Kubernetes.
6. Question: What is a Kubernetes Namespace?
Expected Answer: Namespaces are virtual clusters within a single physical cluster. They provide a way to partition cluster resources and logically isolate groups of resources.
Technical Explanation: Namespaces help in organizing projects, teams, or environments within the same Kubernetes cluster. Resources like Pods, Deployments, and Services are scoped to a specific namespace.
Skill/Concept Tested: Resource isolation and organization using Namespaces.
7. Question: What is a Kubernetes ReplicaSet?
Expected Answer: A ReplicaSet ensures that a specified number of Pod replicas are running at any given time. If a Pod dies, the ReplicaSet automatically creates a new one to maintain the desired number of replicas.
Technical Explanation: ReplicaSets use selectors to identify the Pods they manage. While ReplicaSets can be used directly, Deployments are generally preferred as they provide more advanced update and rollback strategies.
Skill/Concept Tested: Ensuring desired number of Pod replicas.
8. Question: What is the difference between a ReplicaSet and a Deployment?
Expected Answer: A ReplicaSet ensures a specified number of Pods are running. A Deployment is a higher-level abstraction that manages ReplicaSets and provides declarative updates to Pods and ReplicaSets, including rolling updates and rollbacks. Deployments are the recommended way to manage stateless applications.
Technical Explanation: Deployments manage the lifecycle of ReplicaSets. When you update a Deployment, it creates a new ReplicaSet with the updated Pod template and gradually replaces the old ReplicaSet with the new one.
Skill/Concept Tested: Understanding the relationship and differences between ReplicaSets and Deployments.
9. Question: What is Kubeadm?
Expected Answer: Kubeadm is a command-line tool used to bootstrap a minimum viable Kubernetes cluster. It performs the necessary actions to get a basic, functional Kubernetes cluster up and running.
Technical Explanation: Kubeadm handles the initialization of the control plane nodes and the joining of worker nodes to the cluster. It focuses on the essential components and configurations required for a basic Kubernetes setup.
Skill/Concept Tested: Kubernetes cluster bootstrapping tool.
10. Question: What is Kubectl?
Expected Answer: Kubectl is the command-line tool used to interact with the Kubernetes API server. It allows you to run commands against Kubernetes clusters to deploy applications, inspect and manage cluster resources, and view logs.
Technical Explanation: Kubectl communicates with the API server using the Kubernetes API. It takes various commands and flags to perform actions on Kubernetes objects.
Skill/Concept Tested: Kubernetes command-line interface.
11. Question: What is a Kubernetes Secret?
Expected Answer: A Secret is an object in Kubernetes used to store sensitive information, such as passwords, API tokens, and SSH keys. Storing sensitive data in Secrets is safer than embedding it directly in Pod definitions or container images.
Technical Explanation: Secrets can be mounted as volumes or exposed as environment variables in Pods. Kubernetes provides mechanisms to control access to Secrets.
Skill/Concept Tested: Managing sensitive data in Kubernetes.
12. Question: What is a Kubernetes ConfigMap?
Expected Answer: A ConfigMap is an API object used to store non-confidential configuration data in key-value pairs. ConfigMaps allow you to decouple configuration details from your application code and container images.
Technical Explanation: Similar to Secrets, ConfigMaps can be mounted as volumes or exposed as environment variables in Pods, allowing applications to access their configuration.
Skill/Concept Tested: Managing application configuration in Kubernetes.
13. Question: What are Kubernetes Labels and Selectors?
Expected Answer:
* Labels: Key-value pairs that are attached to Kubernetes objects, such as Pods. They are used to organize and select subsets of objects.
* Selectors: Used to query and filter Kubernetes objects based on their labels. They are used by controllers (like ReplicaSets and Deployments) and Services to target specific Pods.
Technical Explanation: Labels are arbitrary metadata that can be attached to objects. Selectors use label key-value pairs to identify sets of objects. There are two types of selectors: equality-based and set-based.
Skill/Concept Tested: Object identification and grouping using labels and selectors.
14. Question: What is a Kubernetes Volume? What are some common volume types?
Expected Answer: A Volume in Kubernetes represents a directory accessible to the containers in a Pod. It provides persistent storage that outlives individual containers. Common volume types include:
* emptyDir: A temporary directory that lasts for the lifetime of the Pod.
* hostPath: Mounts a file or directory from the host node’s filesystem into the Pod.
* PersistentVolumeClaim (PVC) / PersistentVolume (PV): Provides persistent storage provisioned dynamically or statically.
* ConfigMap/Secret: Allow mounting ConfigMap or Secret data as files in a volume.
Technical Explanation: Volumes provide a way to share data between containers in a Pod and to persist data beyond the lifecycle of a single container.
Skill/Concept Tested: Understanding storage options in Kubernetes.
15. Question: What is the purpose of the Kubernetes Scheduler?
Expected Answer: The Kubernetes Scheduler is responsible for deciding which node a newly created Pod should run on. It considers various factors such as resource requirements, node availability, taints and tolerations, affinity and anti-affinity rules when making scheduling decisions.
Technical Explanation: The Scheduler watches for new, unscheduled Pods and tries to find the best fit node for them based on defined policies and available resources.
Skill/Concept Tested: Pod scheduling process in Kubernetes.
16. Question: What are Taints and Tolerations in Kubernetes?
Expected Answer:
* Taints: Properties applied to nodes that indicate that no Pods should be scheduled on them unless they have a matching toleration.
* Tolerations: Properties applied to Pods that allow them to be scheduled on nodes with matching taints.
Technical Explanation: Taints and Tolerations are used to control which Pods can be scheduled on specific nodes. This is useful for dedicating nodes for specific workloads (e.g., nodes with GPUs).
Skill/Concept Tested: Node affinity and controlling Pod placement.
17. Question: What is the purpose of the Kubernetes Controller Manager?
Expected Answer: The Controller Manager is a single binary that runs various controller processes in Kubernetes. These controllers are responsible for observing the state of the cluster and making changes to reach the desired state.
Technical Explanation: Examples of controllers managed by the Controller Manager include the Node Controller (manages node lifecycle), the Replication Controller (maintains the desired number of Pod replicas), and the Endpoint Controller (populates Endpoints objects).
Skill/Concept Tested: Understanding the role of Kubernetes controllers.
18. Question: How do you scale an application in Kubernetes?
Expected Answer: Applications in Kubernetes can be scaled horizontally by increasing the number of Pod replicas. This can be done manually using kubectl scale or automatically using Horizontal Pod Autoscaling (HPA) based on metrics like CPU utilization or custom metrics.
Technical Explanation: Scaling involves updating the replicas field in a Deployment or ReplicaSet specification. The controller then ensures the desired number of Pods are running. HPA automatically adjusts the number of replicas based on defined scaling rules.
Skill/Concept Tested: Application scaling in Kubernetes.
19. Question: How do you perform a rolling update of an application in Kubernetes?
Expected Answer: Kubernetes Deployments provide built-in support for rolling updates. When you update the Pod template in a Deployment, it gradually replaces the old Pods with new ones in a controlled manner, ensuring minimal downtime.
Technical Explanation: The Deployment controller creates a new ReplicaSet with the updated Pod template and progressively scales it up while scaling down the old ReplicaSet, ensuring a smooth transition.
Skill/Concept Tested: Application updates and deployments in Kubernetes.
20. Question: How do you monitor the health of your Kubernetes cluster and applications?
Expected Answer: Monitoring Kubernetes involves tracking the health and performance of the control plane components, worker nodes, and running applications. This can be done using tools like:
* kubectl get events: To view events in the cluster.
* kubectl logs: To view container logs.
* Metrics servers (e.g., kube-state-metrics, Prometheus): To collect and expose metrics.
* Monitoring and logging platforms (e.g., Grafana, Elasticsearch, Kibana): To visualize metrics and analyze logs.
* Health probes (Liveness and Readiness probes): Configured in Pods to allow Kubernetes to monitor container health and readiness.
Technical Explanation: Health probes allow Kubernetes to determine if a container is running (liveness) and if it’s ready to serve traffic (readiness). Metrics provide insights into resource utilization and application performance. Logging helps in troubleshooting issues.
Skill/Concept Tested: Monitoring and health checks in Kubernetes.