25 Kubernetes questions that will help you get certified and become more efficient with K8s

Mastering Kubernetes can be a complex task, but certain tips and tricks can expedite your journey, instilling you with confidence when it comes to maintaining Kubernetes clusters. This curated set of questions is designed to elevate your skills to the next level. If you're aiming for certification, going through this list is a must.

QUESTION 1:

How do you convert a Kubernetes pod to a deployment?

Experience Level: Senior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Export the pod to a yaml definition using the following command:

kubectl get pod yourpod -o yaml > pod.yaml

Create a new deployment definition using the following command:

kubectl create deployment deploymentname --image=imagename --dry-run=client -o yaml > deployment.yaml

Display the pod yaml:

cat pod.yaml

Copy the spec part

Edit the deployment file:

nano deployment.yaml

Paste the pod .spec block to deployment template .spec, correct indentation, save the file.

Create the deployment using the file:

kubectl apply -f deployment.yaml
QUESTION 2:

How do you create a service svc1 from a Kubernetes pod pod1? The service should use a tcp port redirection of 8080:80.

Experience Level: Senior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl expose pod pod1 --name=svc1 --port=8080 --target-port=80
QUESTION 3:

How do you create a temporary pod and verify a http connectivity to a service svc1 that exposed a port 80?

Experience Level: Senior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl run tmp --image=busybox --rm -i -- /bin/sh -c "wget -m 5 svc1:80"

The -m 5 parameter defines maximum time allowed for the transfer. It is used as a 5 second timeout. If the response is not transferred by that time, wget stops.

QUESTION 4:

What are the three kinds of object management supported in Kubernetes?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

  • Imperative commands
  • Imperative object configuration
  • Declarative object configuration

Very often you generate a manifest using an imperative command together with --dry-run=client parameter and then further tweak it using an editor. Once finished, you apply the changes.

Example:

Run the following to generate a pod manifest.

kubectl run mypod --image=nginx --dry-run=client -o yaml > file.yaml

Run the following to open the pod manifest in an editor:

nano file.yaml

Apply the changes by running the following command:

kubectl apply -f file.yaml

The above technique will also allow you to get back to the manifest if needed. You can always delete the resoruce (pod), modify the manifest and recreate it again using the modified version.

QUESTION 5:

How can you display a list of Kubernetes pods that will automatically rerender when a pod status changes?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl get pod --watch
QUESTION 6:

How do you list Kubernetes service accounts?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run one of the following commands (they are all the same):

kubectl get sa
kubectl get serviceaccount
kubectl get serviceaccounts
QUESTION 7:

What command can you use to get the address of the Kubernetes control plane and cluster services?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl cluster-info
QUESTION 8:

How can you speed up your work flow when using kubectl?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Configure alias, so that you don't need to type kubectl.

Run the following command:

alias k=kubectl

Then you can type kubectl commands like this:

k get pod
QUESTION 9:

How can you speed up switching between namespaces using kubectl?

Experience Level: Medior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Option 1:

Create alias and variable:

alias k=kubectl
    export n="config set-context --current --namespace"

Then switch namespace like this:

k $n=default

Option 2:

Create two aliases

alias k=kubectl
alias kn="kubectl config set-context --current --namespace"

Then switch namespace like this:

kn default
QUESTION 10:

How do you find Kubernetes pods that consume the most CPU?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl top pod --sort-by="cpu" -o wide

You can also disable headers by using --no-headers parameter.
To display information about usage of containers, use --containers=true parameter.

QUESTION 11:

What does kubectl cordon do?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Cordon marks the Kubernetes node unschedulable to prevent new pods from arriving. This is usually done as a preparation for node upgrade.

To cordon the node, run the following command:

kubectl cordon nodename
QUESTION 12:

What does kubectl uncordon do?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Uncordon makes the node schedulable again after it has been cordoned before. This command is usually used after the node has been upgraded to higher version (for which it needed to be cordoned).

To uncordon the node, run the following command:

kubectl uncordon nodename
QUESTION 13:

What does kubectl drain do?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Drain marks the node as unschedulable to prevent new pods from arriving. It also evicts the pods from the node.

Drain is executed to drain the node in preparation for maintenance.

To drain the node, run the following command:

kubectl drain nodename
QUESTION 14:

What is a taint in Kubernetes?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

A taint is a node rule defining that pods shouldn't be scheduled on the node unless the pods have a matching rule (toleration) saying that they can be scheduled on the node and ignore the taint.
QUESTION 15:

