CKAD Exercices Part3
CKAD Exercices Part3
CKAD Exercices Part3
CKAD - 2023
Objectives
Questions
Create 5 nginx pods in which two of them is labeled env=prod and three of them is labeled
env=dev
Get the pods with label env=dev and also output the labels
Get the pods with label env=prod and also output the labels
Get the pods with labels env=dev and env=prod and output the labels as well
Change the label for one of the pod to env=uat and list all the pods to verify
Remove the labels for the pods that we created now and verify all the labels are removed
Let’s add the label app=nginx for all the pods and verify
Get all the nodes with labels (if using minikube you would get only master node)
Create a Pod that will be deployed on this node with the label nodeName=nginxnode
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
CKAD - 2023
labels:
run: nginx
name: nginx
spec:
nodeSelector:
nodeName: nginxnode
containers:
- image: nginx
name: nginx
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
status: {}
Verify the pod nginx that we just created has this label
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: webapp
name: webapp
spec:
replicas: 5
selector:
matchLabels:
app: webapp
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: webapp
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
Delete the deployment you just created and watch all the pods are also being deleted
Create a deployment of webapp with image nginx:1.17.1 with container port 80 and verify the
image version
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: webapp
CKAD - 2023
name: webapp
spec:
replicas: 1
selector:
matchLabels:
app: webapp
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: webapp
spec:
containers:
- image: nginx:1.17.1
name: nginx
ports:
- containerPort: 80
resources: {}
status: {}
// verify
kubectl describe deploy webapp | grep Image
Update the deployment with the image version 1.17.4 and verify
Check the rollout history and make sure everything is ok after the update
Undo the deployment to the previous version 1.17.1 and verify Image has the previous version
Update the deployment with the image version 1.16.1 and verify the image and also check the
rollout history
Update the deployment with the wrong image version 1.100 and verify something is wrong with
the deployment
Undo the deployment with the previous version and verify everything is Ok
Update the deployment with the image version latest and check the history and verify nothing is
going on
Check the rollout history and verify it has the new version
Apply the autoscaling to this deployment with minimum 10 and maximum 20 replicas and target
CPU of 85% and verify hpa is created and replicas are increased to 10 from 1
Clean the cluster by deleting deployment and hpa you just created
Create a Job with an image node which prints node version and also verifies there is a pod
created for this job
Output the yaml file for the Job with the image busybox which echos “Hello I am from job”
CKAD - 2023
kubectl create job hello-job --image=busybox --dry-run -o yaml -- echo "Hello I am from job"
Copy the above YAML file to hello-job.yaml file and create the job
kubectl create job hello-job --image=busybox --dry-run -o yaml -- echo "Hello I am from job" > hello-
job.yaml
Verify the job and the associated pod is created and check the logs as well
Create the same job and make it run 10 times one after one
kubectl create job hello-job --image=busybox --dry-run -o yaml -- echo "Hello I am from job" > hello-
job.yaml
apiVersion: batch/v1
kind: Job
metadata:
creationTimestamp: null
name: hello-job
spec:
completions: 10
template:
metadata:
creationTimestamp: null
spec:
containers:
- command:
- echo
- Hello I am from job
image: busybox
name: hello-job
CKAD - 2023
resources: {}
restartPolicy: Never
status: {}
Watch the job that runs 10 times one by one and verify 10 pods are created and delete those
after it’s completed
kubectl create job hello-job --image=busybox --dry-run -o yaml -- echo "Hello I am from job" > hello-
job.yaml
apiVersion: batch/v1
kind: Job
metadata:
creationTimestamp: null
name: hello-job
spec:
parallelism: 10
template:
metadata:
creationTimestamp: null
spec:
containers:
- command:
- echo
- Hello I am from job
image: busybox
name: hello-job
resources: {}
restartPolicy: Never
status: {}
Watch the job that runs 10 times parallelly and verify 10 pods are created and delete those after
it’s completed
Create a Cronjob with busybox image that prints date and hello from kubernetes cluster
message for every minute
kubectl create cronjob date-job --image=busybox --schedule="*/1 * * * *" -- bin/sh -c "date; echo Hello
from kubernetes cluster"
Verify that CronJob creating a separate job and pods for every minute to run and verify the logs
of the pod
Delete the CronJob and verify all the associated jobs and pods are also deleted