Kubernetes Interview Questions and Answers

Kubernetes Interview Questions and Answers

1. What is Kubernetes?

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It allows you to manage applications across a cluster of machines and provides features like load balancing, self-healing, and rolling updates.


2. What are the key components of Kubernetes?

The key components of Kubernetes include:

  • Master node: The control plane that manages the Kubernetes cluster.
  • Worker nodes: The nodes that run the containerized applications.
  • Pods: The smallest deployable unit in Kubernetes.
  • Services: Used for exposing applications and ensuring network communication.
  • ReplicaSets: Ensure the desired number of pod replicas are running.
  • Deployments: Manage ReplicaSets and provide declarative updates to pods.
  • ConfigMaps and Secrets: Store configuration data and sensitive information.

3. What is a Pod in Kubernetes?

A Pod is the smallest and simplest unit in Kubernetes. It can contain one or more containers that share the same network, storage, and specification. Pods are typically used to deploy and run applications in Kubernetes.


4. What is the difference between a Pod and a Container?

A Container is an isolated environment where a single application runs, while a Pod is a higher-level abstraction in Kubernetes that can contain one or more containers that share the same network and storage resources.


5. What is a ReplicaSet in Kubernetes?

A ReplicaSet ensures that a specified number of replicas of a pod are running at any given time. If a pod fails, the ReplicaSet will automatically create a new pod to maintain the desired number of replicas.


6. What is the role of the Kubernetes Scheduler?

The Kubernetes Scheduler is responsible for assigning pods to available worker nodes in the cluster. It considers resource requirements, constraints, and other factors before placing a pod on a node.


7. What is a Deployment in Kubernetes?

A Deployment is a Kubernetes resource that provides declarative updates to Pods and ReplicaSets. It ensures that the desired number of pod replicas are running, and it can manage rolling updates and rollbacks.


8. What is a Service in Kubernetes?

A Service is an abstraction that exposes a set of Pods as a network service. It provides a stable IP address and DNS name to access the Pods, even if the Pods are dynamically created or destroyed.


9. What is a Namespace in Kubernetes?

A Namespace is a way to divide cluster resources into virtual sub-clusters. It provides isolation for resources like pods, services, and deployments within the same cluster. Namespaces help in organizing and managing resources in large clusters.


10. What is Kubernetes Ingress?

Ingress is a collection of rules that allow external HTTP and HTTPS traffic to reach the services within a Kubernetes cluster. It provides load balancing, SSL termination, and name-based virtual hosting.


11. What is a ConfigMap in Kubernetes?

A ConfigMap is an API object used to store configuration data as key-value pairs. It allows you to separate configuration settings from application code and inject them into your pods.


12. What is a Secret in Kubernetes?

A Secret is similar to a ConfigMap but is used to store sensitive data, such as passwords, OAuth tokens, and SSH keys. Secrets are stored in an encoded format and can be used to inject sensitive information into pods.


13. What is Kubernetes Volumes?

A Volume is a storage resource used by pods to store data. Volumes allow data to persist beyond the lifecycle of a pod. Different types of volumes include emptyDir, hostPath, NFS, and persistent volumes (PVs).


14. What is PersistentVolume (PV) in Kubernetes?

A PersistentVolume (PV) is a piece of storage in the Kubernetes cluster that has been provisioned by an administrator. It is a resource in the cluster and is independent of the pod lifecycle.


15. What is PersistentVolumeClaim (PVC) in Kubernetes?

A PersistentVolumeClaim (PVC) is a request for storage by a user. It specifies size, access modes, and storage class, and it binds to an available PersistentVolume (PV) in the cluster.


16. What is the difference between a StatefulSet and a Deployment in Kubernetes?

A StatefulSet is used for applications that require stable, unique network identifiers, persistent storage, and ordered deployment. A Deployment, on the other hand, is used for stateless applications where pods can be replaced without any persistent storage concerns.


17. What is Horizontal Pod Autoscaler (HPA)?

The Horizontal Pod Autoscaler (HPA) automatically scales the number of pod replicas based on observed CPU utilization or other custom metrics. It ensures that your application can handle varying levels of load.


18. What is a DaemonSet in Kubernetes?

A DaemonSet ensures that a copy of a pod runs on all (or selected) nodes in a Kubernetes cluster. It is useful for running background services, such as logging agents, monitoring agents, or network plugins.


19. What is a Job in Kubernetes?

A Job is a resource that manages the execution of one or more pods that run until completion. Jobs are typically used for tasks that are short-lived and need to run a specific number of times or until completion.


20. What is CronJob in Kubernetes?

A CronJob is a scheduled job that runs at specified times or intervals, similar to a cron job in Unix-based systems. It allows you to run jobs on a recurring schedule.


21. What is Kubernetes Scheduler?

The Kubernetes Scheduler is responsible for selecting a suitable node for pod placement based on resource availability, constraints, and affinity/anti-affinity rules.


22. What are Affinity and Anti-Affinity in Kubernetes?

Affinity allows you to specify rules for placing pods on specific nodes based on labels, while Anti-Affinity allows you to specify rules to avoid placing certain pods together. These mechanisms help in controlling pod placement for high availability and resource optimization.


23. What is a Kubernetes Cluster?

A Kubernetes Cluster is a set of nodes (machines) that run containerized applications managed by Kubernetes. It consists of a Master Node and multiple Worker Nodes, which run the application workloads.


24. What is the role of the Master Node in Kubernetes?

