Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Kubernetes Interview Questions and Answers For Freshers 
2.1.
1. What is Kubernetes? 
2.2.
2. How many containers in a pod communicate with each other? 
2.3.
3. When it comes to software and DevOps, what is orchestration?
2.4.
4. What is the difference between Job and POD?
2.5.
5. Explain some of the pod's usage patterns?
2.6.
6. Explain components in the architecture of Kubernetes?
2.7.
7. How do you tie service to a pod or a set of pods?
2.8.
8. What are the various services available in Kubernetes? 
2.9.
9. What are namespaces, exactly? What's wrong with utilizing a single default namespace?
2.10.
10. If we have Pod with two containers, can I ping each other?
3.
Kubernetes Interview Questions and Answers For Intermediate 
3.1.
11. What are the disadvantages of Kubernetes?
3.2.
12. What are the features of Kubernetes?
3.3.
13. Why is a load balancer used in Kubernetes? 
3.4.
14. What does Kube-proxy do?
3.5.
15. What does "pods are ephemeral" mean??
3.6.
16. Describe the role of Kube-apiserver?
3.7.
17. Name the tools used for container monitoring?
3.8.
18. What is the difference between loadbalancerIP and externalP? 
3.9.
19. What is ingress, it runs as a pod or on a pod? 
3.10.
20. What are different ways to provide API security on Kubernetes? 
4.
Kubernetes Interview Questions and Answers For Advanced 
4.1.
21. What is ingress default backend? 
4.2.
22. What is Prometheus in Kubernetes?
4.3.
23. Are deployments with more than one replica automatically doing rolling updates when a new deployment config is applied?
4.4.
24. What issues does container orchestration address?
4.5.
25. What do I need to run the Kubernetes architecture on-premises? 
4.6.
26. Define stateful sets in Kubernetes?
4.7.
27. What exactly is Kubectl? List out some Kubectl commands? 
4.8.
28. What are labels in Kubernetes?
4.9.
29. What are the objectives of the replication controller?
4.10.
30. What are the types of Kubernetes volume?  
5.
Frequently Asked Questions
5.1.
What is Kubernetes vs Docker?
5.2.
What Kubernetes is used for?
5.3.
Why is Kubernetes needed?
6.
Conclusion 
Last Updated: May 29, 2024
Easy

Kubernetes Interview Questions

Kubernetes Interview Questions

Introduction

Kubernetes is a distributed open-source platform that allows us to schedule and execute application containers across clusters. There are two sorts of resources in a Kubernetes cluster:

The Master => Coordinates all cluster actions, such as scheduling applications, preserving their state, scaling applications, and deploying new updates.

Nodes => In a Kubernetes cluster, a node is an instance of an OS that operates as a worker computer.

A node will also contain two components

  1. Agent for controlling and interacting with the master Kubelet
  2. Tools for running container operations (Docker/containers)

Kubernetes Cluster

It is built from the bottom to be a loosely connected set of containers for delivering, managing, and scaling applications. Converges the current and intended state of the system to serve as an engine for resolving state (self-healing). The shared pool of resources (hardware) is hidden from the nodes' underlying hardware to facilitate deployment.

Kubernetes bundles one or more containers into a higher-level structure called a pod, the smallest unit of items that may be deployed on the platform. The container is one level above Pod.

A Pod is always running on a Node, but they share a few resources, such as Shared Volumes, Cluster Unique IP, and information about running each container. The pod's containers will all run on the same node.

The control plane, which is at the heart of Kubernetes, is an API server that allows you to query and alter the state of an object.

POD

 

Kubernetes Interview Questions and Answers For Freshers 

1. What is Kubernetes? 

Source 

Ans: This is one of the most fundamental Kubernetes interview questions, but it's also crucial! Kubernetes is an open-source container orchestration tool or system that automates processes, including containerized application administration, monitoring, scaling, and deployment. It is used to manage many containers (since it can handle the grouping of containers), allowing for the discovery and management of logical units.

