Top 20+ Most Asked Kubernetes Interview Questions for 2021

by StarAgile

April 15, 2021
Category DevOps


KUBERNETES INTERVIEW QUESTIONS

Description: 

Kubernetes is also one of the most used container management platforms. A keen understanding of Kubernetes can help you further your career. If you want to make sure you can land that job, then preparing the answers for the most commonly asked Kubernetes interview questions is just what you need to do.

Introduction: 

Almost all the major companies are adopting Kubernetes as their container management platform. To advance your career and get a well-paying job at a multinational company, prepare for your interview with Kubernetes interview questions and answers.

Overview: 

When it comes to containerization, Kubernetes has become the industry standard. Many institutions that rely on containers for development and deployment use Kubernetes. Given this, there is a high demand for professionals who are well-versed in Kubernetes.

It is not enough to know Kubernetes; you need to display your knowledge to the interviewer and convince them that you are the best person for the job. As with anything else, the only way to ace an interview is by practising. You should go through some of the most common Kubernetes interview questions and figure out their answers. 

Kubernetes Interview Questions And Answers

The Kubernetes interview questions and answers test your knowledge in more ways. The interview questions on Kubernetes are categorized as domain-based, skill-based and scenario-based to help you prepare. 

Domain-Based Kubernetes Interview Questions

Domain-based Kubernetes interview questions try to gauge your knowledge of the fundamentals of Kubernetes. These interview questions on Kubernetes will mostly ask you about various components and functions of Kubernetes or to differentiate between items. 

1) What is Kubernetes, and what are its features?

True to the Greek translation of its name, Kubernetes is a helmsman for containers in applications. It is a container management system that can automate the monitoring, managing, deployment and scaling of containerized applications. It helps organizations deploy applications faster to keep up with the changing needs of the customer.

Some of its features are:

      - Automated Scheduling: The Kubernetes scheduler can launch containers of cluster nodes.

     - Self-Healing Capabilities: It automatically reschedules, replaces and restarts the containers that have died.

     - Automated Rollouts and Rollbacks: Organizations can rollout and rollback the applications with ease.

     - Load Balancing and Horizontal Scaling: An application deployed using Kubernetes can scale up or down depending on the current needs.   

2) What are the differences between Kubernetes and Docker Swarm?

Docker Swarm is another container management platform native to Docker. Kubernetes interview questions such as these are analyzing your knowledge of Docker Swarm as well as Kubernetes. Here are the differences between kubernetes and docker.

Kubernetes
Docker
Installation is complicated but the platform is very robust once installed.
Installation is simple but the cluster is not robust.
Highly scalable and can scale automatically
Scaling is faster than Kubernetes, but cannot scale automatically
Can deploy rolling updates as well as automatics rollbacks.
Can deploy rolling updates but cannot do automatic rollbacks.
Kubernetes dashboard offers a GUI.
There is no GUI.
In-built monitoring and logging tools.
Need to use third-party tools for logging and monitoring. 
Need to intervene manually to balance the load between different containers. 
Does automatic load balancing.
Containers in the same pod can share storage space. 
Containers can share storage across the board.
Can manage complex applications.
Can only orchestrate single Docker containers.

3) What is a node? What does the node status contain? 

A node is a machine in the cluster. It is the smallest unit of computing hardware. The node can either be a virtual machine or a physical machine. The node contains services to run the pods.

The status of the node contains its address, condition, capacity, and info.

DevOps Training

4) What is a pod in Kubernetes? What is a daemon set?

A pod is a high-level structure that wraps around containers running on the same host. You can also think of a pod as the smallest unit of Kubernetes administrators. The containers within a pod share resources and a local network. They can easily communicate while also ensuring that there is a level of isolation between various containers.

Daemon sets are a set of pods that only run once on a host. You may need to measure host-level attributes such as the network conditions. Daemon sets can do this as it is a one-time job. 

5) What is a controller manager in Kubernetes? What are the different types of controller managers in Kubernetes? 

The controller manager is a daemon set that regulates the state of the system. It is embedded in the core control loops, Namespace creations and garbage collection. The controller is the reason the Master node can run multiple processes.