How can you identify what IP addresses have the nodes assigned in Kubernetes?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

To get IP addresses of all nodes, run the following command:

kubectl get nodes -o wide
QUESTION 16:

How do you display current Kubernetes context using kubectl?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Option 1:

Run the following command:

kubectl config current-context

Option 2:

Run the following command:

kubectl config get-contexts|grep "*"
QUESTION 17:

Using kubectl, how do you display list of names of available Kubernetes contexts that you can use from the machine?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl config get-contexts -o name
QUESTION 18:

Without kubectl, how do you display list of names of available Kubernetes contexts that you can use from the machine?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Use the following command:

cat ~/.kube/config|yq eval -o json|jq ".contexts[].name"

How does it work?

  • The configuration data is stored the file ~/.kube/config
  • cat command displays the conent of the file
  • yq command converts the output from yaml to JSON format
  • jq command will iterate over all child elements of element (array) contexts, name property of each child element is displayed.
QUESTION 19:

How can you display all objects that are present in the current Kubernetes namespace?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl get all
QUESTION 20:

How can you display yaml details of all deployments, pods and services that are present in the current Kubernetes namespace?

Experience Level: Junior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl get deploy,po,svc -o yaml
QUESTION 21:

You are looking for IP address details of your Kubernetes nodes, but you are not sure what is a structure of node manifests. How can you find this details and learn more about the structure?

Experience Level: Medior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl get node -o yaml|grep --ignore-case --context=10 ip

How it works?

  • Using kubectl, details of nodes are displayed in yaml format
  • Using grep command, rows are searched for string ip (case insensitive search), besides the row, block of 10 rows before and 10 rows after is displayed
  • This allows you to quickly find key blocks in manifests when you don't know exactly what you are looking for. Based on the output you can further refine the query.
QUESTION 22:

Using kubectl, how do you convert yaml manifest of a specific pod pod1 to JSON format?

Experience Level: Medior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command:

kubectl get po pod1 -o json
QUESTION 23:

How do you find all pods that run on a master node?

Experience Level: Medior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command to find a master node:

kubectl get node|grep master

Copy the node name and run the following command:

kubectl get pod -o wide|grep your-master-node-name
QUESTION 24:

How can you run a pod on each node of Kubernetes and make sure that it is running only once on on each node?

Experience Level: Medior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Option 1:

Create a deamonset.

Option 2:

Create a deployment that has pods with antiaffinity that allows only one pod to run on a node. Make sure the count of replicas is the same or higher than the number of nodes.

QUESTION 25:

How do you get a list of endpoints that are available for service service1?

Experience Level: Medior
Tags: Kubernetes
Question category: Kubernetes(58)NEW

Answer

Run the following command

kubectl get ep service1

Blog

15 Azure Cloud questions to verify that you understand Azure Network Security Groups

Azure Network Security Groups play a crucial role in fortifying your virtual network and enhancing the security of your cloud-based application. Evaluate your understanding of these key components now.

Read article

25 Adobe XD questions that will help you to nail your job interview

Presenting a thorough list of Adobe XD job interview questions, accompanied by their answers. This resource is expertly designed to empower you to excel in job interviews, pinpoint knowledge gaps, and uncover fresh insights about Adobe XD. Recognized as a potent tool, Adobe XD streamlines the creation of prototypes and the design of user experiences.

Read article

25 Flexbox questions that will help you to nail your job interview

Introducing an all-inclusive list of Flexbox job interview questions, complete with answers. This resource is meticulously curated to aid you in acing job interviews, spotting areas of knowledge deficit, and discovering new facets of Flexbox. An innovative layout mode introduced in CSS3, Flexbox was designed to supersede less efficient float and table layouts. It enables the automatic arrangement of responsive elements within a container, adapting fluidly to different screen sizes.

Read article

25 Git questions that will help you to nail your job interview

Presenting an extensive list of Git job interview questions, complete with answers. This resource is designed not only to help you ace your job interview but also to identify any existing knowledge gaps and provide an opportunity to learn new aspects about Git. As a modern distributed version control system, Git holds the position as the most widely used system in today's tech landscape.

Read article

25 Kubernetes questions that will help you get certified and become more efficient with K8s

Mastering Kubernetes can be a complex task, but certain tips and tricks can expedite your journey, instilling you with confidence when it comes to maintaining Kubernetes clusters. This curated set of questions is designed to elevate your skills to the next level. If you're aiming for certification, going through this list is a must.

Read article