Kubernetes CKA sample exam question 13 with answer

Question
Create a pod called web-pod using image nginx, expose it internally with a service called web-pod-svc. Check that you are able to look up the service and pod from within the cluster.
Use the image busybox:1.28 for DNS lookup.
Record results in /root/web-svc.svc and /root/web-pod.pod

Answer
Create the pod:

kubectl run web-pod --image nginx
Expose that pod:
kubectl expose pod web-pod --name=web-pod-svc --port=80
Get the pod in wide format. We will need the IP for DNS lookup:
kubectl get po -o wide
Check the endpoint for service:
kubectl describe svc web-pod-svc
Create nslookup pod:
kubectl run nslookup --image=busybox:1.28 --command sleep 4800
Try to nslookup web-pod-svc from this new pod:
kubectl exec -it nslookup -- nslookup web-pod-svc
We can see that it is resolved. Redirect to the file:
kubectl exec -it nslookup -- nslookup web-pod-svc > /root/web-svc.svc
Verify the output:
cat /root/web-svc.svc
Try to lookup the pod:
kubectl exec -it nslookup -- nslookup 10-50-192-1.default.pod
where the 10-50-192-1 is the IP of the pod with dashes, default is the namespace
You should use this name to properly resolve it. Write to a file:
kubectl exec -it nslookup -- nslookup 10-50-192-1.default.pod > /root/web-pod.pod
Verify:
cat /root/web-pod.pod