The different types of controller managers are:

Replication controller

Endpoints controller

Namespace controller

Service accounts controller

Token controller

Node controller

6) What is the role of the Kube-scheduler and Kube-API server?

The Kube-scheduler is responsible for distributing the workload to the Worker nodes. It schedules the tasks for the worker nodes. It stores the information regarding the resources of all the nodes. When a new task arrives, the scheduler selects the node that is most suitable for running it based on the resources it has.

The Kube-API server is the front end of the Master node. It is the point of entry for REST commands which control the cluster. It configures and validates data for all API objects in Kubernetes. 

7) Can you explain the Kubernetes architecture? 

There are two main components in the Kubernetes architecture - the Master Node and Worker Node. The Master node contains the Kube-scheduler, controller manager, etc. and Kube-API server.

The Worker node contains pods and the services needed to communicate with the Master node as well as to manage the containers. The Kubelet receives the configurations of the pods from the API server and ensures that the required containers are running as needed.

8) What is Kube-proxy?

Kube-proxy is a proxy that runs on every node and maintains the network rules on the nodes. It can forward TCP/UDP packets across backend network service. If an operating system packet filtering layer is available, then Kube-proxy uses it to forward packets. Otherwise, it forwards the packets on its own. 

Skill-Based Kubernetes Interview Questions

Knowledge of various aspects of Kubernetes can only take you so far. You should have the skills necessary to excel at the job. Skill-based Kubernetes interview questions and answers test if you have the skills necessary to become a Kubernetes professional. 

9) What are some of the modifications that an organization needs to make to run Kubernetes architecture?

Kubernetes requires the right kind of storage and networking equipment to ensure that all its processes can run smoothly. You will need to integrate the storage, network and servers in one flawless environment. Setting all this up may take a little while and maybe a little complicated, but the setup is a one time job. Once installed, Kubernetes will automate storage and networking, and you will not have to bother with it again. 

10) What are the different services used by Kubernetes?

There are four different types of services on Kubernetes. 

     - Cluster IP service: It is the default service types that expose the services within the internal cluster. It makes the service reachable only within the cluster.    

     - Node Port service: It exposes the service on each node's IP at a static port. 

     - External Name Creation service: It maps the service to the contents of the External Name Field by a CNAME record with its value.

     - Load Balancer service: It uses a cloud provider's load balancer to expose the service externally.  

11) Can you schedule pods on a tainted node? 

The pods on a tainted node will not be scheduled by default. However, you can achieve this by applying tolerations to the pod specifications. You can do that as follows.

spec:

tolerations:

- key: "key"

operator: "Equal"

value: "value"

effect: "NoSchedule"

12) Can you use many claims out of a persistentVolume? 

You cannot use many claims out of a persistentVolume. This is because persistentVolume and persistentVolumeClaims have a one-to-one relationship. The persistentVolumeReclaimPolicy is set to Retain, and so, persistentVolume will remain even if you delete the claim. But it cannot be used by any other claim.

13) How will you provide API security on Kubernetes? 

With security being a crucial consideration in today's world and security being considered one of its weaknesses, Kubernetes interview questions such as this one will test your ability to make the platform secure and protect it from threats. 

There are various things you can do to amp up API security.

      - Use Transport Layer Security or TLS for all API traffic. 

      - Always make sure to use the latest version of Kubernetes. Kubernetes platform is constantly being updated to enhance its security.

      - Ensure that all API clients are authenticated. 

      - Use Role-Based-Access-Control to control access to Kubernetes API. 

      - Ensure that the production clusters have enabled Kubelet authentication and authorisation. 

      - Limit the permission given to instant credentials while running Kubernetes on a cloud platform.

      - Restrict the pod access to metadata API using network policies. 

      - Run sensitive workloads in a dedicated set of machines.

      - Restrict access to untested alpha and beta features as they may have security vulnerabilities. 

      - Enable audit logs and monitor them for unwanted API calls. 

14) How will you determine if a pod is always running?

You can use a liveness probe to determine if the pod is always running. A probe is a diagnostic that returns either Success, Failure or Unknown. The kubelet runs the probe on containers from time to time.

