Hi, which is the right solution for the below task? _*Create the nginx pod with . . .

Sangeetha Radhakrishnan:
which is the right solution for the below task?
Create the nginx pod with version 1.17.4 and expose it on port 8080
Solution1: kubectl run nginx --image=nginx:1.17.4 --port=8080
Solution2: kubectl run nginx --image=nginx:1.17.4 --port=8080; kubectl expose pod nginx --port 8080
As per my understanding the solution2 seems to be correct, because the solution1 does not create service to expose the pod on port 8080, only the nginx container will run on port 8080.
Is my understanding correct?

Fernando Jimenez:
I would concur with you.

As per me, Solution 1 is correct … if the question didn’t say anything about service then it is just expose a container port by --port option

Fernando Jimenez:
Given the ambiguity of the question by using the word expose without much more explanation, solution 2 will cover all bases without harm. Quite often the use of expose port x means a service in itself.

Sangeetha Radhakrishnan:
yes, the solution2 will cover both

Fernando Jimenez:
However, for the sake of completion I would like to point out that the container for nginx will be listening in port 80 and giving it kubectl run nginx --image=nginx:1.17.4 --port=8080 will not force nginx to listen on 8080. In fact, the port in a container is already accessible without the need to tell it in the kubectl run. Further more, the only way that the service could work, for real, is if the imperative command were to be issued as kubectl expose pod nginx --port 8080 --target-port 80

Just for clarification on word ‘expose’, when question use this word in terms of k8s then we have to treat that in context with built in term in this case ‘expose’.