The Master Node manages the Kubernetes cluster, including the API server, controller manager, scheduler, and etcd (a key-value store). It is responsible for maintaining the desired state of the cluster and handling communication between various components.


25. What is etcd in Kubernetes?

etcd is a consistent and highly-available key-value store used by Kubernetes to store all cluster data, including configurations, secrets, and resource states. It serves as the source of truth for the Kubernetes system.


26. What is the purpose of the Kubernetes API Server?

The API Server exposes the Kubernetes API and acts as the front-end for the Kubernetes control plane. It processes REST requests and updates the cluster’s state.


27. What are Kubernetes Labels?

Labels are key-value pairs attached to Kubernetes objects (e.g., pods, services) that help identify and organize them. Labels are used for selection, filtering, and grouping objects.


28. What are Kubernetes Selectors?

Selectors are used to filter and select Kubernetes objects based on labels. They are used in Services, ReplicaSets, and other controllers to match the appropriate pods.


29. How does Kubernetes handle Networking?

Kubernetes provides a flat network model where every pod can communicate with any other pod across nodes using unique IP addresses. It uses services for stable networking between pods and supports different network plugins to manage communication.


30. What is a Kubernetes LoadBalancer?

A LoadBalancer is a type of Kubernetes Service that automatically provisions an external load balancer (such as from a cloud provider) to distribute traffic across multiple pods.


31. What are Kubernetes Annotations?

Annotations are key-value pairs attached to Kubernetes objects that store non-identifying metadata. They are often used for debugging, auditing, and managing configuration data.


32. What is the Kubernetes Control Plane?

The Control Plane is the collection of components (API Server, Controller Manager, Scheduler, etc.) that manage the Kubernetes cluster. It makes decisions about the cluster’s state, such as scheduling pods, scaling applications, and managing resources.


33. What is the difference between kubectl get and kubectl describe?

  • kubectl get: Lists resources (like pods, services, deployments) in a Kubernetes cluster.
  • kubectl describe: Provides detailed information about a specific resource, including its status, events, and conditions.

34. What is kubectl apply used for in Kubernetes?

kubectl apply is used to create or update resources in the Kubernetes cluster by applying a configuration file (YAML or JSON). It ensures that the cluster’s current state matches the desired state defined in the configuration.


35. What is kubectl delete used for?

kubectl delete is used to remove resources like pods, services, deployments, etc., from the Kubernetes cluster.


36. What is a Kubernetes Context?

A Kubernetes Context is a set of access parameters (cluster, user, namespace) that defines the environment in which kubectl commands are executed. It allows you to switch between different clusters and namespaces easily.


37. What are the types of Kubernetes Services?

There are four main types of Kubernetes Services:

  1. ClusterIP: Exposes the service on an internal IP within the cluster.
  2. NodePort: Exposes the service on a static port on each node.
  3. LoadBalancer: Exposes the service externally via a load balancer.
  4. ExternalName: Maps the service to an external DNS name.

38. How do you scale a deployment in Kubernetes?

You can scale a Kubernetes deployment by specifying the desired number of replicas using the kubectl scale command or by editing the deployment configuration.


39. What is Kubernetes RBAC (Role-Based Access Control)?

RBAC is a method of regulating access to resources in Kubernetes based on the roles of individual users or service accounts. It allows administrators to define what actions users or services can perform on Kubernetes resources.


40. What is Kubernetes Horizontal Pod Autoscaling?

Horizontal Pod Autoscaling (HPA) automatically adjusts the number of pod replicas in a deployment or replica set based on observed CPU utilization or custom metrics.


41. What is a Kubernetes Service Account?

A Service Account is an identity used by processes running in a pod to access the Kubernetes API. Service accounts are used to assign permissions and access controls to pods.


42. What are Taints and Tolerations in Kubernetes?

Taints are applied to nodes to prevent pods from being scheduled on them unless they tolerate the taint. Tolerations are applied to pods to allow them to be scheduled on nodes with matching taints.


43. What is a Kubernetes Helm?

Helm is a package manager for Kubernetes that helps manage Kubernetes applications. It allows users to define, install, and upgrade complex applications using charts (pre-configured Kubernetes resources).


44. What is a Kubernetes Namespace used for?

A Namespace provides a way to partition resources in a cluster. It is useful for organizing resources, providing multi-tenancy, and allowing resource isolation for different environments (e.g., dev, prod).


45. What is a Kubernetes Secret used for?

A Secret is used to store sensitive data, such as passwords, OAuth tokens, and SSH keys, in an encoded format. It allows secure storage and access to sensitive information within a Kubernetes cluster.


46. How does Kubernetes manage security?

Kubernetes manages security through authentication, authorization (RBAC), network policies, and service accounts. It also uses secrets and encryption to handle sensitive data securely.


47. What is the kubectl logs command used for?

The kubectl logs command is used to view the logs of a container running inside a pod. It helps in debugging and monitoring application behavior.


48. What is the role of the kubelet?

The kubelet is an agent running on each worker node in the Kubernetes cluster. It ensures that the containers in the pods are running and healthy according to the specifications provided by the control plane.


49. What is a Kubernetes Proxy?

A Kubernetes Proxy is a network proxy that runs on each node in the cluster. It maintains network rules for pod-to-pod communication and acts as a load balancer for services.


50. How do you monitor a Kubernetes Cluster?

Monitoring in Kubernetes can be done using tools like Prometheus (for metrics collection) and Grafana (for visualization), as well as Kubernetes-native tools like kubectl top for resource usage.