If the liveness probe returns a Failure, then the kubelet kills the container and restarts it. 

15) How can you ensure that the pod automatically comes up when the host restarts?

You can use a replication controller to ensure that the pod automatically comes up when the host restarts. The replication controller supervises pods that have been running for a long time. The controller launches a specific number of pods called replicas and ensures that they are kept running. 

16) Is there a way to test a manifest without executing it? If so, what is it?

There is a way to test a manifest without running it. You can use the --dry-run flag to do so. It helps you preview the object without actually sending it. You can use it to check the YAML syntax and to ensure that the specification has the required key-value pairs. 

17) How will you drain traffic from a pod during maintenance?

You can drain traffic using the command:

kubectl drain <nodename>

The command ensures that no new pods are assigned to the node. It also evicts the existing pods or deletes them if eviction is not supported. 

Scenario-Based Kubernetes Interview Questions

Domain knowledge and skills are important to land a job as a Kubernetes professional. But more than that, you should know how to apply the knowledge during various scenarios. 

The Kubernetes interview questions and answers for experienced professionals will include scenario-based interview questions on Kubernetes to test how well you can apply your knowledge in various scenarios.

Scenario-based Kubernetes interview questions for freshers are also equally important. While there are many things you will learn on the job, Kubernetes interview questions like these are designed to test how you approach various scenarios and to understand your thought process.

18) A company is built on monolithic architecture and has several products. The monolithic architecture is causing issues when the company is scaling. How can the company shift to microservices? 

The company can start by building microservices piece by piece in parallel and switch configurations in the background. They can then start migrating these microservices on to the Kubernetes platforms one by one. Start small and monitor them to make sure that everything is running as it should. If everything is stable, you can continue migrating in small batches.   

19) A Kubernetes job should finish within a minute. However, there is a possibility that it exceeds this limit considerably in rare instances. How will you stop the application when the job exceeds the usual time?

You can use the activeDeadlineSeconds flag for such occasions. The flag indicates the duration of a job. You have to specify the value for the flag when you create the job specification. Once the job has been running for the duration specified in the flag, it will be terminated automatically.

20) There are two containers running inside a pod, and one stops while the other continues to run. How will you ensure to terminate the pod when this happens? 

You can use a liveness probe and a readiness probe to determine when a container stops running. When the probe fails, you can have the pod terminated.

21) There are multiple containers running inside a pod. You want to wait for a specific container to start before you start another one. How will you achieve this?

You can use Init containers to achieve this. Init containers are similar to regular containers with the exception that they always run to completion and one Init container has to run successfully before the next one starts.

You will have to add the initContainers field in the pod specifications. It will be an array of Container objects. When the pod starts up, the kubelet will wait till the networking and storage is ready and then run the Init containers in the order that they appear in the pod's specifications. If you want containers in a specific order, you should put them in the same order in the pod's specification.  

22) You recently updated the ConfigMap of a pod. You want the container inside the pod to reflect this change. How will you do this? 

There are two ways of ensuring that the changes in the ConfigMap of the pod are reflected in the containers within the pod.

If the ConfigMap is mounted into the pod as a volume, then changes will get updated with a slight delay. The kubelet checks whether the ConfigMap is fresh periodically using its local TTL-based cache. Once the changes are reflected in the cache, and it is detected by the kubelet during its periodic sweep, the changes will be made in the containers as well.

However, this can take up to two minutes. The default Kubelet sync period is one minute, and so is the time to live or TTL of the cache of the ConfigMap.  

If you want the changes to reflect instantaneously, then you will have to update the annotations of the pod. It will trigger an immediate refresh. 

23) Will the rolling updates declared with deployment take effect if I manually delete pods of the replica set? 

The scheduler ensures that the desired number of pods are present. When you manually delete pods, the scheduler will recreate them.  

Bottom Line

Kubernetes is a widely used container management system, and there is a demand for Kubernetes professionals in the software industry. However, the field is also highly competitive. You can use the Kubernetes interview questions and answers given above to give yourself an edge in the interview and land your dream job. 

Find out about the DevOps tools in our DevOps training course.