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:

  1. Create a single Pod named ready-if-service-ready with image nginx:1.16.1-alpine.
  2. Configure a LivenessProbe which simply runs true.
  3. Also configure a ReadinessProbe which does check if the url http://service-am-i-ready:80 is reachable, you can use wget http://service-am-i-ready:80 for this.
  4. Start the Pod and confirm it isn't ready because of the ReadinessProbe
  5. Create a second Pod named am-i-ready of image nginx:1.16.1-alpine with label id: cross-server-ready.
  6. The already existing Service service-am-i-ready should now have that second Pod as endpoint.
  7. Now the first Pod should be in ready state - confirm that.

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, service-am-i-ready.

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 service-am-i-ready.

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 LivenessPRobe and 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 service-am-i-ready.

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: