Kubernetes CKA sample exam question 118 with answer

Question
Create a pod called front-app using nginx image. It should be accessible on local port 80 as well as on node’s port. Make sure the port should be same for all nodes in the cluster.

Answer
In this task you have to create a pod and then expose it on port 80. When you expose a pod or a deployment, it creates a new service.
In this case you have to specify type of service which is NodePort. A NodePort service uses same port on all nodes so no additional configuration is needed. That is just a trick added to the question:

kubectl run front-app --image=nginx --port=80
kubectl expose pod front-app --port=80 --type=NodePort