Reputation: 1024
if I create a pod imperatively like this, what does the --port option do?
kubectl run mypod --image=nginx --port 9090
nginx application by default is going to listen on port 80. Why do we need this option? The documentation says
--port='': The port that this container exposes.
If it is exposed using kubectl expose pod mypod --port 9090
, it is going to create service on port 9090 and target port 9090. But in the above case it neither creates a service
Upvotes: 1
Views: 466
Reputation: 1024
When port option is already given to pod,
When --port option is neither defined in the pod nor in expose it will be an error.
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#ports
Upvotes: 1
Reputation: 15500
...nginx application by default is going to listen on port 80. Why do we need this option?
The use of --port 80
means the same if you write in spec:
...
containers:
- name: ...
image: nginx
ports:
- containerPort: 80
...
It doesn't do any port mapping but inform that this container will expose port 80.
...in the above case it neither creates a service
You can add --expose
to kubectl run
which will create a service, in this case is the same if you write in spec:
kind: Service
...
spec:
ports:
- port: 80
targetPort: 80
...
Note you can only specify one port with --port
, even if you write multiple --port
, only the last one will take effect.
Upvotes: 3