2. How many containers in a pod communicate with each other? 

Ans: Containers in a pod share networking resources and can communicate with one another through localhost. For example, if a pod has two containers, one running MySQL on port 3306 and the other running PHP on port 80, the PHP container might contact the MySQL container through localhost:3306.

3. When it comes to software and DevOps, what is orchestration?

Ans: Orchestration integrates numerous services to promptly automate procedures or synchronize data. You need to operate an application with six or seven microservices. If you put them in different containers, communication will become difficult. In this case, orchestration would be useful since it would allow all services in various containers to work together to achieve a single objective.


4. What is the difference between Job and POD?

Ans: A Pod guarantees that a container is continually functioning, but the Job ensures that the pods do their tasks. The Job entails doing a certain activity.

Example: 

kubectl run mypod1 --image=nginx --restart=Never
kubectl run mypod2 --image=nginx --restart=onFailure
○ → kubectl get pods
NAME           READY STATUS   RESTARTS AGE
mypod1         1/1 Running   0 59s
○ → kubectl get job
NAME     DESIRED SUCCESSFUL   AGE
mypod1   1 0            19s

 

5. Explain some of the pod's usage patterns?

Ans: There are two major methods to use pods:

  • A pod runs a single container: A single container per pod is the simplest and most frequent Pod design, with each container representing a full application. A Pod may be thought of as a wrapper in this scenario.
  • Pods that operate several containers must communicate with one another: Multiple-container pods are typically used to run co-located, co-managed projects requiring resource sharing. One container serving files from a shared drive, while another container refreshes or updates those files, might create a single coherent service unit. The Pod binds these containers and storage resources into a single, controllable entity.

Each Pod is designed to execute a single application instance. If you wish to run many application instances, create one Pod for each instance. Replication is the term for this process. A controller, such as a Deployment, creates and manages replicated Pods as a group.

6. Explain components in the architecture of Kubernetes?

Ans: Different components are: 

  • Master Node: The master node is the first and most important component in the Kubernetes cluster, and it is responsible for cluster administration. It serves as the starting point for all administrative tasks. The cluster may include more than one master node to ensure fault tolerance.
  • API Server: The API server is the entry point for any REST commands used to operate the cluster.
  • Scheduler: The slave node's tasks are scheduled by the scheduler. It keeps track of how much each slave node uses its resources. It is in charge of allocating workload.
  • ETCD: Wright values, etcd components, and store configuration info. To accept orders and function, it connects with the most component. It also takes care of network rules and port forwarding.
  • Worker/slave nodes: Worker/slave nodes are another important component that provides all the services needed to handle container networking, connect with the master node, and assign resources to scheduled containers.
  • Kubelet: It obtains a Pod's configuration from the API server and verifies that the containers mentioned are up and running.
  • Docker Container: Each worker node has a Docker container that executes the defined pods.
  • Pods: A pod is a collection of one or more containers that execute logically on the same node.

7. How do you tie service to a pod or a set of pods?

Ans: By labeling pods and including a selection in the service that functions as a glue to keep the service attached to the pods.

apiVersion: v1
metadata:
name: my-service
spec:
  selector:
    app: MyApp
ports:
- protocol: TCP
port: 80

 

8. What are the various services available in Kubernetes? 

Ans: Some of the services accessible in Kubernetes are: 

1) Cluster IP service

2) Load Balancer service 

3) Node Port service, and 

4) External Name Creation service 

9. What are namespaces, exactly? What's wrong with utilizing a single default namespace?

