Kubernetes Interview Prep

·

5 min read

These questions and their answers should help you strengthen your Kubernetes knowledge and prepare you for any Kubernetes-related interviews. Keep practicing and refining your skills! 🚀

1. What is Kubernetes and why is it important?

Kubernetes is an open-source container orchestration platform designed to automate deploying, scaling, and managing containerized applications. It helps manage containers across clusters of hosts and provides essential features such as service discovery, scaling, load balancing, and self-healing, making it a crucial tool for running applications in production environments.


2. What is the difference between Docker Swarm and Kubernetes?

  • Docker Swarm is Docker's native clustering and orchestration tool, focusing on simplicity and tightly integrated with Docker.

  • Kubernetes, on the other hand, is a more robust, feature-rich, and flexible orchestration tool with advanced features such as auto-scaling, rolling updates, and support for multiple cloud environments.

FeatureDocker SwarmKubernetes
SetupSimpler to set upMore complex and feature-rich
ScalingManual scalingAuto-scaling and horizontal pod scaling
Load BalancingBuilt-inLoad balancing with Services
EcosystemTightly coupled with DockerLarger, more flexible ecosystem

3. How does Kubernetes handle network communication between containers?

Kubernetes uses an internal virtual network that allows pods to communicate with each other, whether they are on the same node or across different nodes. It assigns a unique IP address to each pod, and containers within a pod share the same network namespace, which allows them to communicate over localhost. For external communication, Kubernetes uses Services (ClusterIP, NodePort, LoadBalancer).


4. How does Kubernetes handle scaling of applications?

Kubernetes can automatically scale applications horizontally by adding or removing pod replicas. This can be achieved via:

  • Horizontal Pod Autoscaler (HPA): Scales pods based on CPU utilization or custom metrics.

  • Manual Scaling: Use the kubectl scale command to manually adjust the number of replicas.


5. What is a Kubernetes Deployment and how does it differ from a ReplicaSet?

  • A Deployment in Kubernetes provides declarative updates to applications, allowing you to define how many replicas of a pod should run, handle rolling updates, and rollbacks.

  • A ReplicaSet ensures a specific number of pod replicas are running at any given time, but without providing rolling updates or rollback functionality.

Deployments use ReplicaSets under the hood to ensure pod availability.


6. Can you explain the concept of rolling updates in Kubernetes?

Rolling updates in Kubernetes allow for the gradual replacement of old versions of pods with new ones. It ensures that the application remains available during the update process. Kubernetes accomplishes this by scaling up new pod versions while simultaneously scaling down the old ones.


7. How does Kubernetes handle network security and access control?

Kubernetes handles network security through:

  • Network Policies: Define how pods communicate with each other and external services.

  • RBAC (Role-Based Access Control): Controls access to the Kubernetes API, ensuring that users have the necessary permissions to perform actions.


8. Can you give an example of how Kubernetes can be used to deploy a highly available application?

To deploy a highly available application in Kubernetes, you can:

  • Use a Deployment with multiple pod replicas.

  • Use a Service (e.g., ClusterIP or LoadBalancer) to load balance traffic across multiple replicas.

  • Deploy the application across multiple nodes and availability zones for redundancy.


9. What is a namespace in Kubernetes? Which namespace does any pod take if we don't specify any namespace?

A Namespace in Kubernetes is a way to divide cluster resources between multiple users or teams. By default, if no namespace is specified, Kubernetes creates resources in the default namespace.


10. How does ingress help in Kubernetes?

An Ingress in Kubernetes is a resource that manages external access to services within a cluster, typically through HTTP or HTTPS. It provides load balancing, SSL termination, and name-based virtual hosting.


11. Explain different types of services in Kubernetes?

  • ClusterIP: Exposes the service on an internal IP address within the cluster.

  • NodePort: Exposes the service on each node’s IP at a static port.

  • LoadBalancer: Exposes the service externally using a cloud provider’s load balancer.

  • ExternalName: Maps the service to an external name (e.g., external DNS names).


12. Can you explain the concept of self-healing in Kubernetes and give examples of how it works?

Kubernetes supports self-healing by automatically restarting failed containers, replacing terminated pods, and rescheduling them on healthy nodes. For example:

  • Pod restart: If a pod fails, Kubernetes will automatically restart it.

  • Node failure: Kubernetes will reschedule pods to other nodes if a node fails.


13. How does Kubernetes handle storage management for containers?

Kubernetes manages storage through Persistent Volumes (PV) and Persistent Volume Claims (PVC). PVs are provisioned storage, while PVCs are requests for storage by pods. Kubernetes supports different types of storage such as NFS, cloud-provider storage (e.g., AWS EBS, GCE Persistent Disk), and hostPath.


14. How does the NodePort service work?

A NodePort service in Kubernetes exposes a service on each node’s IP at a static port. This allows external traffic to access the service by making a request to any node’s IP address on that specified port.


15. What is a multinode cluster and a single-node cluster in Kubernetes?

  • A single-node cluster is a Kubernetes cluster where both the control plane and the worker node are on the same machine.

  • A multinode cluster has multiple worker nodes, with the control plane running separately, providing higher availability, scalability, and redundancy.


16. What is the difference between create and apply in Kubernetes?

  • kubectl create: Used to create resources in the cluster, but cannot update them.

  • kubectl apply: Can create and update resources, making it more suitable for managing resources declaratively through YAML files.


Happy Learning! 🎉

Â