Prepare for your CKA certification with a real example
This time we are going to learn how to think when we are preparing the CKA test certification. We are going to see how to work with a complex exercise:
- Create a single Pod named
- Configure a LivenessProbe which simply runs
- Also configure a ReadinessProbe which does check if the url
http://service-am-i-ready:80is reachable, you can use
wget http://service-am-i-ready:80for this.
- Start the Pod and confirm it isn't ready because of the ReadinessProbe
- Create a second Pod named
- The already existing Service
service-am-i-readyshould now have that second Pod as endpoint.
- Now the first Pod should be in ready state - confirm that.
Kubernetes audit: it's a complex framework, and it's tricky to get it right. We are here to help you with that. About Kubernetes audits
We have a pod that in the readynessProbe is pointing to an url that is an endpoint created with a service. This service points to another pod, but the interesting thing here is that the exercise starts with one service only,
We start with our service and as you can see here we have defined in this service an id called cross-server-ready:
This id is the key of the exercise. Now we need to create a pod
ready-if-service-ready pointing in the
readinessProbe to the url
This url is setup in the service pointing to the endpoint
am-i-ready with the id
cross-server-ready that will be set it up in the service as you show and in the pod.
We start with
kubectl get all and we see that the service is there.
Now we need to create our pod with the
ReadinessPRobe and to learn how to do that best thing is to check in Kubernetes Documentation page that as we know we are allowed to use in our CKA certification. In the search we have an entry with a pod deployment example that we can get for our case.
Copy the code and create a file called
ready-if-service-ready where we paste the code. We need to remove the parts that are not needed in our case, change the id and the component name. Then we need to change the image to use a busy box image, and after that we need to setup the
livenessProbe with the command
true and the
readinessProbe with the command
sh -c wget to the
Now we apply the the yaml file with Kubectl apply
-f. If we execute
kubectl get all again we can see that the pod is running but if we run
kubectl describe pod/ready-if-service-ready we can see that there is a problem and the
readisnessPRobe is failing. The reason is that we point to the service but the service is not pointing to the pod because is not there yet.
Next step is to create the new pod that is missing. To do that we start copying our previous yaml file. We edit the file and the first thing that we are going to do is remove the livened probe and readiness probe. After that we change the id to
cross-server-ready and the name of the pod and the container name with the image name that will be an Nginx this time.
Now we save and apply the template. If again we execute
kubectl get all we can see that currently our pods are still not running any. If we execute now
kubectl describe pod/cross-server-ready we will see that the pod is not yet ready. In this case is because we are using Google Cloud with GKE autopilot and we need time to start the pod.
When the pod is up and running we can now execute again
kubectl get all we can see how are pods are running as we described in the initial draft. Now we can check with
kubectl describe service/service-am-i-ready and check the endpoint. And that’s all! Remember that it's always better to think twicee in the CKA test!
Here's the same article in video form for your convenience: