Share with friends

Hey there, Kubernetes newbie! Containers are pretty cool, right? And Kubernetes? That's the thing that keeps all those containers in order. This section will get you prepped to answer those basic Kubernetes interview questions with confidence. Pods, deployments, no sweat!

It contains commonly asked Kubernetes questions that can be asked in a freshers role for DevOps or Kubernetes Engineer or an intern.

More on the topic

Kubernetes Interview Questions - Beginner Level

Kubernetes Interview Questions - Medium Level Part 1

Kubernetes Interview Questions - Medium Level Part 2

Kubernetes Interview Questions - Advanced Level Part 1

Kubernetes Interview Questions - Advanced Level Part 2

Kubernetes Interview Questions - Advanced Level Part 3

Kubernetes Interview Questions - Advanced Level Part 4

Beginner Level Kubernetes Interview Questions and Answers

1. What is Kubernetes?

Answer: Kubernetes, an open-source container orchestration platform, streamlines the manual tasks associated with deploying, managing, and scaling containerized applications. It organizes containers within an application into logical units, simplifying management and discovery.

2. What is a Pod in Kubernetes?

Answer: A Pod is the smallest deployable unit in Kubernetes. It can contain one or more containers, along with shared storage/network resources and a specification for how to run the containers. All containers in a Pod share the same IP address and port space.

3. What is a Kubernetes Cluster?

Answer: A Kubernetes cluster is a set of nodes that run containerized applications. A cluster consists of at least one master node and multiple worker nodes. The master node manages the cluster, while the worker nodes run the applications.

4. What is a Node in Kubernetes?

Answer: In Kubernetes, a node is like a worker bee. It can be a virtual machine or a physical machine, depending on the cluster setup. Each node has everything it needs to run pods, and the master components keep an eye on them to make sure they're doing their job.

5. What is a Namespace in Kubernetes?

Answer: Imagine a big party where a bunch of people are hanging out. To keep things organized, the party planners create different areas for different groups of friends. These areas are like namespaces. They let each group have their own space to chill, chat, and dance without getting all mixed up with the other groups. That way, everyone can have a good time and not worry about tripping over each other's feet.

6. What is a ReplicaSet?

Answer: A ReplicaSet ensures that a specified number of pod replicas are running at any given time. If a pod crashes or is deleted, the ReplicaSet will create a new pod to replace it.

7. What is a Deployment in Kubernetes?

Answer: Deployments let you make changes to your applications in a controlled and declarative way. Just tell the Deployment controller what you want your application to look like, and it'll gradually make the necessary changes to match that desired state.

8. How do you create a Pod in Kubernetes?

Answer: You create a Pod by defining a Pod specification in a YAML file and applying it using the kubectl apply -f <file> command.

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx

9. What is a Service in Kubernetes?

Answer: A Service is an abstraction that defines a logical set of Pods and a policy by which to access them. Services enable network access to a set of Pods.

10. How do you scale a Deployment in Kubernetes?

Answer: You can scale a Deployment using the kubectl scale command followed by the deployment name and the desired number of replicas.

kubectl scale deployment <deployment-name> --replicas=<number>

11. What is kubectl?

Answer: kubectl is the command-line tool for interacting with the Kubernetes API server. It allows you to create, inspect, update, and delete Kubernetes resources.

12. What is a ConfigMap?

Answer: A ConfigMap is like a little box that holds key-value pairs of information that isn't top secret. Pods can use this information as environment variables, command-line arguments, or even as configuration files in a volume.

13. What is a Secret in Kubernetes?

Answer: A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Secrets can be used in Pods in a similar way as ConfigMaps but are intended for confidential data.

14. How do you update a Kubernetes Deployment?

Answer: You update a Deployment by modifying the Deployment's configuration file and applying the changes using the kubectl apply -f <file> command. Kubernetes will roll out the changes to the pods.

15. What is the kube-apiserver?

Answer: Within the Kubernetes control plane, the serves as a crucial component, acting as the primary interface for interacting with the Kubernetes API. Functioning as the front-end, it adeptly handles REST operations, facilitating seamless communication and data exchange.

16. What is the kube-scheduler?

Answer: The kube-scheduler is on the lookout for new Pods that don't have a home yet (no assigned node). When it spots one, it picks a node for the Pod to run on, making sure there are enough resources and that it fits in with any other rules.

17. What is the kube-controller-manager?

Answer: The kube-controller-manager runs controllers that regulate the state of the cluster. It includes the node controller, replication controller, endpoints controller, and others.

