Kubernetes – practise exercise – 1

After completing CKA and CKAD certifications, I thought of writing few posts with exercises that can be used by anyone preparing for K8s certifications. I will try my best to cover from basics to complicated ones with both imperative and declarative way wherever possible. This is not same as actual exam and created just for practice, this might help you a lot while preparing as I have covered most of the topics that is part of exam curriculum.

Tip: Make use of imperative commands wherever possible in exam.

  1. Create a new pod app-1 with nginx image and list the pods in default namespace.
syntax: kubectl run <pod-name> --image=<image name>

create the pod:  kubectl run app-1 --image=nginx

List the pods: kubectl get pods

declarative: save the below code into yaml file and run the command kubectl create -f <file-name>.yaml


2. Delete the pod app-1 we just created:

syntax: kubectl delete pod <pod name>

             kubectl delete pod app-1

3. Create a new namespace amazon:

syntax: kubectl create ns <name space>

             kubectl create ns amazon

declarative: save the below code into yaml file and run the command kubectl create -f <file-name>.yaml

4.create a new pod app-2 with nginx image in amazon namespace

syntax: kubectl run <pod name> --image=<image name> -n <name space>

              kubectl run app-2 --image=nginx -n amazon


5. List the pods in amazon namespace

 syntax:      kubectl get pods -n <name space>

                    kubectl get pods -n amazon

6. Create a new pod app-3 with nginx image and tag 3

syntax:  kubectl run <pod name> --image=<image name>:<tag>

              kubectl run app-3 --image=nginx:3


apiVersion: v1
kind: Pod
  name: app-3
- name: app-3
  image: nginx:3

7. Create a new pod app-4 with image nginx:12345, check the status of the pod created.

imperative: kubectl run app-4 --image=nginx:12345

                   kubectl get pods app-4

8. Update the pod app-4 to use correct image nginx

                   kubectl set image pod/app-4 app-4=nginx


kubectl edit pod app-4

search for image nginx:12345 and replace it with nginx , save and exit.

9. List pods from all namespaces:

kubectl get pods --all-namespaces

10. List services from all namespaces:

kubectl get svc --all-namespaces

11. List services from default namespace:

kubectl get svc

12. Get complete details of pod app-4

kubectl describe pod app-4

13. Check pods from all namespaces with node names they are located

kubectl get pods --all-namespaces -o wide

14. Output the pod app-4 to a yaml file: 

kubectl get pod app-4 -o yaml > /tmp/output-app4.yaml

15. Create





Leave a Reply