Kubernetes Interview Questions and Answers
Question - 101 : - Define Kube-api server?
Answer - 101 : -
The Kube-API is the frontend of the master node that exposes all the components in the API server. It provides communication between the Kubernetes nodes and the master components.
Question - 102 : - What are the advantages of Kubernetes?
Answer - 102 : -
The advantages of the Kubernetes are as follows:
- Kubernetes is open-source and free
- It is highly scalable and runs in any operating system
- It provides more concept and is more powerful than Docker swarm
- It provides scheduler, auto-scaling, rolling upgrades, and health checks
- It has a flat network space and customized functionalities
- It is easy to make effective CI/CD pipelines
- It can improve productivity
Question - 103 : - How do we control the resource usage of POD?
Answer - 103 : -
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"
Question - 104 : - What are the various K8's services running on nodes and describe the role of each service?
Answer - 104 : -
Mainly K8 cluster consists of two types of nodes, executor and master.
Executor node: (This runs on master node)
- 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:
- Kube-apiserver: Master API service which acts as an entry point to K8 cluster.
- Kube-scheduler: Schedule PODs according to available resources on executor nodes.
- Kube-controller-manager: is a control loop that watches the shared state of the cluster through the apiserver and makes changes attempting to move the current state towards the desired stable state
Question - 105 : - What is PDB (Pod Disruption Budget)?
Answer - 105 : -
A Kubernetes administrator can create a deployment of a kind: PodDisruptionBudget for high availability of the application, it makes sure that the minimum number is running pods are respected as mentioned by the attribute minAvailable spec file. This is useful while performing a drain where the drain will halt until the PDB is respected to ensure the High Availability(HA) of the application. The following spec file also shows minAvailable as 2 which implies the minimum number of an available pod (even after the election).
Example: YAML Config using minAvailable =>
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: zk-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: zookeeper
Question - 106 : - What is the difference between Docker Swarm and Kubernetes?
Answer - 106 : -
Below are the main difference between Kubernetes and Docker:
- 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.
Question - 107 : - How to run a POD on a particular node?
Answer - 107 : -
Various methods are available to achieve it.
- 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.
Question - 108 : - What are the different ways to provide external network connectivity to K8?
Answer - 108 : -
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.
$ kubectl proxy --port=8080 $ http://localhost:8080/api/v1/proxy/namespaces//services/:/