18. What is a PersistentVolume (PV) in Kubernetes?

Answer: A PersistentVolume (PV) is like a storage space in a cluster. It can be set up by an admin or created automatically using Storage Classes. Think of it as a resource in the cluster, just like a node where you can store stuff.

19. What is a PersistentVolumeClaim (PVC)?

Answer:Think of a PersistentVolumeClaim (PVC) as a storage request made by a user. It's like a Pod, except Pods use node resources, while PVCs use PV resources. When making a claim, you can specify the size and how you want to access the storage.

20. How do you expose a Deployment using a Service?

Answer: You expose a Deployment by creating a Service that targets the Deployment's pods. This can be done using kubectl expose deployment command or by defining a Service in a YAML file and applying it.

apiVersion: v1
kind: Service
metadata:
  name: example-service
spec:
  selector:
    app: example-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

21. What is a DaemonSet?

Answer: A DaemonSet is like a manager that makes sure every node in your cluster runs a copy of a Pod. When you add a new node to the cluster, the DaemonSet automatically creates a Pod on it. And when you remove a node from the cluster, the DaemonSet takes care of deleting the Pod on that node.

22. What is an Ingress in Kubernetes?

Answer: An Ingress, an API object in a cluster, handles external access to services, primarily HTTP. Through Ingress, you can achieve load balancing, SSL termination, and even name-based virtual hosting, offering a comprehensive solution for managing external access within a cluster environment.

23. How do you delete a Pod in Kubernetes?

Answer: You can delete a Pod using the kubectl delete pod <pod-name> command. This will remove the Pod from the cluster.

24. What is the difference between a StatefulSet and a Deployment?

Answer: A StatefulSet is used for stateful applications, where each pod has a unique identity and stable, persistent storage. A Deployment is used for stateless applications, where any pod can replace any other.

25. What are Labels and Selectors in Kubernetes?

Answer: Labels are key-value pairs attached to objects, such as pods, that can be used to organize and select subsets of objects. Selectors are used to filter and group objects based on their labels.

26. What is a Job in Kubernetes?

Answer: A Job is a way to create one or more Pods and make sure that a certain number of them finish successfully. Jobs are used for running batch processes or short-lived tasks.

27. What is the purpose of the kube-proxy?

Answer: kube-proxy maintains network rules on each node. These rules let network chats happen between the Pods and network sessions inside or outside of the cluster.

28. How do you view logs for a specific Pod?

Answer: You can view logs for a specific Pod using the kubectl logs <pod-name> command. For containers within a Pod, you can specify the container name with kubectl logs <pod-name> -c <container-name>.

29. What is kubectl describe used for?

Answer: kubectl describe shows detailed information about a specific Kubernetes resource, such as a Pod, Service, or Node. It provides information about the resource's status, events, and other details.

kubectl describe pod <pod-name>

30. How do you create a namespace in Kubernetes?

Answer: You can create a namespace by defining it in a YAML file and applying it using kubectl apply -f <file> or by using the kubectl create namespace <namespace-name> command.

apiVersion: v1
kind: Namespace
metadata:
  name: example-namespace

31. What is a ResourceQuota in Kubernetes?

Answer: A ResourceQuota is like a limit on how much of a resource you can use in a namespace. It ensures that the aggregate usage of resources like CPU, memory, and object counts within a namespace do not exceed specified hard limits.

32. How do you run a command in a running Pod?

Answer: You can run a command in a running Pod using the kubectl exec command.

kubectl exec -it <pod-name> -- <command>

33. What is the kubectl get command used for?

Answer: The kubectl get command is used to list resources of a specific type, such as Pods, Nodes, or Services.

kubectl get pods

34. How do you get detailed information about nodes in a cluster?

Answer: You can get detailed information about nodes using the kubectl describe nodes command.

35. What is an Init Container in Kubernetes?

Answer: Init Containers are like special containers that get the party started in a Pod before the main app containers show up. They're basically boxes that can hold tools or scripts that aren't already included in the app's image.

36. How do you check the status of a Pod?

Answer: You can check the status of a Pod using the kubectl get pod <pod-name> command or the kubectl describe pod <pod-name> command for more details.

37. What is the kubectl apply command used for?

Answer: The kubectl apply command is used to create or update resources defined in configuration files. It applies the changes specified in the YAML or JSON files to the cluster.

kubectl apply -f <file>

38. What are Taints and Tolerations in Kubernetes?

