Which answer is correct for the Kubernetes scenario

Task

Create a pod with the following characteristics, and leave it running when complete:

  • The pod must run in the frontend namespace. Check if the namespace has already been created and create if necessary
  • The name of the pod should be cache
  • Use the library/redis image with the 3.2 tag
  • Expose port 6379

kubectl create ns frontend

Answer1:

kubectl run cache --image=library/redis:3.2 --port 6379 -n frontend

Answer2:

kubectl -n frontend run cache --image=library/redis:3.2 --port 6379 --expose

What’s the difference between the two commands? You get your answer from that.

As the question says “expose”. In my opinion the command with “–expose” should be the right answer.

If the problem didn’t ask you to create a service, then the flag would not be appropriate. I’d guess that’s the reason.

1 Like


snapshot from kubernetes-nework-policy-recipes.
It doesn’t say to create a service.

Is there some differene between.
expose it at [port] vs expose [port] ???

–expose creates a service of the same name as the pod. --port sets what port is used by the pod, which the service created via --expose uses that as its port value as well.