Are You Pivoting Towards K8s? Aiming For CKA?
Are You Pivoting Towards K8s? Aiming For CKA?
Table of Contents
Reference Courses: ....................................................................................................................................... 3
Final exam preparation: ................................................................................................................................ 3
Exam Restrictions:......................................................................................................................................... 3
Import pointer for Exam Terminal: ............................................................................................................... 4
Important Tip – Time management: ............................................................................................................. 4
Important Tip – Answering questions:.......................................................................................................... 5
Exam Topics sort by weightage in desc order:.............................................................................................. 9
Domain 1: core concepts .............................................................................................................................. 9
json path useful scenarios: ....................................................................................................................... 9
Additional scenarios that is for your practice: .......................................................................................... 9
Busybox test pod creation note: ......................................................................................................... 11
Domain 2 : Application Life cycle management.......................................................................................... 11
Important topics (rolling updates | rollbacks | scaling | record instruction | Jobs and cron Jobs ) ...... 11
Domain 3 :-Networking ............................................................................................................................... 16
Important points ..................................................................................................................................... 16
Example Scenarios .................................................................................................................................. 17
Service - Scenarios .............................................................................................................................. 17
DNS – Service and Pod DNS checks..................................................................................................... 21
Network policies ..................................................................................................................................... 22
Domain 4:- Scheduling ................................................................................................................................ 22
Important Questions and pointer: .......................................................................................................... 22
Domain 5 :-Security..................................................................................................................................... 24
Domain 6 :- Storage .................................................................................................................................... 24
Domain 7:-Installation, configuration, Validation (Highest weightage 8% in the Exam)............................ 24
How to setup a kubeadm cluster? .......................................................................................................... 24
Master Node: ...................................................................................................................................... 24
Worker Node:...................................................................................................................................... 25
Verification: ......................................................................................................................................... 25
ETCD back-up and restore....................................................................................................................... 26
Domain 8 :- Logging / Monitoring ............................................................................................................... 27
Domain 9:- Troubleshooting ....................................................................................................................... 28
Useful approach towards debugging the broken cluster ....................................................................... 28
Domain 10: Cluster Maintenance ............................................................................................................... 29
Reference Courses:
➢ https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/
➢ https://www.udemy.com/course/certified-kubernetes-administrator/
Exam Restrictions:
• Exam will be running for 3 continues hours. Try to avoid taking breaks during exam.
• Exam pass percentage is 74% and given with 24 tasks. Roughly if you get 18 to 19
questions right, you would exceed the % expectation.
• You can keep a glass of water in a transparent glass during exam.
• You are not allowed to have any other gadgets on the exam table and the ambience
must be noise free
• Proctor will continuously monitor you throughout the exam
• Try avoiding murmuring the questions and avoid covering your mouth with your hands
(even if you have a habit of)
• Try maintaining placing your face in the mid of the camera. Sometimes we adjust our
posture that may lead to move away from camera focus. Proctor will bare for three
times. The third time will be the final warning. Fourth time, if we repeat the same then he
will terminate the exam session and will be disqualified.
➢ First step upon starting your exam window before read your first question, please do this
step
o Use the K8s cheatsheet bash profile autocompletion
o Please redo this if you exit from the exam terminal in the mid of your exam and
relaunch the exam terminal
➢ Second step set the vim shortcuts profile, this is to ease the yaml indentation correction
via tab press and view the line numbers in the vi editor.
vim ~/.vimrc
set nu
set ic
set expandtab
set shiftwidth=2
set tabstop=2
As we set the kubectl autocompletions, we would not required to set any other aliases
for kubectl commands rather you can use the tab to autocomplete the commands
Note: Please remember if you do any typo error in the mid of the kubectl command
then the autocompletion will not work.
➢ If you are trying to dry-run the pod definition as yaml along with the commands and
arguments, please place the --dry-run -o yaml prior -- commands section, else the dry
run yaml content will be empty.
o Example: Correct command
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- args:
- sh
- -c
- sleep 3600
image: busybox
name: busybox
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
status: {}
o Example: Wrong pattern (dry run param is used at the end of the pod creation
command)
k run busybox --image=busybox --restart=Never -- sh -c “sleep 3600” --dry-run
-o yaml > busybox-pod.yaml
➢ If you are trying to dry-run the pod definition as yaml and the pod to be created in any
specific namespace.
o For example, in qa namespace, you want to create busybox pod, you have
opted to dry run the yaml first and apply it
o Please note that if you use the --namespace=qa along with the dry-run
command option, it will not be effective and the resultant yaml will not contain the
namespace section added
o Example of wrong usage,
o Correct usage is dry run the yaml without the namespace and when apply the
yaml use the --namespace=qa parameter.
k run busybox --image=busybox --restart=Never --dry-run -o yaml -- sh -c
“sleep 3600” > busybox-pod.yaml
➢ Please note that busybox container image will not have the required nettool package
installed in it. Hence use busybox:1.28 container image if you are required to any pod /
service networking troubleshooting or dns tasks.
#Job imperative command to run parallel X number and complete after Y times
k run <Jobname> --restart=OnFailure | dry-run as yaml & edit yaml to add
.spec.parallelism : X | .spec.completions : Y
# Edit service
systemctl edit kubelet.service
or
vim /etc/systemd/system/kubelet.service
1. Retrieve the name,OS Image and the Internal IP address of the nodes in a new line.
Result:
master Ubuntu 16.04.6 LTS 172.17.0.61
node01 Ubuntu 16.04.6 LTS 172.17.0.48
❖ Please retrieve the nodes spec to file using k get nodes -o yaml
❖ Understand the structure of the yaml elements on the screen
❖ Identify the list and map elements from the yaml. Generally, if you are listing all
the nodes then it will be listed as array of items.
❖ If you want to print the data into new lines, then you should range over the items.
Result:
node01
Solution 2: Get nodes as custom columns > Get node metadata name > Get the taint
info | Exclude NoSchedule taint effect via grep command
Result:
NODENAME TAINTS
node01 <none>
3) Retrieve the nodes that are not schedulable and the time that they are being made as
unschedulable.
Solution: Range over node items > Get node metadata name > Filter the taint effect is
equal to NoSchedule and fetch the timeAdded map key to list the time that is being
made unscheduled or drained.
Result:
node01 2020-04-03T03:33:03Z
4) Check the Image version of the nginx pod without the describe command?
-----------------------------------------------------------------------------------------------------------
[In case of error in the deployment of your app, if you want to rollback to previous version of the
deployment then run rollout to undo]
# if you want to rollback to specific version of the deployment then use --to-
revision=<version#>
scenario 3:- Cron job that will be executed every minutes that prints the current date and Hello
from the Kubernetes cluster
https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/
# --restart=OnFailure represents the run is for Job and –schedule represents this Job is a
cron
scenario 5 :- ConfigMaps
General Exam scenario would be creating a config map from given literal and attach that to pod
as environment variable or as volume mount.
https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/
• You can use ConfigMap as the Key Value Pair to inject the env variable to the POD
definition.
We can create config map from file as well. Lets assume the app_config.properties has
the key value pairs defined in it and we are about to create a configMap using the file.
• You can refer to the kubectl bookmarks for the reference K8s documentation page.
scenario 6 :- Secrets
https://kubernetes.io/docs/concepts/configuration/secret/
General Exam scenario would be creating a config map from given literal and attach that to pod
as environment variable or as volume mount.
In case, you want to pass on the env variable such as DB Host, User, Password to the web
application then use Kubernetes Secrets.
kubectl create secret generic app-secret --from-literal=DB_host=mysql --from-
literal=DB_user=root --from-literal=DB_passwd=mysql
There is a concept called horizontal pod autoscaling (HPA) and is important for exam point of
view that you will be asked to scale your deployment to max of 3 replicas if the cpu usage hits
80%
kubectl autoscale deployment/my-nginx --min=1 --max=3 --cpu-percent=80
pod/nginx-envpod created
# Verify that the pod is created with the specified limit and request range
master $ k describe pod nginx-limit-req-pod | grep -i limits -A 5
Limits:
cpu: 4
memory: 4Gi
Requests:
cpu: 2
memory: 2Gi
Note: Always practice using the imperative kubectl command to save your time in the exam.
-------------------------------------------------------------------------------------------------------------------------------
Domain 3 :-Networking
Important points
Familiarize with how to create a service and understand diff types of services clusterIP and
NodePort
➢ How to set a port for NodePort >> Familiar with port and target port within a service
➢ If you expose any deployment or pod without explicitly defining the type , it will be
defaulted to ClusterIP service
➢ For any service,
o port is Service’s own front end port which client will be accessing
o target-port is back end application’s port that are running inside the container
➢ A service will internally create an End point object that collects the pool of POD ips that
are matching the service’s selector label and create an Ip table to route the actual
request.
➢ Whenever you expose any service, ensure the selector used for the service is correct.
o The Service will not be able to directly connect to the pods rather it connects via
end points
o If the selector doesn’t match with the running pods label, then there will be no
underlying end points created for the service. Hence the actual client request to
the service will timeout.
o
Example Scenarios
Service - Scenarios
o Example Scenario: There is a nginx deployment running and the underlying
pods are with label run=nginx and expose the service as nginx-dev-service type
cluster IP and the service port should be 8080. Note that the target nginx service
is running with port 80 in the container.
# Filter the pods to confirm the pods are running with run=nginx label
master $ k get ep
NAME ENDPOINTS AGE
nginx-dev-service 10.44.0.2:80,10.44.0.3:80,10.44.0.4:80 2m50s
# Launch the busybox pod with image busybox:1..28 for any serevice / dns checks
# We will need to test the service accessibility from a client. We will use the
servicecheck pod and the client. Get into the servicecheck pod and access the nginx-
dev-service over the service’s front end port 8080
# Connection is successful to the nginx app running inside pod’s container with port 80
o Assume that when you expose the deployment with wrong selector then the
result would be,
o Service creation will be successful
o Underlying endpoints would not be created. Hence there will be no Ip
tables for request routing from service to target pods
o Client connection will be unsuccessful
o Let’s simulate the scenario, take the resources from the above
example.
The End point object couldn’t find a running pod with the defined selector label
app=web
master $ k get ep
NAME ENDPOINTS AGE
nginx-wrong-service <none> 80s
# We will need to test the service accessibility from a client. We will use the
servicecheck pod that was created earlier. Get into the servicecheck pod and access
the nginx-wrong-service over the service’s front end port 8080
# Failed to connect to the nginx app running inside pod’s container with port 80
➢ When you are asked to expose a deployment as NodePort and given with the specific
node port then you will need to dry-run the expose imperative command as yaml and
manually edit the yaml with the given node port
o Example Scenario: There is a nginx deployment running and the underlying
pods are with label run=nginx and expose the service as nginx-np-service type
Node Port and the service port should be 8080 and the node port will be 32008.
Note that the target nginx service is running with port 80 in the container.
# Expose the service as NodePort Type and dry run as yaml
# Edit the nginx-np-service.yaml file and add the nodePort: 32008 as sibling to the
targetport element to match with the asked node port
master $ k get ep
NAME ENDPOINTS AGE
nginx-np-service 10.32.0.2:80,10.32.0.3:80,10.32.0.4:80 118s
# Verify the ap accessibility over service. Please note that the node port is used to
access the service from LB end and from internal cluster if you want to access the
service then use the service’s own front-end port 8080
# Connection is successful to the nginx app running inside pod’s container with port 80
Name: nginx-dev-service
Address 1: 10.96.141.251 nginx-dev-service.default.svc.cluster.local
Example Scenario: Pod DNS Check. Record the dns entry of pod nginx-7db9fccd9b-7b5j7
to the file /opt/nginx-pod-dns
# List the pod nginx-7db9fccd9b-7b5j7 and with the wide option to see the pod IP
master $ k get po nginx-7db9fccd9b-7b5j7 -o wide
NAME READY STATUS RESTARTS AGE IP NODE
NOMINATED NODE READINESS GATES
nginx-7db9fccd9b-7b5j7 1/1 Running 0 48m 10.32.0.2 node01 <none>
<none>
Name: 10-32-0-2.default.pod
Address 1: 10.32.0.2 10-32-0-2.nginx-dev-service.default.svc.cluster.local
Network policies
Scenario 1 :- deployment > service expose > map ingress network policy >> testing
https://kubernetes.io/docs/concepts/services-networking/network-policies/#default-policies
------------------------------------------------------------------------------------------------------------------------------
o Once your dry run the pod add the nodeSelector to he yaml definition. Refer to
the Kubernetes docs for reference.
➢ Fix the broken cluster. All the pods are in pending state,
o If you are asked to fix the broken cluster where the Pods are in pending state or
API Server itself inaccessible
▪ There is a high possibility that the kubelet is not referring to the right static
pod manifest path in the master node.
o Verify the static pod path entry staticPodpath: /etc/kubernetes/manifests in the
kubelet config file /var/lib/kubelet/config.yaml
o If the above entry is not there or the entry is pointed to staticPodpath: BROKEN
then adding/updating the entry staticPodpath: /etc/kubernetes/manifests and
save the file.
o Restart and enable the kubelet in the node
▪ systemctl daemon-reload
▪ systemctl restart kubelet
▪ systemctl enable kubelet
o Try access the Kube API server by issuing kubectl get nodes.
o You will get results now as the master node’s kubelet is launched all the master
component pod’s from the manifest path /etc/kubernetes/manifests
o If you are asked to launch a static pod in any target node, once you ssh to the
target node
o Verify the static pod path entry staticPodpath: /etc/kubernetes/manifests in the
kubelet config file /var/lib/kubelet/config.yaml
o If the above entry is not there then adding the entry and save the file.
o Restart and enable the kubelet in the node
▪ systemctl daemon-reload
▪ systemctl restart kubelet
▪ systemctl enable kubelet
o Go to /etc/kubernetes/manifests/ and vi static-pod.yaml and copy the static pod
creation yaml content form the notepad and save the file
o Exit from the node and go to the exam terminal look for the pods created
master $ k get po
NAME READY STATUS RESTARTS AGE
static-pod-node01 1/1 Running 0 11s
Note: The static pod is differentiated with the name. Always the static pods are
appended with the node name that was launched. In our case the created pod is
static-pod and is appended with it’s node name node01.
------------------------------------------------------------------------------------------------------------------------------
Domain 5 :-Security
➢ Basic understanding SSL/TLS certificates
➢ Certificate Authority
➢ Component’s Certificate
➢ Good understanding on Kebernetes secrets >> create a secret from a literal value >>
Create a secret from a file >> Mount Secret to a pod-based Environment variable >>
Mount secret to a pod
➢ Basics of Authentication and Authorization >> create a role and role binding >> create a
cluster role and cluster role binding >> Associate with the user / service account
➢ Familiar with pod security context >> runAsUser >> runAsGroup >> fsGroup
➢ To verify that the user <ravi> has the access to create pods in namespace dev,
-------------------------------------------------------------------------------------------------------------------------------
Domain 6 :- Storage
➢ Understanding of Volumes
o Mostly Empty directory volume will be asked in the exam
o You will need to map the empty directory volume to the pod volume mount
➢ Creating Persistent Volume and Volume Claim might be asked.
➢ Refer to K8s bookmarks’ s Storage section for the reference pages.
-------------------------------------------------------------------------------------------------------------------------------
• Copy the Node joining token from the terminal to exam notepad
• Install the Pod network Add on
o Flannel – Copy the kubectl apply command and apply as is
kubectl apply -f
https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65
e414cf26827915/Documentation/kube-flannel.yml
o Please do not add additional add on. Flannel is enough to
bring your cluster up and running
• Ensure you enable kubelet as a precautionary measure to auto
start the kubelet process upon node restarts
o systemctl daemon-reload
o systemctl restart kubelet
o systemctl enable kubelet
Worker Node:
▪ Follow the Kubernetes documentation
• Ensure you are switched to the respective worker node and
switched to root user
• Install kubelet kubeadm kubectl
• Join your nodes
• Ensure you enable kubelet as a precautionary measure to auto
start the kubelet process upon node restarts
o systemctl daemon-reload
o systemctl restart kubelet
o systemctl enable kubelet
Verification:
▪ ssh to master node and issue k get nodes command to confirm the
Cluster is setup is completed.
-----------------------------------------------------------------------------------------------------------------------------
o List all top three hungry pods from all namespaces in a file /tmp/cpu-hungry-
pods.txt
kubectl top pod --all-namespaces | sort --reverse --key 3 --numeric| head -3 >
/tmp/cpu-hungry-pods.txt
-----------------------------------------------------------------------------------------------------------------------------
➢ Exit from the node and verify the node status from the exam terminal kubectl get nodes
-----------------------------------------------------------------------------------------------------------------------------
Scenario: Make the worker node node01 as un-schedulable. Ensure all the running
pods are evicted from the node
master $ kubectl drain node01 --ignore-daemonsets
Scenario: Make the worker node node01 as un-schedulable. Ensure all the running
pods are evicted from the node01 and migrated to new node.
master $ kubectl drain node01 --ignore-daemonsets --force