Answer: Taints are like security guards that keep Pods away from certain nodes. On the other hand, Tolerations are like VIP passes that let Pods hang out on nodes with taints. They work together to decide which Pods can crash at which nodes.

39. How do you label a Kubernetes resource?

Answer: You can label a resource using the kubectl label command.

kubectl label pod <pod-name> key=value

40. What is a Horizontal Pod Autoscaler (HPA)?

Answer: HPA automatically scales the number of pods in a Deployment, ReplicaSet, or StatefulSet based on observed CPU utilization or other custom metrics.

41. How do you delete a namespace in Kubernetes?

Answer: You can delete a namespace using the kubectl delete namespace <namespace-name> command. This will delete all the resources in the namespace.

42. What is the difference between kubectl create and kubectl apply?

Answer: kubectl create is used to create resources from a file or input. It fails if the resource already exists. kubectl apply is used to create or update resources, applying changes if the resource exists.

43. What is a Rollback in Kubernetes?

Answer: A rollback in Kubernetes refers to reverting a Deployment to a previous version. This can be done using the kubectl rollout undo command.

44. How do you check the version of Kubernetes running in your cluster?

Answer: You can check the Kubernetes version using the kubectl version command.

45. What is a kubelet?

Answer: On every node within the cluster, the kubelet serves as an agent. It works by interacting with the container runtime to make sure that containers are operational within a Pod.

46. What is the role of the etcd database in Kubernetes?

Answer: etcd is a distributed key-value store that Kubernetes uses to store all cluster data, including configuration and state information.

47. What is a LimitRange in Kubernetes?

Answer: A LimitRange sets resource usage constraints per Pod or Container in a namespace. It ensures that all Containers and Pods consume resources within defined limits.

48. How do you use a ConfigMap in a Pod?

Answer: You can use a ConfigMap in a Pod by mounting it as a volume or using it as environment variables.

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    env:
    - name: EXAMPLE_ENV
      valueFrom:
        configMapKeyRef:
          name: example-configmap
          key: example-key

49. How do you set resource requests and limits for a container?

Answer: You set resource requests and limits in the Pod specification.

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

50. What is a StorageClass in Kubernetes?

Answer: A StorageClass provides a way to describe the "classes" of storage available in a cluster. It defines the provisioner, parameters, and reclaimPolicy for the dynamically created PersistentVolumes.

51. What is the purpose of the kubectl config command?

Answer: The kubectl config command is used to configure access to clusters. It manages the kubeconfig file, which contains information about clusters, users, contexts, and namespaces.

52. How do you list all Pods in all namespaces?

Answer: You can list all Pods in all namespaces using the kubectl get pods --all-namespaces command.

53. What is the kubectl port-forward command used for?

Answer: The kubectl port-forward command is used to forward one or more local ports to a Pod. This allows you to access the Pod's applications directly from your local machine.

kubectl port-forward <pod-name> <local-port>:<pod-port>

54. What is the purpose of a ServiceAccount in Kubernetes?

Answer: A ServiceAccount gives a name to the things that happen in a Pod. Pods use ServiceAccounts to authenticate with the Kubernetes API.

55. How do you specify environment variables for a container in Kubernetes?

Answer: Environment variables are specified in the Pod specification.

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    env:
    - name: EXAMPLE_ENV
      value: example-value

56. What is the kubectl get events command used for?

Answer: The kubectl get events command is used to list the events in the cluster. Events provide a timeline of changes in the cluster, such as pod creation, deletion, and errors.

57. What are Network Policies in Kubernetes?

Answer: Network Policies are used to control the communication between Pods and network endpoints. They define how Pods are allowed to communicate with each other and other network entities.

58. What is the kubectl rollout command used for?

Answer: The kubectl rollout command is used to manage the rollout of a resource. It allows you to check the status of a rollout, pause or resume a rollout, and undo a rollout.

59. What is a ResourceQuota used for in Kubernetes?

Answer: A ResourceQuota is used to set constraints on the total amount of resources that can be consumed within a namespace. It helps ensure that no single namespace can monopolize cluster resources.

60. How do you restart a Pod in Kubernetes?

Answer: Pods cannot be restarted directly. However, you can delete the Pod, and the controller (e.g., Deployment) will create a new one. You can use the kubectl delete pod <pod-name> command.

61. What is the purpose of the kubectl top command?

Answer: The kubectl top command is used to show resource usage, such as CPU and memory, for nodes or pods.

