Day 37: Must-Know Kubernetes Questions for Interview Preparation

Day 37: Must-Know Kubernetes Questions for Interview Preparation

ยท

10 min read

  1. What is Kubernetes and why it is important?

    Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It was originally developed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF).

    • This is why it is important:

      1. Kubernetes simplifies the deployment and management of containers.

      2. Kubernetes enables horizontal scaling of applications.

      3. Kubernetes offers features like self-healing.

      4. Kubernetes uses declarative configurations, allowing you to specify the desired state of your applications.

      5. Kubernetes aligns with DevOps principles by automating many aspects of application deployment and management.

      6. Kubernetes is designed to scale and adapt to evolving technology trends.

  2. What is the difference between docker swarm and Kubernetes?

    • Docker Swarm:

      1. It's tightly integrated with the Docker ecosystem and uses Docker Compose for defining multi-container applications.

      2. It's a good choice for smaller teams or organizations looking for a straightforward container orchestration solution.

      3. Swarm provides basic scaling and orchestration features, making it suitable for simpler use cases and applications.

    • Kubernetes:

      1. It has a broader ecosystem and is more agnostic when it comes to container runtimes.

      2. Kubernetes has a steeper learning curve but offers more extensive features and flexibility.

      3. Kubernetes is known for its advanced scaling and orchestration capabilities.

  3. How does Kubernetes handle network communication between containers?

    • This is how Kubernetes handle network communication between the containers:

      1. Containers within the same Pod share the same network namespace

      2. Kubernetes introduces the concept of a "Service" to provide a stable IP address and DNS name for a set of Pods. Services can be of different types, including NodePort, ClusterIP and LoadBalancer.

      3. Kubernetes provides a DNS service called kube-DNS or CoreDNS, which allows services to be discovered by name.

      4. Kubernetes supports various network plugins or Container Network Interfaces (CNIs), which enable communication between Pods across nodes in the cluster.

  4. How does Kubernetes handle the scaling of applications?

    • Kubernetes provides several methods to handle the scaling of the applications. Here are some of them:

      1. Cluster Autoscaler: Cluster Autoscaler is an optional component in Kubernetes that automatically adjusts the size of the cluster by adding or removing nodes based on resource requirements.

      2. Manual Scaling: Kubernetes also supports manual scaling. You can use the kubectl scale command to adjust the number of replicas in a Deployment or ReplicaSet.

      3. Vertical Pod Autoscaling (VPA): VPA is an experimental feature that adjusts the resource limits and requests of individual Pods based on their resource usage.

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

    • Kubernetes Deployment:

      1. A Deployment is a higher-level abstraction that manages ReplicaSets and provides declarative updates to applications.

      2. Deployments enable you to make declarative updates to applications.

      3. You can use Deployments to scale an application horizontally by changing the number of replicas.

      4. Deployments automatically handle Pod failures by creating new Pods to replace failed ones.

    • Kubernetes ReplicaSet:

      1. A ReplicaSet is a lower-level controller that ensures a specified number of replica Pods are running.

      2. ReplicaSets does not handle declarative updates like Deployments.

      3. ReplicaSets can be used for basic scaling operations, such as increasing or decreasing the number of replicas.

      4. While you can manually roll back to a previous configuration, it's not as straightforward as with Deployments.

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

    Rolling updates in Kubernetes is a strategy for updating an application or its containers with minimal or zero downtime. This strategy involves gradually replacing old instances of an application (containers) with new ones while ensuring that the application remains available and responsive throughout the update process.

    • This is how it works:

      1. Rolling updates are typically managed through Kubernetes Deployments.

      2. To initiate a rolling update, you make changes to the Pod template in the Deployment configuration.

      3. Kubernetes starts by scaling up the new ReplicaSet to create new Pods with the updated configuration.

    • Benefits:

      1. Rolling updates minimize or eliminate downtime by gradually transitioning from old to new Pods.

      2. If issues arise during the update, you can easily roll back to the previous version by undoing the changes to the Pod template.

      3. Kubernetes ensures that new Pods are healthy before directing traffic to them, maintaining application reliability.

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

    Kubernetes handles network security and access control through a combination of built-in features, network policies, and authentication mechanisms.

    Here is how it manages the network between the clusters:

    • Kubernetes allows you to define Network Policies that specify how Pods are allowed to communicate with each other within a namespace.

    • Kubernetes provides various authentication methods, such as client certificates, bearer tokens, and service accounts.

    • Each Pod in Kubernetes can be associated with a Service Account, which provides an identity for the Pod.

    • Kubernetes Ingress resources define rules for managing external access to services within the cluster.

    • Kubernetes enforces network isolation between Pods by default.

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

    Let's walk through an example of how Kubernetes can be used to deploy a highly available web application.

    • First, containerize your web application using Docker.

    • Define a Kubernetes Deployment object that describes how many replicas (copies) of your application should run. For high availability.

    • To distribute incoming traffic among the multiple replicas of your application, create a Kubernetes Service of type "LoadBalancer" or "NodePort."

    • To ensure that each Pod gets its fair share of resources and can handle traffic effectively, configure resource requests and limits in the Deployment manifest.

    • Use Kubernetes-native monitoring tools like Prometheus and Grafana to collect metrics from your application.

    • Create an HPA resource that monitors resource utilization or custom metrics and automatically adjusts the number of replicas.

    • Use Kubernetes' built-in rolling update mechanism to deploy new versions of your application without causing downtime.

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

    A namespace is a virtual cluster within a physical cluster. Namespaces provide a way to logically partition a Kubernetes cluster into multiple distinct environments or projects, each with its own set of resources.

    If you don't specify a namespace for a pod, it will be placed in the default namespace by default. The default namespace is created when the Kubernetes cluster is set up,

  10. How does ingress help in Kubernetes?

    Ingress is an API object that manages external access to services within the cluster. It provides a way to configure the routing of external traffic to different services based on hostnames, paths, and other HTTP/HTTPS request attributes. Ingress acts as a traffic controller, allowing you to define how incoming requests should be handled and which services should receive them.

  11. Explain different types of services in Kubernetes.

    Services are used to expose applications running in pods to network traffic. There are several types of services, each designed for specific use. Here are some common services that are used in Services:

    • ClusterIP: This is the default service type. It exposes the service on an internal cluster IP, making it accessible only within the cluster.

    • NodePort: NodePort services expose the service on a static port on each node's IP. This means the service is accessible on each node's IP address at the specified port.

    • LoadBalancer: LoadBalancer services expose the service using a cloud provider's load balancer (e.g., AWS ELB, GCP Load Balancer). It automatically distributes traffic to the service's pods.

    • Headless: Headless services are used when you don't want Kubernetes to create a cluster IP for a service.

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

    Self-healing in Kubernetes refers to the platform's ability to automatically detect and recover from failures or issues within a cluster without manual intervention. Kubernetes achieves self-healing through various mechanisms, ensuring that applications are resilient and maintain high availability.

    Here are some key aspects of self-healing:

    • ReplicaSets ensure that a specified number of pod replicas are running at all times. If a pod fails or becomes unresponsive, the ReplicaSet automatically creates a replacement pod to maintain the desired replica count.

    • Kubernetes allows you to define health checks for pods using readiness and liveness probes.

    • Kubernetes constantly monitors the health of nodes (worker machines) in the cluster.

    • DaemonSets ensure that a specific pod runs on all or a subset of nodes in the cluster.

  13. How does Kubernetes handle storage management for containers?

    Kubernetes provides several mechanisms for managing storage for containers, allowing you to dynamically provision, attach, and use storage resources. Here's how Kubernetes handles storage management for containers:

    • Storage Classes: Kubernetes introduces the concept of Storage Classes, which abstracts the underlying storage infrastructure and provides a way to define different classes of storage with varying performance and characteristics.

    • Persistent Volumes (PVs) and Persistent Volume Claims (PVCs): Persistent Volumes represent physical storage resources in the cluster. A PV can be dynamically provisioned or pre-allocated, depending on the storage infrastructure and the configuration.

    • Volume Plugins: Kubernetes supports various volume plugins that allow containers to use different types of storage, such as local storage, network-attached storage (NAS), cloud-based storage etc.

  14. How does the NodePort service work?

    NodePort is one of the types of Kubernetes services that allows external access to services running within a Kubernetes cluster. Here's how the NodePort service works:

    • When you create a NodePort service in Kubernetes, it allocates a specific port on every node in the cluster.

    • The NodePort service is associated with a set of pods that you want to expose to the external network.

    • A Cluster IP is also allocated for the service. This internal Cluster IP is used for communication between the service and the pods within the cluster.

    • When an external client (e.g., a user's web browser) sends a request to the NodePort service, the request is directed to any of the nodes in the cluster that have the allocated NodePort open.

    • The selected pod processes the request and sends the response back to the node.

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

    • Multi-Node Cluster:

      1. A multinode cluster, also known as a multi-node cluster, is a Kubernetes cluster that consists of multiple nodes or machines.

      2. Multinode clusters are commonly used in production environments and scenarios where high availability, scalability, and fault tolerance are essential. Each node in a multinode cluster contributes to the cluster's computing and storage capacity, and workloads can be distributed across multiple nodes for load balancing and redundancy.

      3. Multinode clusters offer increased reliability because they can tolerate the failure of individual nodes without disrupting the entire cluster.

    • Single-node Cluster:

      1. A single-node cluster, as the name suggests, is a Kubernetes cluster that consists of only one node or machine.

      2. Single-node clusters are typically used for development, testing, and learning purposes. They are a convenient way to experiment with Kubernetes on a local machine without the complexity of a full multinode cluster.

      3. Single-node clusters are easy to set up and can run on a laptop or desktop computer.

  16. Difference between create and apply in Kubernetes?

    In Kubernetes, both kubectl create and kubectl apply are used to create or update Kubernetes resources.

    • Kubectl Create:

      1. When you use kubectl create, it creates a new resource based on the provided configuration file.

      2. kubectl create is typically used for creating resources that should not be modified or updated after creation.

        #example to create configmap with create command
        kubectl create configmap my-config
  • Kubectl Apply:

    1. When you use kubectl apply, it creates or updates a resource based on the configuration file.

    2. kubectl apply is commonly used for managing resources that need to be maintained or updated over time.

        #Example to use apply in kubernetes
        kubectl apply -f deployment.yml

These questions will help you in DevOps Interview.


<That's all for today. Hope you like it. FOLLOW to join me in the journey of DevOps>

ย