Kubernetes Interview Questions
Kubernetes Interview Questions
Q2: I have thousands of pods and lots of applications running on the pods
which deployment strategy you will follow rolling or re-create? and why?
1. Rolling Updates:
A rolling update strategy gradually replaces instances of the old application
with instances of the new version. This means that your application remains
available throughout the update process, as the new pods are slowly
introduced and the old ones are terminated.
2. Re-create Strategy:
In the re-create strategy, all existing pods with the old version of the
application are terminated before the new version is deployed. This means
there will be a brief downtime during the update process.
Labels: Labels are key-value pairs that you can attach to Kubernetes
objects, such as pods, nodes, services, and more. They are used to mark
resources with metadata that provides additional information about the
resource.
Selectors: Selectors are used to efficiently and flexibly identify a group of
resources based on their labels. Selectors allow you to filter and target
specific resources that match certain criteria.
1. Cluster IP service:
The ClusterIP is the default Kubernetes service that provides service inside a
cluster (with no external access) that other apps inside your cluster can
access.
The NodePort service is the most fundamental way to get external traffic
directly to your service. It opens a specific port on all Nodes and forwards any
traffic sent to this port to the service.
The Minikube makes it easy for the local running of Kubernetes. Within a
virtual machine, the Minikube runs a single-node Kubernetes cluster.
The process of load balancing will let us expose services. There are two
types of load balancing when it comes to Kubernetes:
Internal load balancing: This is used for balancing the loads automatically
and allocating the pods with the required configuration.
External load balancing: This directs the traffic from the external loads to
the backend pods.
1. Liveness Probe
Suppose that a Pod is running our application inside a container, but due to
some reason let’s say memory leak, CPU usage, application deadlock, etc
the application is not responding to our requests, and is stuck in an error
state.
The liveness probe checks the container's health as we tell it to, and if for
some reason the liveness probe fails, it restarts the container. We can define
liveness probe in 3 ways
2. Readiness Probe
In some cases, we would like our application to be alive, but not serve traffic
unless some conditions are met e.g, populating a dataset, waiting for some
other service to be alive, etc.
In such cases, we use a readiness probe. If the condition inside the readiness
probe passes, only then our application can serve traffic.
1. Deployment:
Deployments are best suited for stateless applications, where each instance
of the application is identical and can be easily replaced without concerns
about its identity or data.
When a pod that is managed by k8s gets deleted the new pod will come up
with the new ID
Deployment provides rolling updates & roll back feature and pods can easily
be rolled out
2. Satetfulsets:
StatefulSets are designed for managing stateful applications, where each pod
instance has a unique identity and possibly persistent data.
When a pod that is managed by k8s gets deleted the new pod will come up
with the same ID
StatefulSets are more complex to update compared to Deployments, as you
have to consider data migration, ordering, and potential disruption.
Path and Host-Based Routing: You can configure the Ingress Controller to
route traffic to different Services based on the URL path or the host header of
the incoming request.
Load Balancing: The Ingress Controller can distribute incoming traffic across
multiple instances of a Service, helping to ensure high availability and
efficient resource utilization.
Q20: Can 2 pods on the same node communicate with each other?
If two pods are scheduled on the same node, Pods use virtual bridges to
communicate with each other.
Q21: How to check the deprecated API version in K8s while upgrading the
cluster?
You can use kubectl commands to list the deprecated API versions in your
cluster
kubectl api-versions | grep -i deprecated
From the K8s docs also you can check
Starting from Kubernetes 1.19, you might receive deprecation warnings when
using deprecated APIs.
A NodePort service exposes a specific port on all the nodes in the cluster.
It doesn't provide automatic load balancing across nodes.
Typically used for small-scale clusters or testing purposes.
A LoadBalancer service is designed for production environments and
provides built-in load balancing.
It requests a cloud provider to allocate an external load balancer, distributing
traffic across multiple nodes.
External clients can access the service using the IP address of the load
balancer.
The load balancer distributes traffic to the nodes where the service is running.
Q23: What is the pod disruption budget?
If you have a deployment with a replica count of 5 pods and you set a Pod
Disruption Budget of 2, it means that during maintenance or other disruptions,
only a maximum of 2 pods can be simultaneously unavailable. This
guarantees that the application remains available and responsive to user
requests to the extent specified by the budget.
Kubernetes network policies are rules that control the flow of network traffic
between pods and services within a Kubernetes cluster.
No, if the scheduler in a Kubernetes cluster is down, new pods will not be
scheduled automatically.
However, if pods were already scheduled and running before the scheduler
went down, they will continue to run as long as the underlying nodes are
operational and healthy.
In Kubernetes, each pod runs in its own IP address, and namespaces provide
a way to isolate resources within a cluster. By default, pods within a
namespace share the same IP address range as the cluster.
If you want to allocate different IP address ranges to different namespaces,
you can achieve this through the use of a Container Network Interface (CNI)
plugin that supports IP allocation customization.
Calico is the most common CNI plugin used for that
We can install the calico and create the IP pool resource using that and
specify the IP address range in that and using the namespaceselector we can
attach that pool to the namespace.
Q36: Can you explain the concept of self-healing in Kubernetes and give
examples of how it works?
When databases scale, they add Slave Pods to only read data. This is
because if two Pods write on the same data, it will create data inconsistency.
Hence, one Pod is always the master node and the other slaves. The slave
Pods get replicated data of the master Pod and are called Read Replicas.
Q41: Let’s say my pod has 3 containers and I want to check the logs of all
the containers how can I do that?
Q42: How to restrict the access of pods from various IPs in the K8s
cluster?*
The Cluster Autoscaler is responsible for adjusting the size of the worker
node Auto Scaling Group (ASG) in your EKS cluster based on the pending
pods in the cluster. When there are more pending pods than available
resources in the cluster, it scales up the number of worker nodes in the ASG,
and when there are idle nodes, it scales them down to save costs.
Q44: From where KubeAPI server get all the info about pods?
The primary source of truth for all Kubernetes cluster data, including pod
information, is the etcd datastore. Etcd is a distributed key-value store that
stores the configuration data of the entire cluster. When a user or a controller
creates, updates, or deletes a pod, the relevant information is persisted in
etcd.
The kubelet is an agent that runs on each node in the Kubernetes cluster and
is responsible for managing containers and pods on that node. Kubelet
communicates with the kube-apiserver to report the status of pods on its
node and to perform actions on pods as instructed by the API server. Kubelet
regularly polls the kube-apiserver for updates and syncs the state of pods on
its node with the desired state defined in the Kubernetes API.
Using nodeSelector, nodeAffinity, Taints, and Tolerations, you can restrict the
daemonset to run on specific nodes.
Q47: What will happen in thebackground when you type kubectl get pods?
Q49: How to check deprecated API version in k8s while upgrading cluster?
You can use kubectl commands to list the deprecated API versions in your
cluster
kubectl api-versions | grep -i deprecated
From the k8s docs
Starting from Kubernetes 1.19, you might receive deprecation warnings when
using deprecated APIs.
They are the same but differ only in using selectors to reproduce pods.The
replication controller allows us to create multiple pods easily, but if a pod
crashes, it ensures it is replaced with a new pod. It can scale the number of
pods and update or delete multiple pods with a single command.
The replica set is the same as the replication controller except that they have
more options for the selectors. They use set-based selectors to manage the
pods. Here the rolling-update command won’t work.
Q54: K8s deployment best practices - how our application is more reliable,
high available, and disaster recovery