62. How do you create a ConfigMap from a file?

Answer: You can create a ConfigMap from a file using the kubectl create configmap command.

kubectl create configmap <configmap-name> --from-file=<file-path>

63. What is the purpose of the kubectl cluster-info command?

Answer: The kubectl cluster-info command displays information about the Kubernetes cluster, such as the master and service endpoints.

64. How do you create a secret from a file?

Answer: You can create a secret from a file using the kubectl create secret command.

kubectl create secret generic <secret-name> --from-file=<file-path>

65. What is a Service's type in Kubernetes, and what types are available?

Answer: The Service's type determines how the Service is exposed. Available types are ClusterIP (default), NodePort, LoadBalancer, and ExternalName.

66. How do you get the IP address of a Pod?

Answer: You can get the IP address of a Pod using the kubectl get pod <pod-name> -o wide command.

67. What is a Kubernetes Manifest?

Answer: A Kubernetes Manifest is a YAML or JSON configuration file that describes the desired state of a Kubernetes object, such as a Pod, Deployment, or Service.

68. What is a Liveness Probe in Kubernetes?

Answer: A Liveness Probe is a mechanism used by Kubernetes to check if a container is still running. If the liveness probe fails, the container will be restarted.

69. What is a Readiness Probe in Kubernetes?

Answer: A Readiness Probe is used to determine if a container is ready to start accepting traffic. If the readiness probe fails, the Pod will be removed from the Service endpoints until it passes.

70. How do you define a Liveness Probe in a Pod specification?

Answer: You define a Liveness Probe in the Pod specification using the livenessProbe field.

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 3
      periodSeconds: 3

71. How do you define a Readiness Probe in a Pod specification?

Answer: You define a Readiness Probe in the Pod specification using the readinessProbe field.

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    readinessProbe:
      httpGet:
        path: /ready
        port: 8080
      initialDelaySeconds: 3
      periodSeconds: 3

72. What is the purpose of a headless Service in Kubernetes?

Answer: A headless Service does not have a ClusterIP. It is used to facilitate direct communication between clients and pods without load balancing. This is useful for StatefulSets and applications that require direct pod access.

73. How do you create a headless Service in Kubernetes?

Answer: You create a headless Service by setting the clusterIP field to None.

apiVersion: v1
kind: Service
metadata:
  name: headless-service
spec:
  clusterIP: None
  selector:
    app: example-app
  ports:
  - port: 80
    targetPort: 8080

74. What is a Sidecar Container in Kubernetes?

Answer: A Sidecar Container is a container that runs alongside the main application container in the same Pod. It can enhance or extend the functionality of the main container, such as logging or monitoring.

75. What is the difference between a ConfigMap and a Secret?

Answer: Both ConfigMap and Secret store configuration data, but Secrets are intended for sensitive information and are stored in base64 encoded format. ConfigMaps are used for non-confidential data.

76. What is a PodDisruptionBudget (PDB)?

Answer: A PodDisruptionBudget (PDB) specifies the minimum number or percentage of Pods that must remain available during voluntary disruptions, such as maintenance.

77. How do you create a PodDisruptionBudget in Kubernetes?

Answer: You create a PodDisruptionBudget by defining it in a YAML file and applying it.

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: example-pdb
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: example-app

78. What is a Rolling Update in Kubernetes?

Answer: A Rolling Update gradually replaces old Pods with new ones. It ensures zero downtime by incrementally updating Pods and verifying their readiness before proceeding to the next.

79. What is a Canary Deployment?

Answer: A Canary Deployment is a strategy where a new version of an application is released to a small subset of users before rolling it out to the entire infrastructure. This helps in testing the new version with minimal risk.

80. What is a Blue-Green Deployment?

Answer: A Blue-Green Deployment is a strategy where two environments (blue and green) are maintained. One environment is live (blue), and the other is staged for the new release (green). After the new version is verified, traffic is switched from blue to green.

81. What is the kubectl run command used for?

Answer: The kubectl run command is used to create a single Pod or deployment running a specified container image.

kubectl run nginx --image=nginx

82. How do you update the image of a running Deployment?

Answer: You update the image of a running Deployment using the kubectl set image command.

kubectl set image deployment/example-deployment example-container=nginx:latest

83. What is the kubectl cp command used for?

Answer: The kubectl cp command is used to copy files and directories to and from containers.

kubectl cp <local-file> <pod-name>:<container-path>

84. What is the purpose of a ServiceAccount in Kubernetes?

