Practice Test - PODs
- Take me to Practice Test
Here are the solutions to the practice test
-
How many pods exist on the system?
kubectl get podsCount the number of pods (if any)
-
Create a new pod with the nginx image.
kubectl run nginx --image=nginx -
How many pods are created now?
kubectl get podsCount the number of pods (if any)
To get the system to tell you you can also do this
kubectl get pods --no-headers | wc -l--no-headersshould be obvious - output only the details.wcis the word count program.-ltells it to count lines instead, and it will count the lines emitted bykubectl
-
What is the image used to create the new pods?
kubectl describeoutputs lots of information. The following will describe all pods whose name starts withnewpods, and then we filter withgrepto get what we are looking for.kubectl describe pod newpods | grep imageWe see that all three are pulling the same image.
-
Which nodes are these pods placed on?
kubectl get pods -o wideNote the node column for each of the 3
newpodspods -
How many containers are part of the pod webapp?
kubectl describe pod webappLook under the
Containerssection. Note there isnginxandagentx -
What images are used in the new webapp pod?
Examine the output from Q6. For each of the identified containers, look at
Image: -
What is the state of the container agentx in the pod webapp?
kubectl describe pod webappExamine the
State:field for theagentxcontainer. -
Why do you think the container agentx in pod webapp is in error?
Examine the output from Q8 and look in the
Events:section at the end. Look at the event that saysfailed to pull and unpack image ... -
What does the READY column in the output of the kubectl get pods command indicate?
kubectl get podsLook at the
webapppod which we know has two containers and one is in error. You can deduce which of the answers is correct from this. -
Delete the webapp Pod.
kubectl delete pod webappTo delete the pod without any delay and confirmation, we can add
--forceflag. Note that in a real production system, forcing is a last resort as it can leave behind containers that haven’t been cleaned up properly. Some may have important cleanup jobs to run when they are requested to terminate, which wouldn’t get run.You can however use
--forcein the exam as it will gain you time. No exam pods rely on any of the above. -
Create a new pod with the name redis and with the image redis123.
Use a pod-definition YAML file.To create the pod definition YAML file:
--dry-run=clienttellskubectlto test without actually doing anything.-o yamlsays “Output what you would send to API server to the console”, which we then redirect into the named file.kubectl run redis --image=redis123 --dry-run=client -o yaml > redis.yamlAnd now use the YAML you created to deploy the pod.
kubectl create -f redis.yaml -
Now change the image on this pod to redis.
Once done, the pod should be in a running state.There are three ways this can be done!
-
Method 1
Edit your manifest file created in last questionvi redis.yamlFix the image name in the redis.yaml to
redis, save and exit.Apply the edited yaml
kubectl apply -f redis.yaml -
Method 2
Edit the running pod directly (note not all fields can be edited this way)kubectl edit pod redisThis will bring the pod YAML up in
vi. Edit it as per method 1. When you eixtvithe change will be immediately applied. If you make a mistake, you will be dropped back intovi -
Method 3
Patch the image directly. For this you need to know thenameof the container in the pod, as we assign the new image to that name, as incontainer_image_name=new_imagekubectl set image pod/redis redis=redis
-