Ans: Namespaces allow you to divide your cluster into virtual clusters where you may organize your applications logically and independently from the rest of the cluster (for example, create an app with the same name in two different namespaces).

  • Using the default namespace alone makes it difficult to keep track of all the apps you administer in your cluster over time. Namespaces make it easy to divide apps into logical groupings, such as a namespace for all monitoring programs and another for all security applications, and so on.
  • Namespaces are especially helpful for managing Blue/Green environments, as each namespace may include many versions of an app and share resources with other namespaces (namespaces like logging, monitoring, etc.).
  • One cluster, numerous teams, is another use case for namespaces. When numerous teams share the same cluster, they may step on each other's toes. If they end up establishing an app with the same name, it signifies one of the teams has taken over the other's app since Kubernetes can't have two applications with the same name (in the same namespace).

10. If we have Pod with two containers, can I ping each other?

Ans: Containers in the same pod seem to be on the same computer. You may ping them directly using localhost: port. Each container in a pod has the same IP address. Inside a pod, you may ping localhost. Two containers in the same pod have the same IP address and network namespace, and they are both localhost. This is how discovery works: Component A's pods -> Component B's Service -> Component B's pods and Services have domain names servicename.namespace.svc.cluster.local, and the DNS search path of pods includes such stuff by default, so a pod in namespace Foo may connect to 'bar' to locate a Service bar in the same namespace Foo.

 

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Kubernetes Interview Questions and Answers For Intermediate 

11. What are the disadvantages of Kubernetes?

Ans: Disadvantages are: 

  • The Kubernetes dashboard isn't nearly as useful as it might be.
  • The security system is ineffective.
  • It is quite complicated and has the potential to hinder productivity.
  • Kubernetes is more expensive than its competitors..

12. What are the features of Kubernetes?

Ans: Main Features of Kubernetes include

  1. Automated Scheduling: Kubernetes provides an advanced scheduler to launch containers on cluster nodes. 
  2. Self Healing Capabilities: Rescheduling, Replacing, and restarting the containers which have died. 
  3. Automated Rollouts and Rollbacks: Kubernetes supports rollouts and rollbacks for the desired state of the containerized application
  4. Horizontal scaling and load balancing: Kubernetes can scale up and scale down the application as per the requirements.

13. Why is a load balancer used in Kubernetes? 

Ans: Load balancing is a technique for distributing incoming traffic across different backend servers and ensuring that the application is accessible to consumers.

In Kubernetes, as illustrated in the diagram above, all incoming traffic is routed to a single IP address on the load balancer, which is a method to expose your service to the outside world and send the traffic to a specific pod (through service) using a round-robin algorithm. Even if a pod goes down, load balancers are alerted, and traffic is not directed to that unavailable node. As a result, Kubernetes load balancers are in charge of distributing a set of tasks (incoming traffic) to the pods.

14. What does Kube-proxy do?

Ans:  Kube-proxy has two functions.

  • Open a random port on the node for each Service and proxy that port to the Service.
  • Install and maintain iptables rules that collect visits to a virtual IP: port and forward them to the port.

The kube-proxy component is responsible for managing host sub-netting and making services accessible to other components.

Shutting down the master does not prevent a node from providing traffic, and kubeproxy functions in the same manner as a service. Iptables will forward the connection to the Kube proxy, then deliver it to one of the service's pods. The target address is translated to whatever is in the endpoints by kube-proxy.

15. What does "pods are ephemeral" mean??

Ans: Pods are transient. They are not intended to operate indefinitely, and once canceled, they cannot be brought back. Pods do not vanish unless a user or a controller removes them.

Pods do not "repair" or "heal" on their own. If a Pod is scheduled on a node that fails later, the Pod will be destroyed. Similarly, if a Pod is ejected from a node, it will not be replaced.

16. Describe the role of Kube-apiserver?

Ans: This type verifies API objects and offers configuration data. Pods, services, and replication controllers are all included. It also serves as the cluster's frontend and offers REST operations. All other components communicate via this common frontend cluster state.

17. Name the tools used for container monitoring?

Ans:  Tools that are used for container monitoring are:

  • Heapster
  • cAdvisor
  • Prometheus
  • InfluxDB
  • Grafana

