Kubernetes interview questions
58 questions with answers. 2,401 open jobs in India ask for Kubernetes.
What is Kubernetes?
Kubernetes is an open-source container orchestration platform used to manage, scale, and deploy containerised applications across multiple hosts. It automates tasks like scheduling, load balancing, rolling updates, and self-healing, ensuring applications run reliably and efficiently in production environments.
From Tech Vault (Apache 2.0)
What problems does Kubernetes solve?
Kubernetes solves the challenges of running containerised applications at scale. It handles automated deployment, scaling, and management of containers across multiple hosts, provides load balancing, self-healing for failed containers, and simplifies networking and storage. This ensures applications remain available, resilient, and easy to maintain in production.
From Tech Vault (Apache 2.0)
What is the difference between Docker and K8s?
Docker is a platform for building, running, and managing individual containers, while Kubernetes (K8s) is an orchestration system for deploying and managing many containers across multiple hosts. Docker focuses on containerisation itself, whereas Kubernetes handles scaling, load balancing, and maintaining containerised applications in production.
From Tech Vault (Apache 2.0)
What are the core components of the control plane and data plane? What are the components used for?
In Kubernetes, the control plane manages the cluster and makes global decisions. Its core components include the API server (handles requests), etcd (stores cluster state), scheduler (assigns workloads to nodes), and controller manager (maintains desired state). The data plane runs workloads on nodes and includes the kubelet (ensures containers run), kube-proxy (handles networking), and the container runtime. The control plane directs the cluster, while the data plane executes workloads.
From Tech Vault (Apache 2.0)
What is a Pod and what does it do?
A Pod is the smallest deployable unit in Kubernetes and represents one or more containers that share the same network, storage, and lifecycle. Pods allow containers to communicate easily and manage resources together. They provide isolation, scheduling, and scaling, and are the basic building blocks for running applications in a Kubernetes cluster.
From Tech Vault (Apache 2.0)
How can containers within a pod communicate with each other?
Containers within a pod communicate with each other using localhost networking because they share the same network namespace. They can also share volumes for file-based communication. This allows containers in the same pod to easily exchange data and coordinate their tasks.
From Tech Vault (Apache 2.0)
What is a K8s cluster ?
A Kubernetes cluster is a set of machines (nodes) that run containerised applications under the control of the Kubernetes control plane. It includes master components that manage the cluster and worker nodes that run application workloads. The cluster provides scalability, load balancing, and high availability for applications.
From Tech Vault (Apache 2.0)
What are deployments?
A Deployment in Kubernetes is a resource that manages a set of Pods and ensures the desired number of replicas are running. It handles rolling updates, rollbacks, and scaling, making it easier to deploy and maintain applications reliably in a cluster.
From Tech Vault (Apache 2.0)
What are stateful sets?
A StatefulSet in Kubernetes manages stateful applications that require stable, unique network identities and persistent storage. Unlike Deployments, StatefulSets ensure Pods are created and deleted in a defined order and maintain their data across restarts, making them suitable for databases and other stateful services.
From Tech Vault (Apache 2.0)
How do you restrict pod-to-pod communication in a cluster?
Pod-to-pod communication in a Kubernetes cluster can be restricted using Network Policies. These define rules specifying which Pods can communicate with each other or with external endpoints. By default, all Pods can communicate, so applying network policies allows you to enforce isolation and control traffic between Pods for security.
From Tech Vault (Apache 2.0)
How can I rollback a deployment?
You can rollback a Kubernetes deployment using the kubectl rollout undo command. This restores the deployment to a previous revision, allowing you to quickly recover from failed updates or errors while keeping the desired number of Pods running.
From Tech Vault (Apache 2.0)
What are namespaces?
Namespaces in Kubernetes are virtual clusters within a single physical cluster. They help organise and isolate resources, allowing multiple teams or applications to share the same cluster without interfering with each other. Namespaces also enable resource quotas and access control.
From Tech Vault (Apache 2.0)
What is the role of the kube-apiserver?
The kube-apiserver is the central component of the Kubernetes control plane. It exposes the Kubernetes API, validates and processes requests, and serves as the gateway for all interactions with the cluster. Other control plane components and users communicate with the cluster through the API server.
From Tech Vault (Apache 2.0)
Take me through a full cycle of an app deployment from code to an app running on a pod/deployment.
A full Kubernetes app deployment starts with writing the application code and building a container image, usually with Docker. The image is pushed to a container registry. Next, you create Kubernetes manifests, such as a Deployment and Service, defining how many Pods to run and how they are exposed. Using kubectl apply, the manifests are sent to the API server. The scheduler assigns Pods to nodes, kubelets pull the container image, and the containers start running. The Service exposes the app, allowing users or other Pods to access it. The Deployment ensures the desired state is maintained, handling scaling and updates automatically.
From Tech Vault (Apache 2.0)
Can you explain a simple K8s cluster architecture and the components within it?
A simple Kubernetes cluster has a control plane and worker nodes. The control plane includes the API server (handles requests), etcd (stores cluster state), scheduler (assigns Pods to nodes), and controller manager (maintains desired state). Worker nodes run the application workloads and include the kubelet (manages containers), kube-proxy (handles networking), and the container runtime (like Docker or containerd). The control plane manages the cluster, while worker nodes execute the workloads.
From Tech Vault (Apache 2.0)
What happens when a master node fails?
If a master node fails in Kubernetes, the cluster’s control plane becomes unavailable, meaning no new Pods can be scheduled, and management operations cannot be processed. However, existing workloads on worker nodes continue to run. To prevent downtime, clusters often have high-availability setups with multiple master nodes so that if one fails, others can take over.
From Tech Vault (Apache 2.0)
What is an Ingress controller?
An Ingress controller in Kubernetes is a component that manages external access to services in a cluster, usually via HTTP or HTTPS. It watches Ingress resources and configures a load balancer or reverse proxy to route traffic to the correct service, enabling features like path-based routing, SSL termination, and virtual hosting.
From Tech Vault (Apache 2.0)
How can one build a highly availabe (HA) cluster in K8s?
A highly available (HA) Kubernetes cluster is built by running multiple master nodes across different failure zones. Each master node runs components like the API server, scheduler, and controller manager, often behind a load balancer to distribute requests. Etcd is also configured in a clustered, replicated setup. Worker nodes are spread across zones, ensuring workloads continue running if a node or zone fails.
From Tech Vault (Apache 2.0)
What is the role of ETCD in K8s?
etcd is a distributed key-value store used by Kubernetes to store all cluster state and configuration data. It holds information about Pods, Services, ConfigMaps, and more. The control plane reads from and writes to etcd to ensure the desired state of the cluster is maintained, making it a critical component for reliability and consistency.
From Tech Vault (Apache 2.0)
Explain what are Taints and Tolerations in K8s?
Taints and tolerations in Kubernetes control which Pods can be scheduled on which nodes. A taint is applied to a node to repel certain Pods, while a toleration is applied to a Pod to allow it to be scheduled on nodes with matching taints. This helps isolate workloads, reserve nodes for specific purposes, and manage cluster resources effectively.
From Tech Vault (Apache 2.0)
What are the possible types of deployment? Provide a short description for each type.
- Big Bang / Recreate – Old version down, new up → downtime.
- Rolling – Gradual replacement of instances → zero downtime, needs backward compatibility.
- Blue/Green – Two identical environments; switch traffic instantly → fast rollback, double cost.
- Canary – Roll out to a small user subset first → limits blast radius, needs monitoring.
- A/B Testing – Different versions to different user groups → for business experiments.
- Shadow – New version processes live traffic without affecting response → risk‑free load testing.###### Relative links: Links
- https://devtron.ai/blog/top-6-kubernetes-deployment-strategies/
From Java interview (MIT)
Difference between ClusterIP, NodePort and LoadBalancer service types in Kubernetes?
A ClusterIP exposes the following:
spec.clusterIp:spec.ports[*].port
You can only access this service while inside the cluster. It is accessible from its
spec.clusterIpport. If aspec.ports[*].targetPortis set it will route from the port to the targetPort. The CLUSTER-IP you get when callingkubectl get servicesis the IP assigned to this service within the cluster internally.A NodePort exposes the following:
<NodeIP>:spec.ports[*].nodePortspec.clusterIp:spec.ports[*].port
If you access this service on a nodePort from the node's external IP, it will route the request to
spec.clusterIp:spec.ports[*].port, which will in turn route it to yourspec.ports[*].targetPort, if set. This service can also be accessed in the same way as ClusterIP.Your NodeIPs are the external IP addresses of the nodes. You cannot access your service from
spec.clusterIp:spec.ports[*].nodePort.A LoadBalancer exposes the following:
spec.loadBalancerIp:spec.ports[*].port<NodeIP>:spec.ports[*].nodePortspec.clusterIp:spec.ports[*].port
You can access this service from your load balancer's IP address, which routes your request to a nodePort, which in turn routes the request to the clusterIP port. You can access this service as you would a NodePort or a ClusterIP service as well.
From Stack Overflow: asked by AmazingBergkamp, answered by kellanburket (CC BY-SA 4.0)
kubectl apply vs kubectl create?
Those are two different approaches:
Imperative Management
kubectl createis what we call Imperative Management. On this approach you tell the Kubernetes API what you want to create, replace or delete, not how you want your K8s cluster world to look like.Declarative Management
kubectl applyis part of the Declarative Management approach, where changes that you may have applied to a live object (i.e. throughscale) are "maintained" even if youapplyother changes to the object.You can read more about imperative and declarative management in the Kubernetes Object Management documentation.
tl:dr
They do different things. If the resource exists,
kubectl createwill error out andkubectl applywill not error out.From Stack Overflow: asked by Suresh Vishnoi, answered by Ara Pulido (CC BY-SA 4.0)
Ingress vs Load Balancer
Load Balancer: A kubernetes LoadBalancer service is a service that points to external load balancers that are NOT in your kubernetes cluster, but exist elsewhere. They can work with your pods, assuming that your pods are externally routable. Google and AWS provide this capability natively. In terms of Amazon, this maps directly with ELB and kubernetes when running in AWS can automatically provision and configure an ELB instance for each LoadBalancer service deployed.
Ingress: An ingress is really just a set of rules to pass to a controller that is listening for them. You can deploy a bunch of ingress rules, but nothing will happen unless you have a controller that can process them. A LoadBalancer service could listen for ingress rules, if it is configured to do so.
You can also create a NodePort service, which has an externally routable IP outside the cluster, but points to a pod that exists within your cluster. This could be an Ingress Controller.
An Ingress Controller is simply a pod that is configured to interpret ingress rules. One of the most popular ingress controllers supported by kubernetes is nginx. In terms of Amazon, ALB can be used as an ingress controller.
For an example, this nginx controller is able to ingest ingress rules you have defined and translate them to an nginx.conf file that it loads and starts in its pod.
Let's for instance say you defined an ingress as follows:
apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: ingress.kubernetes.io/rewrite-target: / name: web-ingress spec: rules: - host: kubernetes.foo.bar http: paths: - backend: serviceName: appsvc servicePort: 80 path: /appIf you then inspect your nginx controller pod you'll see the following rule defined in
/etc/nginx.conf:server { server_name kubernetes.foo.bar; listen 80; listen [::]:80; set $proxy_upstream_name "-"; location ~* ^/web2\/?(?<baseuri>.*) { set $proxy_upstream_name "apps-web2svc-8080"; port_in_redirect off; client_max_body_size "1m"; proxy_set_header Host $best_http_host; # Pass the extracted client certificate to the backend # Allow websocket connections proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Real-IP $the_real_ip; proxy_set_header X-Forwarded-For $the_x_forwarded_for; proxy_set_header X-Forwarded-Host $best_http_host; proxy_set_header X-Forwarded-Port $pass_port; proxy_set_header X-Forwarded-Proto $pass_access_scheme; proxy_set_header X-Original-URI $request_uri; proxy_set_header X-Scheme $pass_access_scheme; # mitigate HTTPoxy Vulnerability # https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/ proxy_set_header Proxy ""; # Custom headers proxy_connect_timeout 5s; proxy_send_timeout 60s; proxy_read_timeout 60s; proxy_redirect off; proxy_buffering off; proxy_buffer_size "4k"; proxy_buffers 4 "4k"; proxy_http_version 1.1; proxy_cookie_domain off; proxy_cookie_path off; rewrite /app/(.*) /$1 break; rewrite /app / break; proxy_pass http://apps-appsvc-8080; }Nginx has just created a rule to route
http://kubernetes.foo.bar/appto point to the serviceappsvcin your cluster.Read the rest at the sourceFrom Stack Overflow: asked by arunkjn, answered by Lindsay Landry (CC BY-SA 4.0)
What's the difference between Docker Compose and Kubernetes?
- Containers are at the core of the other technologies listed here
- Docker is a popular implementation of the technology that allows applications to be bundled into a container.
dockeris a command-line tool to manage images, containers, volumes, and networks
- Docker Compose is the declarative version of the docker cli
- It can start one or more containers
- It can create one or more networks and attach containers to them
- It can create one or more volumes and configure containers to mount them
- All of this is for use on a single host
- Docker swarm has been abandoned by Docker Inc. and is not being actively maintained or supported.
- Docker Swarm is for running and connecting containers on multiple hosts.
- Docker Swarm is a container cluster management and orchestration tool.
- It manages containers running on multiple hosts and does things like scaling, starting a new container when one crashes, networking containers ...
- The Docker Swarm file named stack file is very similar to a Docker Compose file
- The only comparison between Kubernetes and Compose is at the most trivial and unimportant level: they both run containers, but this says nothing to help one understand what the two tools are and where they are useful. They are both useful for different things
- Kubernetes (K8S) is a distributed container orchestration tool initially created by Google
- It was open-sourced in 2014 and handed over to the Cloud Native Computing Foundation (CNCF) the following year
- The CNCF is an industry body with hundreds of members drawn from the majority of large cloud, software and hardware companies
- At the time of writing (late 2021) there are nearly a thousand K8S related projects split into around twenty classes with a total of over $21 billion dollars in funding
- Kubernetes (2021) is the most popular distributed system orchestrator in the world with 88% adoption
- Because of its near ubiquity, K8S has become the most popular contemporary platform for innovative system development in 2021
- Kubernetes is a competitor (more or less) to Docker swarm but does more stuff than docker swarm i.e a popular choice.
From Stack Overflow: asked by George Katsanos, answered by yamenk (CC BY-SA 4.0)
What's the difference between Apache's Mesos and Google's Kubernetes?
Kubernetes is an open source project that brings 'Google style' cluster management capabilities to the world of virtual machines, or 'on the metal' scenarios. It works very well with modern operating system environments (like CoreOS or Red Hat Atomic) that offer up lightweight computing 'nodes' that are managed for you. It is written in Golang and is lightweight, modular, portable and extensible. We (the Kubernetes team) are working with a number of different technology companies (including Mesosphere who curate the Mesos open source project) to establish Kubernetes as the standard way to interact with computing clusters. The idea is to reproduce the patterns that we see people needing to build cluster applications based on our experience at Google. Some of these concepts include:
- pods — a way to group containers together
- replication controllers — a way to handle the lifecycle of containers
- labels — a way to find and query containers, and
- services — a set of containers performing a common function.
So with Kubernetes alone you will have something that is simple, easy to get up-and-running, portable and extensible that adds 'cluster' as a noun to the things that you manage in the lightest weight manner possible. Run an application on a cluster, and stop worrying about an individual machine. In this case, cluster is a flexible resource just like a VM. It is a logical computing unit. Turn it up, use it, resize it, turn it down quickly and easily.
With Mesos, there is a fair amount of overlap in terms of the basic vision, but the products are at quite different points in their lifecycle and have different sweet spots. Mesos is a distributed systems kernel that stitches together a lot of different machines into a logical computer. It was born for a world where you own a lot of physical resources to create a big static computing cluster. The great thing about it is that lots of modern scalable data processing application run well on Mesos (Hadoop, Kafka, Spark) and it is nice because you can run them all on the same basic resource pool, along with your new age container packaged apps. It is somewhat more heavy weight than the Kubernetes project, but is getting easier and easier to manage thanks to the work of folks like Mesosphere.
Now what gets really interesting is that Mesos is currently being adapted to add a lot of the Kubernetes concepts and to support the Kubernetes API. So it will be a gateway to getting more capabilities for your Kubernetes app (high availability master, more advanced scheduling semantics, ability to scale to a very large number of nodes) if you need them, and is well suited to run production workloads (Kubernetes is still in an alpha state).
When asked, I tend to say:
Kubernetes is a great place to start if you are new to the clustering world; it is the quickest, easiest and lightest way to kick the tires and start experimenting with cluster oriented development. It offers a very high level of portability since it is being supported by a lot of different providers (Microsoft, IBM, Red Hat, CoreOs, MesoSphere, VMWare, etc).
If you have existing workloads (Hadoop, Spark, Kafka, etc), Mesos gives you a framework that let's you interleave those workloads with each other, and mix in a some of the new stuff including Kubernetes apps.
Mesos gives you an escape valve if you need capabilities that are not yet implemented by the community in the Kubernetes framework.
From Stack Overflow: asked by binaryanomaly, answered by Craig Mcluckie (CC BY-SA 3.0)
What is the difference between a pod and a deployment?
Both Pod and Deployment are full-fledged objects in the Kubernetes API. Deployment manages creating Pods by means of ReplicaSets. What it boils down to is that Deployment will create Pods with spec taken from the template. It is rather unlikely that you will ever need to create Pods directly for a production use-case.
From Stack Overflow: asked by Bjorn, answered by Radek 'Goblin' Pieczonka (CC BY-SA 3.0)
Where does the convention of using /healthz for application health checks come from?
It historically comes from Google’s internal practices. They're called "z-pages".
The reason it ends with
zis to reduce collisions with actual application endpoints with the same name (like/status). See this talk for more: https://vimeo.com/173610242 (26:50-)Similar endpoints (at least inside Google) are
/varz,/statusz,/rpcz. Services developed at Google automatically get these endpoints to export their health and metrics and there are tools that collect the exposed metrics/statuses from all the deployed services.Open source tools like Prometheus implement this pattern (since original authors of Prometheus are also ex-Googlers) by coming to a well-known endpoint to collect metrics from your application. Similarly OpenCensus allows you to expose z-pages from your app (ideally on a different port) to diagnose problems.
From Stack Overflow: asked by Andy Hume, answered by ahmet alp balkan (CC BY-SA 4.0)
Difference between targetPort and port in Kubernetes Service definition
Service: This directs the traffic to a pod.
TargetPort: This is the actual port on which your application is running inside the container.
Port: Sometimes your application inside the container serves different services on a different port.
Example: The actual application can run on port 8080 and health checks for this application can run on port 8089 of the container. So if you hit the service without a port, it doesn't know to which port of the container it should redirect the request. The service needs to have a mapping so that it can hit the specific port of the container.
kind: Service apiVersion: v1 metadata: name: my-service spec: selector: app: MyApp ports: - name: http nodePort: 30475 port: 8089 protocol: TCP targetPort: 8080 - name: metrics nodePort: 31261 port: 5555 protocol: TCP targetPort: 5555 - name: health nodePort: 30013 port: 8443 protocol: TCP targetPort: 8085if you hit my-service:8089, the traffic is routed to 8080 of the container(
targetPort). Similarly, if you hit my-service:8443, then it is redirected to 8085 of the container(targetPort). But this myservice:8089 is internal to the kubernetes cluster and can be used when one application wants to communicate with another application. So, to hit the service from outside the cluster someone needs to expose the port on the host machine on which kubernetes is running so that the traffic is redirected to a port of the container. This isnodePort(port exposed on the host machine). From the above example, you can hit the service from outside the cluster(Postman or any rest-client) byhost_ip:nodePortSay your host machine ip is 10.10.20.20 you can hit the http, metrics, health services by 10.10.20.20:30475, 10.10.20.20:31261, 10.10.20.20:30013.
From Stack Overflow: asked by Mr.DevEng, answered by Manikanta P (CC BY-SA 4.0)
Is there a way to share secrets across namespaces in Kubernetes?
Secret API objects reside in a namespace. They can only be referenced by pods in that same namespace. Basically, you will have to create the secret for every namespace.
For more details, see this: Kubernetes Documentation / Concepts / Configuration / Secrets
From Stack Overflow: asked by matth3o, answered by Innocent Anigbo (CC BY-SA 4.0)
Related topics
Where these questions come from
Open-source collections on GitHub, official documentation, a government careers service and the Stack Exchange sites, each used under its own licence. The answers are the authors' own words: we only tidy the layout, leave out pictures, and cut a long answer with a link to the rest. Stack Exchange answers stay under CC BY-SA and name who asked and who answered.
- Tech Vaultby moabukar and contributorsApache 2.020 questions
- Java interviewby Anton LiauchukMIT, © 2020 Anton Liauchuk1 question
- Stack Overflowby its contributors, named on each answerCC BY-SA24 questions
- DevOps Stack Exchangeby its contributors, named on each answerCC BY-SA13 questions