main_bg

Kubernetes Interview Questions

Dive into the world of container orchestration with 'Kubernetes Interview Questions.' This blog serves as your comprehensive guide for acing Kubernetes-related interviews, offering a diverse array of questions and detailed answers. Whether you're a DevOps engineer, a system administrator, or a Kubernetes enthusiast, our resource covers Kubernetes fundamentals, containerization, scaling, and best practices. Prepare with confidence and explore the transformative potential of Kubernetes in managing and deploying containerized applications.

1. What is Kubernetes?

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications.

2. Explain the key components of Kubernetes architecture.

The key components include the Master Node (API server, Controller manager, Scheduler), Worker Nodes (Kubelet, Kube Proxy), and etcd (a distributed key-value store).

3. 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:

  • kubectl get nodes: to list all the nodes
  • kubectl drain <node name>: drain a particular node

4. How do we control the resource usage of POD?

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: v1kind: Podmetadata: name: demospec: containers: - name: example1 image:example/example1 resources:   requests:     memory: "_Mi"     cpu: "_m"   limits:     memory: "_Mi"     cpu: "_m"

5. What are the various K8's services running on nodes and describe the role of each service?

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

6. What is PDB (Pod Disruption Budget)?

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/v1beta1kind: PodDisruptionBudgetmetadata: name: zk-pdbspec: minAvailable: 2 selector:   matchLabels:     app: zookeeper

7. What’s the init container and when it can be used?

 init containers will set a stage for you before running the actual POD.

Wait for some time before starting the app Container with a command like sleep 60.

Clone a git repository into a volume.

8. 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.

  • RBAC (Role-based access control) to narrow down the permissions.
  • Use namespaces to establish security boundaries.
  • Set the admission control policies to avoid running the privileged containers.
  • Turn on audit logging.

9. How to monitor the Kubernetes cluster?

Prometheus is used for Kubernetes monitoring. The Prometheus ecosystem consists of multiple components.

  • Mainly Prometheus server which scrapes and stores time-series data.
  • Client libraries for instrumenting application code.
  • Push gateway for supporting short-lived jobs.
  • Special-purpose exporters for services like StatsD, HAProxy, Graphite, etc.
  • An alert manager to handle alerts on various support tools.

10. How to get the central logs from POD?

This architecture depends upon the application and many other factors. Following are the common logging patterns

  • Node level logging agent.
  • Streaming sidecar container.
  • Sidecar container with the logging agent.
  • Export logs directly from the application.

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.

The same can be achieved using EFK stack and fluentd-bit.

11. How to turn the service defined below in the spec into an external one?

spec:  selector:    app: some-app  ports:    - protocol: UDP      port: 8080      targetPort: 8080

Explanation - 

Adding type: LoadBalancer and nodePort as follows:

spec: selector:   app: some-app type: LoadBalancer ports:   - protocol: UDP     port: 8080     targetPort: 8080     nodePort: 32412

12. How should TLS be configured with Ingress?

Add tls and secretName entries.

spec: tls: - hosts:   - some_app.com   secretName: someapp-secret-tls

13. 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. 

Additionally, namespaces can be used for managing Blue/Green environments, in which each namespace contains its own version of an app as well as sharing resources with other namespaces (such as logging or monitoring). It is also possible to have one cluster with multiple teams using namespaces. The use of the same cluster by multiple teams may lead to conflict.  Suppose they end up creating an app that has the same name, this means that one team will override the app created by the other team as Kubernetes prohibits two apps with the same name (within the same namespace).

14. What service and namespace are referred to in the following file?

apiVersion: v1kind: ConfigMapmetadata:  name: some-configmapdata:  some_url: silicon.chip

It is clear from the above file that the service “silicon” is a reference to a namespace called “chip”.

15. 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.

16. What is the purpose of operators?

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.

17. 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.

18. What is Ingress Default Backend?

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.

19. How to run Kubernetes locally?

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.

20. 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.

21. What the following in the Deployment configuration file mean?

spec:  containers:    - name: USER_PASSWORD      valueFrom:        secretKeyRef:          name: some-secret          key: password

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.

22. Can you explain the differences between Docker Swarm and Kubernetes?

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.

23. How to troubleshoot if the POD is not getting scheduled?

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.

24. How to run a POD on a particular node?

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.

25. Code Snippet: Kubernetes Deployment YAML

            
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example-container
        image: nginx:latest
            
        

26. Online Resources:

Published On: 2024-01-17