Day37 of #90DaysOfDevOps

Kubernetes Important interview Questions.

1.What is Kubernetes and why it is 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, whereas Kubernetes is a more comprehensive and widely adopted container orchestration platform.

  • Kubernetes provides more advanced features such as automatic scaling, rolling updates, and declarative configuration, while Docker Swarm is simpler and easier to set up.


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 updating a deployment to a new version without downtime. It gradually replaces old pods with new ones, ensuring that the application remains available during the update process.

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 namespace is kubernetes? Which namespace any pod takes if we don't specify any namespace?

  • A namespace in Kubernetes provides a way to logically isolate resources within a cluster. If no namespace is specified, the pod is created in the default namespace.

10 . How ingress helps in kubernetes?

  • Ingress in Kubernetes is an API object that manages external access to services within a cluster. It provides routing rules, SSL termination, and load balancing for HTTP and HTTPS traffic to different services based on hostnames or paths.

11 . Explain different types of services in kubernetes?

  • Kubernetes supports several types of services:

    • ClusterIP: Exposes the service on an internal IP within the cluster. It is accessible only from within the cluster.

    • NodePort: Exposes the service on a static port on each node's IP. It is accessible from outside the cluster.

    • LoadBalancer: Creates an external load balancer in the cloud provider's network to route external traffic to the service.

    • ExternalName: Maps the service to the contents of the externalName field. It allows accessing services outside the cluster.

    • Headless: Forwards DNS requests to the pods directly without load balancing. Useful for stateful applications.


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 . Difference between create and apply in kubernetes?

  • kubectl create is used to create new Kubernetes resources from configuration files or command-line arguments. If a resource already exists with the same name, create will fail.

  • kubectl apply is used to create or update Kubernetes resources based on the configuration provided. If a resource already exists, apply will update it to match the provided configuration.