Introduction
Kubernetes is a distributed open-source platform that allows us to schedule and execute application containers across clusters. There are two sorts of resources in a Kubernetes cluster:
The Master => Coordinates all cluster actions, such as scheduling applications, preserving their state, scaling applications, and deploying new updates.
Nodes => In a Kubernetes cluster, a node is an instance of an OS that operates as a worker computer.
![Kubernetes Interview Questions](https://files.codingninjas.in/article_images/custom-upload-1688139528-092d535d.webp)
A node will also contain two components
- Agent for controlling and interacting with the master Kubelet
- Tools for running container operations (Docker/containers)
![Kubernetes Cluster](https://files.codingninjas.in/article_images/30-kubernetes-interview-questions-for-advanced-part-3-0-1652103775.webp)
It is built from the bottom to be a loosely connected set of containers for delivering, managing, and scaling applications. Converges the current and intended state of the system to serve as an engine for resolving state (self-healing). The shared pool of resources (hardware) is hidden from the nodes' underlying hardware to facilitate deployment.
Kubernetes bundles one or more containers into a higher-level structure called a pod, the smallest unit of items that may be deployed on the platform. The container is one level above Pod.
A Pod is always running on a Node, but they share a few resources, such as Shared Volumes, Cluster Unique IP, and information about running each container. The pod's containers will all run on the same node.
The control plane, which is at the heart of Kubernetes, is an API server that allows you to query and alter the state of an object.
![POD](https://files.codingninjas.in/article_images/30-kubernetes-interview-questions-for-advanced-part-3-1-1652103775.webp)
Basic Kubernetes Interview Questions
1. What is Kubernetes?
![Kubernetes\](https://files.codingninjas.in/article_images/custom-upload-1725263832-04f8b5ea.webp)
Ans: This is one of the most fundamental Kubernetes interview questions, but it's also crucial! Kubernetes is an open-source container orchestration tool or system that automates processes, including containerized application administration, monitoring, scaling, and deployment. It is used to manage many containers (since it can handle the grouping of containers), allowing for the discovery and management of logical units.
2. How many containers in a pod communicate with each other?
Ans: Containers in a pod share networking resources and can communicate with one another through localhost. For example, if a pod has two containers, one running MySQL on port 3306 and the other running PHP on port 80, the PHP container might contact the MySQL container through localhost:3306.
3. When it comes to software and DevOps, what is orchestration?
Ans: Orchestration integrates numerous services to promptly automate procedures or synchronize data. You need to operate an application with six or seven microservices. If you put them in different containers, communication will become difficult. In this case, orchestration would be useful since it would allow all services in various containers to work together to achieve a single objective.
4. What is the difference between Job and POD?
Ans: A Pod guarantees that a container is continually functioning, but the Job ensures that the pods do their tasks. The Job entails doing a certain activity.
Example:
kubectl run mypod1 --image=nginx --restart=Never
kubectl run mypod2 --image=nginx --restart=onFailure
○ → kubectl get pods
NAME READY STATUS RESTARTS AGE
mypod1 1/1 Running 0 59s
○ → kubectl get job
NAME DESIRED SUCCESSFUL AGE
mypod1 1 0 19s
5. Explain some of the pod's usage patterns?
Ans: There are two major methods to use pods:
- A pod runs a single container: A single container per pod is the simplest and most frequent Pod design, with each container representing a full application. A Pod may be thought of as a wrapper in this scenario.
- Pods that operate several containers must communicate with one another: Multiple-container pods are typically used to run co-located, co-managed projects requiring resource sharing. One container serving files from a shared drive, while another container refreshes or updates those files, might create a single coherent service unit. The Pod binds these containers and storage resources into a single, controllable entity.
Each Pod is designed to execute a single application instance. If you wish to run many application instances, create one Pod for each instance. Replication is the term for this process. A controller, such as a Deployment, creates and manages replicated Pods as a group.
6. Explain components in the architecture of Kubernetes?
Ans: Different components are:
![architecture of Kubernetes](https://files.codingninjas.in/article_images/30-kubernetes-interview-questions-for-advanced-part-3-3-1652103776.webp)
- Master Node: The master node is the first and most important component in the Kubernetes cluster, and it is responsible for cluster administration. It serves as the starting point for all administrative tasks. The cluster may include more than one master node to ensure fault tolerance.
- API Server: The API server is the entry point for any REST commands used to operate the cluster.
- Scheduler: The slave node's tasks are scheduled by the scheduler. It keeps track of how much each slave node uses its resources. It is in charge of allocating workload.
- ETCD: Wright values, etcd components, and store configuration info. To accept orders and function, it connects with the most component. It also takes care of network rules and port forwarding.
- Worker/slave nodes: Worker/slave nodes are another important component that provides all the services needed to handle container networking, connect with the master node, and assign resources to scheduled containers.
- Kubelet: It obtains a Pod's configuration from the API server and verifies that the containers mentioned are up and running.
- Docker Container: Each worker node has a Docker container that executes the defined pods.
- Pods: A pod is a collection of one or more containers that execute logically on the same node.
7. How do you tie service to a pod or a set of pods?
Ans: By labeling pods and including a selection in the service that functions as a glue to keep the service attached to the pods.
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
8. What are the various services available in Kubernetes?
Ans: Some of the services accessible in Kubernetes are:
1) Cluster IP service
2) Load Balancer service
3) Node Port service, and
4) External Name Creation service
9. What are namespaces, exactly? What's wrong with utilizing a single default namespace?
Ans: Namespaces allow you to divide your cluster into virtual clusters where you may organize your applications logically and independently from the rest of the cluster (for example, create an app with the same name in two different namespaces).
- Using the default namespace alone makes it difficult to keep track of all the apps you administer in your cluster over time. Namespaces make it easy to divide apps into logical groupings, such as a namespace for all monitoring programs and another for all security applications, and so on.
- Namespaces are especially helpful for managing Blue/Green environments, as each namespace may include many versions of an app and share resources with other namespaces (namespaces like logging, monitoring, etc.).
- One cluster, numerous teams, is another use case for namespaces. When numerous teams share the same cluster, they may step on each other's toes. If they end up establishing an app with the same name, it signifies one of the teams has taken over the other's app since Kubernetes can't have two applications with the same name (in the same namespace).
10. If we have Pod with two containers, can I ping each other?
Ans: Containers in the same pod seem to be on the same computer. You may ping them directly using localhost: port. Each container in a pod has the same IP address. Inside a pod, you may ping localhost. Two containers in the same pod have the same IP address and network namespace, and they are both localhost. This is how discovery works: Component A's pods -> Component B's Service -> Component B's pods and Services have domain names servicename.namespace.svc.cluster.local, and the DNS search path of pods includes such stuff by default, so a pod in namespace Foo may connect to 'bar' to locate a Service bar in the same namespace Foo.
11. What is a Node in Kubernetes?
Ans: A Node is a physical or virtual machine in the Kubernetes cluster that runs Pods. Each Node is managed by the Kubernetes control plane and contains the necessary services to run the Pods, such as kubelet and a container runtime.
12. What is a Persistent Volume in Kubernetes?
Ans: A Persistent Volume (PV) in Kubernetes is a piece of storage in the cluster that has been provisioned by an administrator or dynamically through storage classes. It is used to store data that needs to persist beyond the lifecycle of individual Pods.
13. How does Kubernetes perform scaling?
Ans: Kubernetes performs scaling through Deployments by adjusting the number of replicas of a Pod. You can scale up or down manually or use the Horizontal Pod Autoscaler to automatically adjust the number of Pods based on CPU utilization or other metrics.
14. What is a Deployment in Kubernetes?
Ans: A Deployment in Kubernetes is a higher-level abstraction that manages the creation and scaling of Pods. It allows you to define the desired state for your application and ensures that the correct number of replicas are running at all times.
15. What is a ReplicaSet in Kubernetes?
Ans: A ReplicaSet is a Kubernetes resource that ensures a specified number of Pod replicas are running at any given time. It is used to maintain high availability by automatically replacing any Pods that fail or are deleted.