Answer: A ServiceAccount provides an identity for processes running in a Pod, allowing Pods to authenticate with the Kubernetes API and access resources.

85. How do you create a ServiceAccount in Kubernetes?

Answer: You create a ServiceAccount by defining it in a YAML file and applying it.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: example-serviceaccount

86. What is the kubeadm tool used for?

Answer: kubeadm is a tool used to bootstrap a Kubernetes cluster. It simplifies the process of setting up a new Kubernetes cluster.

87. What is the purpose of kubectl taint?

Answer: The kubectl taint command is used to add a taint to a node. Taints are used to prevent Pods from being scheduled on certain nodes unless they tolerate the taint.

88. How do you drain a node in Kubernetes?

Answer: You can drain a node using the kubectl drain command. This will evict all Pods from the node and mark it as unschedulable.

kubectl drain <node-name> --ignore-daemonsets

89. What is a Custom Resource Definition (CRD) in Kubernetes?

Answer: A Custom Resource Definition (CRD) is a way to define custom resources in Kubernetes. It allows you to extend the Kubernetes API with your own resource types.

90. How do you create a Custom Resource Definition (CRD)?

Answer: You create a CRD by defining it in a YAML file and applying it.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: examples.example.com
spec:
  group: example.com
  versions:
  - name: v1
    served: true
    storage: true
  scope: Namespaced
  names:
    plural: examples
    singular: example
    kind: Example

91. What is the kubectl explain command used for?

Answer: The kubectl explain command is used to display the documentation of resources. It provides a detailed explanation of the fields of a resource.

kubectl explain pod

92. What is the difference between kubectl delete and kubectl delete --cascade?

Answer: kubectl delete removes the specified resource, while kubectl delete --cascade also deletes all dependent resources, such as Pods managed by a Deployment.

93. What is the purpose of a LimitRange in Kubernetes?

Answer: A LimitRange sets constraints on the resource usage per Pod or Container within a namespace, ensuring that resources are consumed within defined limits.

94. How do you set resource requests and limits for a Pod?

Answer: You set resource requests and limits in the Pod specification.

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

95. What is the purpose of kubectl cordon?

Answer: The kubectl cordon command marks a node as unschedulable, preventing new Pods from being scheduled on that node.

kubectl cordon <node-name>

96. What is the kubectl edit command used for?

Answer: The kubectl edit command is used to edit a resource's configuration directly from the command line. It opens the resource in your default editor.

kubectl edit pod <pod-name>

97. What is the purpose of a NodePort Service?

Answer: A NodePort Service exposes a Service on a static port on each node's IP address, allowing external traffic to access the Service.

apiVersion: v1
kind: Service
metadata:
  name: example-service
spec:
  type: NodePort
  selector:
    app: example-app
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30036

98. What is the kubectl config set-context command used for?

Answer: The kubectl config set-context command is used to configure contexts in the kubeconfig file, specifying parameters like the cluster, user, and namespace to be used by default.

kubectl config set-context my-context --cluster=my-cluster --user=my-user --namespace=my-namespace

99. How do you scale a Deployment in Kubernetes?

Answer: You can scale a Deployment using the kubectl scale command.

kubectl scale deployment <deployment-name> --replicas=<number-of-replicas>

100. What is the purpose of kubectl logs?

Answer: The kubectl logs command is used to retrieve the logs of a container in a Pod. This is useful for debugging and monitoring.

kubectl logs <pod-name>

Awesome work, you just conquered the Kubernetes basics! These building blocks will set you on the path to becoming a container orchestration wizard. Remember, practice is key. Play around, explore, and keep learning - there's a whole Kubernetes world out there waiting for you!

Next Steps

Kubernetes Interview Questions - Beginner Level

Kubernetes Interview Questions - Medium Level Part 1

Kubernetes Interview Questions - Medium Level Part 2

Kubernetes Interview Questions - Advanced Level Part 1

Kubernetes Interview Questions - Advanced Level Part 2

Kubernetes Interview Questions - Advanced Level Part 3

Kubernetes Interview Questions - Advanced Level Part 4

Share with friends

Priyansh Khodiyar's profile

Written by Priyansh Khodiyar

Priyansh is the founder of UnYAML and a software engineer with a passion for writing. He has good experience with writing and working around DevOps tools and technologies, APMs, Kubernetes APIs, etc and loves to share his knowledge with others.

Life is better with cookies 🍪

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt out if you wish. Cookie Policy