Pod Design
Some of the scenario questions here are based on Kodekloud's CKAD course labs.
CKAD and CKA can have similar scenario questions. It is recommended to go through the CKA practice tests.
Shortcuts
First run the two commands below for shortcuts.
export do="--dry-run=client -o yaml"
export now="--force --grace-period=0"
Questions
-
Upgrade the application by setting the image on the deployment to kodekloud/webapp-color:v2. Do not delete and re-create the deployment. Only set the new image name for the existing deployment.
controlplane ~ ✦ ➜ k get deployments.appsNAME READY UP-TO-DATE AVAILABLE AGEfrontend 4/4 4 4 6m46sAnswer
controlplane ~ ✦ ✖ k set image deploy frontend simple-webapp=kodekloud/webapp-color:v2deployment.apps/frontend image updatedcontrolplane ~ ➜ k get deployments.appsNAME READY UP-TO-DATE AVAILABLE AGEfrontend 5/4 4 3 5m18s -
Change the deployment strategy to Recreate.
controlplane ~ ✦ ➜ k get deployments.appsNAME READY UP-TO-DATE AVAILABLE AGEfrontend 4/4 4 4 6m46sAnswer
controlplane ~ ✦2 ➜ k get deployments.appsNAME READY UP-TO-DATE AVAILABLE AGEfrontend 4/4 4 4 8m14scontrolplane ~ ✦2 ➜ k get deployments.apps frontend -o yaml > frontend.ymlcontrolplane ~ ✦2 ➜ k delete -f frontend.ymldeployment.apps "frontend" deletedcontrolplane ~ ✦2 ➜ k get deployments.appsNo resources found in default namespace.## frontend.yml---apiVersion: apps/v1kind: Deploymentmetadata:name: frontendnamespace: defaultspec:replicas: 4selector:matchLabels:name: webappstrategy:type: Recreatetemplate:metadata:labels:name: webappspec:containers:- image: kodekloud/webapp-color:v2name: simple-webappports:- containerPort: 8080protocol: TCPcontrolplane ~ ✦2 ➜ k apply -f frontend.ymldeployment.apps/frontend createdcontrolplane ~ ✦2 ➜ k get deployments.appsNAME READY UP-TO-DATE AVAILABLE AGEfrontend 4/4 4 4 6s -
A pod definition file named throw-dice-pod.yaml is given. The image throw-dice randomly returns a value between 1 and 6. 6 is considered success and all others are failure. Try deploying the POD and view the POD logs for the generated number. File is located at /root/throw-dice-pod.yaml
controlplane ~ ➜ cat throw-dice-pod.yamlapiVersion: v1kind: Podmetadata:name: throw-dice-podspec:containers:- image: kodekloud/throw-dicename: throw-dicerestartPolicy: NeverNext, create a Job using this POD definition file or from the imperative command and look at how many attempts does it take to get a '6'.
-
Job Name: throw-dice-job
-
Image Name: kodekloud/throw-dice
Then update the job definition to run as many times as required to get 3 successful 6's
Answer
controlplane ~ ➜ k apply -f throw-dice-pod.yamlpod/throw-dice-pod createdcontrolplane ~ ➜ k get poNAME READY STATUS RESTARTS AGEthrow-dice-pod 0/1 ContainerCreating 0 3scontrolplane ~ ➜ k get poNAME READY STATUS RESTARTS AGEthrow-dice-pod 0/1 Error 0 4scontrolplane ~ ➜ k logs throw-dice-pod5Create the job.
controlplane ~ ➜ k create job throw-dice-job --image kodekloud/throw-dice $doapiVersion: batch/v1kind: Jobmetadata:creationTimestamp: nullname: throw-dice-jobspec:template:metadata:creationTimestamp: nullspec:containers:- image: kodekloud/throw-dicename: throw-dice-jobresources: {}restartPolicy: Neverstatus: {}controlplane ~ ➜ k create job throw-dice-job --image kodekloud/throw-dice $do > job.yml## job.ymlapiVersion: batch/v1kind: Jobmetadata:creationTimestamp: nullname: throw-dice-jobspec:backoffLimit: 15template:metadata:creationTimestamp: nullspec:containers:- image: kodekloud/throw-dicename: throw-dice-jobresources: {}restartPolicy: Neverstatus: {}controlplane ~ ➜ k apply -f job.ymljob.batch/throw-dice-job createdcontrolplane ~ ➜ k get jobNAME COMPLETIONS DURATION AGEthrow-dice-job 0/1 4s 4sUpdate the job definition to run as many times as required to get 3 successful 6's
apiVersion: batch/v1kind: Jobmetadata:name: throw-dice-jobspec:completions: 3backoffLimit: 25 # This is so the job does not quit before it succeeds.template:spec:containers:- name: throw-diceimage: kodekloud/throw-dicerestartPolicy: Never -
-
Using the same YAML file from the previous question, speed it up by running upto 3 jobs in parallel.
controlplane ~ ✦2 ➜ k get jobNAME COMPLETIONS DURATION AGEthrow-dice-job 3/3 15s 40sAnswer
controlplane ~ ✦2 ➜ k delete job throw-dice-jobjob.batch "throw-dice-job" deletedcontrolplane ~ ✦2 ➜ k get jobNo resources found in default namespace.## job.ymlapiVersion: batch/v1kind: Jobmetadata:name: throw-dice-jobspec:parallelism: 3completions: 3backoffLimit: 25 # This is so the job does not quit before it succeeds.template:spec:containers:- name: throw-diceimage: kodekloud/throw-dicerestartPolicy: Nevercontrolplane ~ ✦2 ➜ k apply -f job.ymljob.batch/throw-dice-job created -
Using the same YAML file from the previous question, schedule that job to run at 21:30 hours every day.
Answer
## cronjob.ymlapiVersion: batch/v1kind: CronJobmetadata:name: throw-dice-cron-jobspec:schedule: "30 21 * * *"jobTemplate:spec:completions: 3parallelism: 3backoffLimit: 25 # This is so the job does not quit before it succeeds.template:spec:containers:- name: throw-diceimage: kodekloud/throw-dicerestartPolicy: Nevercontrolplane ~ ✦5 ➜ k apply -f cronjob.ymlcronjob.batch/throw-dice-cron-job createdcontrolplane ~ ✦5 ➜ k get cronjobs.batchNAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGEthrow-dice-cron-job 30 21 * * * False 0 <none> 8s