18. What is the difference between loadbalancerIP and externalP? 

Ans: The loadbalancerIP is not a fundamental Kubernetes feature; it must be set up by a cloud provider or controller like metallb. MetalLB creates an IP from its pool and assigns it as that Service's External LoadBalanced IP when it finds a Service of type=LoadBalancer with a ClusterIP established. On the other side, kubelet configures the externalIP such that any traffic submitted to any node with that externalIP as the end destination is routed. 'ExternalIP' is a tool for establishing your own load-balancing and implies you already have control over said IP and have appropriately configured traffic to that IP to finally arrive at one or more of your cluster nodes. On cloud systems such as GKE, you should set'spec.loadBalancerIP' to the IP you preallocated instead. When you attempt to build the service with.'loadBalancerIP' instead of 'externalIP,' the ephemeral port isn't created, and the external IP address is stuck in 'pending>' and never changes.

19. What is ingress, it runs as a pod or on a pod? 

Ans: An ingress is a rule set for an ingress controller, which is simply a reverse proxy that is used to display a configuration file (in the case of nginx-ingress, for example). It enables you to access your Kubernetes services from outside the cluster. It has a set of guidelines. A controller is an Ingress Controller. A Kubernetes Deployment is often used. The ingress component of such deployment is a reverse proxy, while the controller part is a reconciler. The reconciler configures the reverse proxy based on the ingress object's rules. Ingress controllers monitor the K8s API for updates and adjust their configuration accordingly. The rules assist in passing information to a controller that is listening for it. Nothing will happen unless you have a controller that can handle the ingress rules.

Ingress controller pods -> LoadBalancer service -> App service (through ingress) -> App pods

20. What are different ways to provide API security on Kubernetes? 

Ans:  The following are some of the methods for ensuring API security:

  • Using the proper authentication mode for the API server authentication mode= Node, RBAC
  • Assuring that traffic is encrypted via TLS
  • Authentication using API
  • Using authorization-mode=Webhook to ensure that kubeless safeguards its API.
  • Failures in RBAC monitoring
  • Default Service Account permissions are being removed.
  • Ascertaining that the kube-dashboard follows a tight RBAC policy
  • Pod security policy implementation for container limits and node protection
  • Using the most recent kube version

 

Kubernetes Interview Questions and Answers For Advanced 

21. What is ingress default backend? 

Ans: It describes what to do with an incoming Kubernetes cluster request that isn't mapped to any backend, i.e. what to do when the incoming HTTP request has no rules set. If the default backend service is not set, it is advised that it be defined so that users do not get an ambiguous error message.

22. What is Prometheus in Kubernetes?

Ans: Prometheus is a monitoring and alerting software program. It can communicate with your systems, capture real-time measurements, compress them, and store them correctly in a database.

23. Are deployments with more than one replica automatically doing rolling updates when a new deployment config is applied?

Ans: When.spec.strategy.type==RollingUpdate is set, the Deployment updates Pods in a rolling update method. You may regulate the rolling update process by specifying maxUnavailable and maxSurge. The default deployment technique is rolling update. Pods and ReplicationControllers are updated in a similar way via kubectl rolling-update. Deployments, on the other hand, are encouraged since they are declarative and contain extra capabilities, such as the ability to roll back to any prior version even after the rolling update is completed. A readiness probe is required for rolling updates to perform as expected. Redeploying deployments is simple, however, I like rolling updates since they allow me to avoid downtime. The following is how to apply kubctl to a rolling update of a deployment.

spec:
minReadySeconds: 180
replicas: 9
revisionHistoryLimit: 20
selector:
matchLabels:
deployment: standard
name: standard-pod
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate

 

24. What issues does container orchestration address?

Ans: Containers are separate processes that run in their own namespace. This signifies that the container will be unaware of other containers by default. It will also be unaware of the files, network interfaces, and processes on the machine. While this can substantially aid software portability, it does not address a number of production challenges, like microservices, container discovery, scalability, disaster recovery, or updates.

