Kubernetes Interview Questions and Answers
Kubernetes Interview Questions and Answers
1) What is Kubernetes?
Kubernetes is a container management system developed in the Google platform. The
purpose of Kubernetes is to manage a containerized application in various types of
physical, virtual, and cloud environments. Google Kubernetes is a highly flexible container
tool to deliver even complex applications, consistently. Applications run on clusters of
hundreds to thousands of individual servers.
Kubernetes can run on-premises bare metal, OpenStack, public clouds Google,
Azure, AWS, etc.
It helps you to avoid vendor lock issues as it can use any vendor-specific APIs or
services except where Kubernetes provides an abstraction, e.g., load balancer and
storage.
It will enable applications that need to be released and updated without any
downtime.
Kubernetes allows you to assure those containerized apps run where and when
you want and help you to find resources and tools which you want to work.
Automated Scheduling
Self-Healing Capabilities
Automated rollouts & rollback
Horizontal Scaling & Load Balancing
Offers environment consistency for development, testing, and production
Infrastructure is loosely coupled to each component can act as a separate unit
Provides a higher density of resource utilization
Offers enterprise-ready features
Application-centric management
Auto-scalable infrastructure
You can create predictable infrastructure
Master Node: The master node is the first and most vital component which is
responsible for the management of Kubernetes cluster. It is the entry point for all
kinds of administrative tasks. There may be more than one master node in the
cluster to check for fault tolerance.
API Server: The API server acts as an entry point for all the REST commands used
for controlling the cluster.
Scheduler: The scheduler schedules the tasks to the slave node. It stores the
resource usage information for every slave node. It is responsible for distributing
the workload.
Etcd: etcd components, store configuration detail, and wright values. It
communicates with the most component to receive commands and work. It also
manages network rules and port forwarding activity.
Worker/Slave nodes: Worker nodes are another essential component that
contains all the required services to manage the networking between the
containers, communicate with the master node, which allows you to assign
resources to the scheduled containers.
Kubelet: It gets the configuration of a Pod from the API server and ensures that the
described containers are up and running.
Docker Container: Docker container runs on each of the worker nodes, which runs
the configured pods.
Pods: A pod is a combination of single or multiple containers that logically run
together on nodes.
25) What are the tools that are used for container monitoring?
Tools that are used for container monitoring are:
Heapster
cAdvisor
Prometheus
InfluxDB
Grafana
Addons
Node components
Master Components
Condition
Capacity
Info
Address
It enables to runs storage platforms like ceph and glusterd on each node.
Daemon sets run the logs collection on every node such as filebeat or fluentd.
It performs node monitoring on each and every node.
37) Explain Replica set
A Replica set is used to keep replica pods stable. It enables us to specify the available
number of identical pods. This can be considered a replacement for the
replication .controller.
kubectl annotate
kubectl cluster-info
kubectl attach
kubectl apply
kubectl config
kubectl autoscale
kubectl config current-context
kubectl config set.
Using correct auth mode with API server authentication mode= Node.
Make kubeless that protects its API via authorization-mode=Webhook.
Ensure the kube-dashboard uses a restrictive RBAC (Role-Based Access Control)
policy
EmptyDir
GCE persistent disk
Flocker
HostPath
NFS
ISCSI
rbd
PersistentVolumeClaim
downwardAPI
Orchestration refers to the integration of multiple services that allows them to automate
processes or synchronize information in a timely fashion. Say, for example, you have six or
seven microservices for an application to run. If you place them in separate containers, this
would inevitably create obstacles for communication. Orchestration would help in such a
situation by enabling all services in individual containers to work seamlessly to accomplish a
single goal.
This is one of the most frequently asked Kubernetes interview questions, where the
interviewer might as well ask you to share your experience working with any of
them. Docker is an open-source platform used to handle software development. Its main
benefit is that it packages the settings and dependencies that the software/application needs to
run into a container, which allows for portability and several other advantages. Kubernetes
allows for the manual linking and orchestration of several containers, running on multiple
hosts that have been created using Docker.
5. What are the main differences between the Docker Swarm and Kubernetes?
Docker Swarm is Docker’s native, open-source container orchestration platform that is used
to cluster and schedule Docker containers. Swarm differs from Kubernetes in the following
ways:
Docker Swarm is more convenient to set up but doesn’t have a robust cluster,
while Kubernetes is more complicated to set up but the benefit of having the
assurance of a robust cluster
Docker Swarm can’t do auto-scaling (as can Kubernetes); however, Docker scaling
is five times faster than Kubernetes
Docker Swarm doesn’t have a GUI; Kubernetes has a GUI in the form of a
dashboard
Docker requires third-party tools like ELK stack for logging and monitoring, while
Kubernetes has integrated tools for the same
Docker Swarm can share storage volumes with any container easily, while
Kubernetes can only share storage volumes with containers in the same pod
Docker can deploy rolling updates but can’t deploy automatic rollbacks;
Kubernetes can deploy rolling updates as well as automatic rollbacks
Deploying Applications consist of an architecture that has an operating system. The operating
system will have a kernel that holds various libraries installed on the operating system needed
for an application.
Whereas container host refers to the system that runs the containerized processes. This kind is
isolated from the other applications; therefore, the applications must have the necessary
libraries. The binaries are separated from the rest of the system and cannot infringe any other
application.
Kubernetes places control for the user where the server will host the container. It
will control how to launch. So, Kubernetes automates various manual processes.
With Kubernetes, users can scale resources not only vertically but also horizontally
that too easily and quickly.
There are two primary components of Kubernetes Architecture: the master node and the
worker node. Each of these components has individual components in them.
The master node dignifies the node that controls and manages the set of worker nodes. This
kind resembles a cluster in Kubernetes. The nodes are responsible for the cluster management
and the API used to configure and manage the resources within the collection. The master
nodes of Kubernetes can run with Kubernetes itself, the asset of dedicated pods.
This kind validates and provides configuration data for the API objects. It includes pods,
services, replication controllers. Also, it provides REST operations and also the frontend of
the cluster. This frontend cluster state is shared through which all other component interacts.
The main components of a node status are Address, Condition, Capacity, and Info.
13. What process runs on Kubernetes Master Node?
The Kube-api server process runs on the master node and serves to scale the deployment of
more instances.
In this Kubernetes interview question, try giving a thorough answer instead of a one-
liner. Pods are high-level structures that wrap one or more containers. This is because
containers are not run directly in Kubernetes. Containers in the same pod share a local
network and the same resources, allowing them to easily communicate with other containers
in the same pod as if they were on the same machine while at the same time maintaining a
degree of isolation.
A cluster of containers is a set of machine elements that are nodes. Clusters initiate specific
routes so that the containers running on the nodes can communicate with each other. In
Kubernetes, the container engine (not the server of the Kubernetes API) provides hosting for
the API server.
In this Kubernetes interview question, the interviewer would expect a thorough explanation.
You can explain what it is and also it has been useful to you (if you have used it in your work
so far!). A Heapster is a performance monitoring and metrics collection system for data
collected by the Kublet. This aggregator is natively supported and runs like any other pod
within a Kubernetes cluster, which allows it to discover and query usage data from all nodes
within the cluster.
With the help of Minikube, users can Kubernetes locally. This process lets the user run a
single-node Kubernetes cluster on your personal computer, including Windows, macOS, and
Linus PCs. With this, users can try out Kubernetes also for daily development work.
Namespaces are used for dividing cluster resources between multiple users. They are meant
for environments where there are many users spread across projects or teams and provide a
scope of resources.
Default
Kube – system
Kube – public
The primary controller managers that can run on the master node are the endpoints controller,
service accounts controller, namespace controller, node controller, token controller, and
replication controller.
Kubernetes uses etcd as a distributed key-value store for all of its data, including metadata
and configuration data, and allows nodes in Kubernetes clusters to read and write data.
Although etcd was purposely built for CoreOS, it also works on a variety of operating
systems (e.g., Linux, BSB, and OS X) because it is open-source. Etcd represents the state of a
cluster at a specific moment in time and is a canonical hub for state management and cluster
coordination of a Kubernetes cluster.
Cluster IP service
The ClusterIP is the default Kubernetes service that provides a service inside a cluster (with
no external access) that other apps inside your cluster can access.
The LoadBalancer service is used to expose services to the internet. A Network load
balancer, for example, creates a single IP address that forwards all traffic to your service.
An ingress is an object that allows users to access your Kubernetes services from outside the
Kubernetes cluster. Users can configure the access by creating rules that define which
inbound connections reach which services.
How does it work- This is an API object that provides the routing rules to manage the
external users' access to the services in the Kubernetes cluster through HTTPS/ HTTP. With
this, users can easily set up the rules for routing traffic without creating a bunch of load
balancers or exposing each service to the nodes.
You must have heard about Public, Private and hybrid clouds. With the help of cloud
infrastructure technologies, you can run Kubernetes on them. In the context of Cloud
Controller Manager, it is the control panel component that embeds the cloud-specific control
logic. This process lets you link the cluster into the cloud provider's API and separates the
elements that interact with the cloud platform from components that only interact with your
cluster.
This also enables the cloud providers to release the features at a different pace compared to
the main Kubernetes project. It is structured using a plugin mechanism and allows various
cloud providers to integrate their platforms with Kubernetes.
33. What is the difference between a replica set and a replication controller?
It monitors the pods and automatically restarts them if they fail. If the node fails, this
controller will respawn all the pods of that node on another node. If the pods die, they won't
be spawned again unless wrapped around a replica set.
Replica Set, on the other hand, is referred to as rs in short. It is told as the next-generation
replication controller. This kind of support has some selector types and supports the equality-
based and the set-based selectors.
It allows filtering by label values and keys. To match the object, they have to satisfy all the
specified label constraints.
A headless service is used to interface with service discovery mechanisms without being tied
to a ClusterIP, therefore allowing you to directly reach pods without having to access them
through a proxy. It is useful when neither load balancing nor a single Service IP is required.
The aggregation of multiple clusters that treat them as a single logical cluster refers to cluster
federation. In this, multiple clusters may be managed as a single cluster. They stay with the
assistance of federated groups. Also, users can create various clusters within the data center
or cloud and use the federation to control or manage them in one place.
Users can sync resources across different clusters in order to deploy the same deployment set
across the various clusters.
The kubelet is a service agent that controls and maintains a set of pods by watching for pod
specs through the Kubernetes API server. It preserves the pod lifecycle by ensuring that a
given set of containers are all running as they should. The kubelet runs on each node and
enables the communication between the master and slave nodes.
Kubectl is a CLI (command-line interface) that is used to run commands against Kubernetes
clusters. As such, it controls the Kubernetes cluster manager through different create and
manage commands on the Kubernetes component
40. How can you get a static IP for a Kubernetes load balancer?
A static IP for the Kubernetes load balancer can be achieved by changing DNS records since
the Kubernetes Master can assign a new static IP address.
Basic Kubernetes Interview Questions
1. How to do maintenance activity on the K8 node?
Whenever there are security patches available the Kubernetes administrator has to perform
the maintenance task to apply the security patch to the running container in order to prevent
it from vulnerability, which is often an unavoidable part of the administration. The
following two commands are useful to safely drain the K8s node.
kubectl cordon
kubectl drain –ignore-daemon set
The first command moves the node to maintenance mode or makes the node unavailable,
followed by kubectl drain which will finally discard the pod from the node. After the drain
command is a success you can perform maintenance.
Note: If you wish to perform maintenance on a single pod following two commands can be
issued in order:
With the use of limit and request resource usage of a POD can be controlled.
Request: The number of resources being requested for a container. If a container exceeds its
request for resources, it can be throttled back down to its request.
Limit: An upper cap on the resources a single container can use. If it tries to exceed this
predefined limit it can be terminated if K8's decides that another container needs these
resources. If you are sensitive towards pod restarts, it makes sense to have the sum of all
container resource limits equal to or less than the total resource capacity for your cluster.
Example:
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: example1
image:example/example1
resources:
requests:
memory: "_Mi"
cpu: "_m"
limits:
memory: "_Mi"
cpu: "_m"
3. What are the various K8's services running on nodes and describe the role
of each service?
Kube-proxy: This service is responsible for the communication of pods within the cluster
and to the outside network, which runs on every node. This service is responsible to
maintain network protocols when your pod establishes a network communication.
kubelet: Each node has a running kubelet service that updates the running node accordingly
with the configuration(YAML or JSON) file. NOTE: kubelet service is only for containers
created by Kubernetes.
Master services:
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: zk-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: zookeeper
Wait for some time before starting the app Container with a command like sleep 60.
Load balancing is a way to distribute the incoming traffic into multiple backend servers,
which is useful to ensure the application available to the users.
Load Balancer
In Kubernetes, as shown in the above figure all the incoming traffic lands to a single IP
address on the load balancer which is a way to expose your service to outside the internet
which routes the incoming traffic to a particular pod (via service) using an algorithm known
as round-robin. Even if any pod goes down load balances are notified so that the traffic is
not routed to that particular unavailable node. Thus load balancers in Kubernetes are
responsible for distributing a set of tasks (incoming traffic) to the pods
7. What are the various things that can be done to increase Kubernetes
security?
By default, POD can communicate with any other POD, we can set up network policies to
limit this communication between the PODs.
This architecture depends upon the application and many other factors. Following are the
common logging patterns
In the setup, journalbeat and filebeat are running as daemonset. Logs collected by these are
dumped to the kafka topic which is eventually dumped to the ELK stack.
Scaler Courses
A course by
Live learning from top instructors around the country along with 1:1 mentorship
PREMIUM
A course by
Live learning from top instructors around the country along with 1:1 mentorship
PREMIUM
4.90
Enrolled: 78037
Enrolled: 85962
Enrolled: 3754
Enrolled: 4832
Enrolled: 5288
4.8
Enrolled: 1251
Enrolled: 3720
Enrolled: 2096
5
Enrolled: 2832
Enrolled: 1374
4.7
Enrolled: 9429
4.8
Enrolled: 1527
Spring Boot Course: Certified Course for Essential Skills
A course byArnav Gupta
This Spring Boot Course is a beginner-friendly course designed to help you learn the fundamentals
of Spring Boot. You’ll gain hands-on experience in building Spring Boot applications, using various
tools and technologies.
Enrolled: 6308
Enrolled: 4030
Enrolled: 5404
Machine Coding Tic Tac Toe - LLD Case Study
A course byArnav Gupta
Scaler Topics Tic Tac Toe Course Free Course offers a comprehensive introduction to the Low-
Level Design (LLD) of a machine-coded Tic Tac Toe game. As a beginner, you will learn the
fundamental concepts of object-oriented programming, data structures, and algorithms while
working on a real-world project. By the end of this course, you will be proficient in designing and
implementing a complete Tic Tac Toe game from scratch.
Enrolled: 1251
4.8
Enrolled: 8464
SQL for Beginners: Learn SQL using MySQL and Database Design Course
A course byPrateek Narang
Are you interested in learning SQL using MySQL? Look no further than our comprehensive free
online course! Scaler Topics SQL using MySQL free course is designed with beginners in mind and
will teach you the fundamentals of SQL and MySQL, enabling you to build a solid foundation in
database management.
5
Enrolled: 14362
4.5
Enrolled: 11522
4.95
Enrolled: 20042
4.9
Enrolled: 28484
DBMS Course - Master the Fundamentals and Advanced Concepts
A course bySrikanth Varma
Scaler Topics free DBMS course is designed to help beginners learn about the fundamental
concepts of database management systems. The course is completely online, and it comes with a
free certificate of completion that you can add to your resume or LinkedIn profile. You'll learn
about the most popular DBMS like MySQL, Oracle, and SQL Server, as well as the theoretical
foundations of databases.
Enrolled: 38216
Enrolled: 31284
5
Enrolled: 6150
4.8
Enrolled: 39510
4.9
Enrolled: 5377
4.95
Enrolled: 3217
4.9
Enrolled: 2239
Enrolled: 11803
4.8
Enrolled: 7499
PREMIUM
Explore Scaler Premium Program and unlock a world of benefits
Structured Curriculum
Experience expert-led learning with our industry-proven curriculum
Career Support
We're dedicated to helping you achieve your career goals
Explore Scaler for FREE
Explanation -
spec:
selector:
app: some-app
type: LoadBalancer
ports:
- protocol: UDP
port: 8080
targetPort: 8080
nodePort: 32412
Explanation -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: someapp-ingress
spec:
rules:
- host: my.host
http:
paths:
- backend:
serviceName: someapp-internal-service
servicePort: 8080
spec:
tls:
- hosts:
- some_app.com
secretName: someapp-secret-tls
4. Why should namespaces be used? How does using the default namespace
cause problems?
Over the course of time, using the default namespace alone is proving to be difficult, since
you are unable to get a good overview of all the applications you can manage within the
cluster as a whole. The namespaces allow applications to be organized into groups that
make sense, such as a namespace for all monitoring applications and another for all security
applications.
It is clear from the above file that the service “silicon” is a reference to a namespace called
“chip”.
6. What is an Operator?
As an extension to K8, the operator provides the capability of managing applications and
their components using custom resources. Operators generally comply with all the
principles relating to Kubernetes, especially those relating to the control loops.
As compared to stateless applications, achieving desired status changes and upgrades are
handled the same way for every replica, managing Kubernetes applications is more
challenging. The stateful nature of stateful applications may require different handling for
upgrading each replica, as each replica might be in a different state. Therefore, managing
stateful applications often requires a human operator. This is supposed to be assisted by
Kubernetes Operator. Moreover, this will pave the way for a standard process to be
automated across several Kubernetes clusters.
8. What is GKE?
GKE is Google Kubernetes Engine that is used for managing and orchestrating systems for
Docker containers. With the help of Google Public Cloud, we can also orchestrate the
container cluster.
It specifies what to do with an incoming request to the Kubernetes cluster that isn't mapped
to any backend i.e what to do when no rules being defined for the incoming HTTP request
If the default backend service is not defined, it's recommended to define it so that users still
see some kind of message instead of an unclear error.
Kubernetes can be set up locally using the Minikube tool. It runs a single-node bunch in a
VM on the computer. Therefore, it offers the perfect way for users who have just ongoing
learning Kubernetes.
2. What is Kubernetes Load Balancing?
Load Balancing is one of the most common and standard ways of exposing the services.
There are two types of load balancing in K8s and they are:
Internal load balancer – This type of balancer automatically balances loads and allocates
the pods with the required incoming load.
External Load Balancer – This type of balancer directs the traffic from the external loads
to backend pods.
Explanation -
USER_PASSWORD environment variable will store the value from the password key in the
secret called "some-secret" In other words, you reference a value from a Kubernetes Secret.
4. Can you explain the differences between Docker Swarm and Kubernetes?
The installation procedure of the K8s is very complicated but if it is once installed then the
cluster is robust. On the other hand, the Docker swarm installation process is very simple
but the cluster is not at all robust.
Kubernetes can process the auto-scaling but the Docker swarm cannot process the auto-
scaling of the pods based on incoming load.
Kubernetes is a full-fledged Framework. Since it maintains the cluster states more
consistently so autoscaling is not as fast as Docker Swarm.
In K8’s scheduler is responsible to spawn pods into nodes. There are many factors that can
lead to unstartable POD. The most common one is running out of resources, use the
commands like kubectl describe <POD> -n <Namespace> to see the reason why POD is not
started. Also, keep an eye on kubectl to get events to see all events coming from the cluster.
nodeName: specify the name of a node in POD spec configuration, it will try to run the
POD on a specific node.
nodeSelector: Assign a specific label to the node which has special resources and use the
same label in POD spec so that POD will run only on that node.
nodeaffinities: required DuringSchedulingIgnoredDuringExecution,
preferredDuringSchedulingIgnoredDuringExecution are hard and soft requirements for
running the POD on specific nodes. This will be replacing nodeSelector in the future. It
depends on the node labels.
By default, POD should be able to reach the external network but vice-versa we need to
make some changes. Following options are available to connect with POD from the outer
world.
Nodeport (it will expose one port on each node to communicate with it)
Load balancers (L4 layer of TCP/IP protocol)
Ingress (L7 layer of TCP/IP Protocol)
Another method is to use Kube-proxy which can expose a service with only cluster IP on
the local system port.
8. How can we forward the port '8080 (container) -> 8080 (service) -> 8080
(ingress) -> 80 (browser)and how it can be done?
The ingress is exposing port 80 externally for the browser to access, and connecting to a
service that listens on 8080. The ingress will listen on port 80 by default. An "ingress
controller" is a pod that receives external traffic and handles the ingress and is configured
by an ingress resource For this you need to configure the ingress selector and if no 'ingress
controller selector' is mentioned then no ingress controller will manage the ingress.
host: abc.org
http:
paths:
backend:
serviceName: abc-service
servicePort: 8080
Then the service will look like
kind: Service
apiVersion: v1
metadata:
name: abc-service
spec:
ports:
protocol: TCP
port: 8080 # port to which the service listens to
targetPort: 8080