Using a container orchestrator can significantly reduce production complexity because these technologies are designed to address the difficulties mentioned above. Kubernetes, for example, is designed to connect containers, deploy containers over a complete network, scale and load balance the network depending on container resource use, and upgrade individual containers without downtime.

If you're simply operating one or two containers, you're accurate in thinking that an orchestrator is unnecessary and adds extra complexity.

25. What do I need to run the Kubernetes architecture on-premises? 

Ans: Many on-premises setups are being rebuilt to accommodate Kubernetes. Integrating storage, servers, and networking into a stable system necessitates expert knowledge. Choosing the correct storage and networking equipment for Kubernetes is critical because it permits interaction with storage, load balancers, and other resources. The ability to automate storage and networking components is a fundamental feature of Kubernetes' value proposition.

26. Define stateful sets in Kubernetes?

Ans: The stateful set is a workload API object for managing stateful applications. It may also be used to scale collections of pods and manage deployments. The state information and other data of stateful pods are stored in the stateful set's disc storage.

27. What exactly is Kubectl? List out some Kubectl commands? 

Ans: Kubectl is the command-and-control platform for the Kubernetes cluster. It essentially offers a CLI for running commands against the Kubernetes cluster, as well as numerous options to construct and administer the Kubernetes component

The important Kubectl commands, are:

  • kubectl annotate
  • kubectl cluster-info
  • kubectl attach
  • kubectl apply
  • kubectl config
  • kubectl autoscale
  • kubectl config current-context
  • kubectl config set.

28. What are labels in Kubernetes?

Ans: Labels are a set of keys that each contain a value. Pods, replication controllers, and related services are all linked to the key values. Labels are usually applied to an object during its production. Users can make changes to them in real-time. 

29. What are the objectives of the replication controller?

Ans:  The replication controller's goals are as follows:

  • It is in charge of managing and regulating the pod lifetime.
  • It keeps track of how many clones are operating and if they are within the allowable limit.
  • The replication controller assists the user in checking the status of the pods.
  • It allows you to change a pod. The user can move its location in whatever direction they like.

30. What are the types of Kubernetes volume?  

Ans: The types of Kubernetes Volume are:

  • EmptyDir
  • GCE persistent disk
  • Flocker
  • HostPath
  • NFS
  • ISCSI
  • rbd
  • PersistentVolumeClaim
  • downwardAPI

Frequently Asked Questions

What is Kubernetes vs Docker?

Kubernetes and Docker are powerful tools in container orchestration. Docker is a platform for developing, shipping, and running applications in containers, while Kubernetes is a container orchestration system, managing the deployment, scaling, and operation of containerized applications, providing robust automation and scalability for cloud-native environments.

What Kubernetes is used for?

Kubernetes is used for container orchestration, automating the deployment, scaling, and management of containerized applications. It ensures efficient resource utilization, facilitates seamless scaling, and enhances application resilience, making it a cornerstone for managing and deploying microservices in cloud-native environments.

Why is Kubernetes needed?

Kubernetes is essential for several reasons. It automates the deployment and scaling of containerized applications, streamlining complex processes. It ensures high availability, fault tolerance, and efficient resource utilization, simplifying the management of microservices. Kubernetes is crucial for orchestrating containerized workloads in dynamic and scalable environments, making it a foundational tool in modern cloud-native development.

Conclusion 

In this article, we discussed the Kubernetes interview questions. This is final part of the Kubernetes interview questions covering advanced-level questions. For beginner and intermediate level questions, please refer 30 Kubernetes Interview Questions: Intermediate Level and  30 Kubernetes Interview Questions: Intermediate Level

Recommended Readings:

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem DesignMachine learning and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Previous article
Power Automate Interview Questions
Next article
Top 30 Tally Interview Questions and Answers (2024)
Live masterclass