<p>if I create a pod imperatively like this, what does the --port option do?</p>
<p><code>kubectl run mypod --image=nginx --port 9090</code></p>
<p>nginx application by default is going to listen on port 80. Why do we need this option?
The documentation says</p>
<blockquote>
<p>--port='': The port that this container exposes.</p>
</blockquote>
<p>If it is exposed using <code>kubectl expose pod mypod --port 9090</code>, it is going to create service on port 9090 and target port 9090. But in the above case it neither creates a service</p>

Logu
<p><code>...nginx application by default is going to listen on port 80. Why do we need this option?</code></p>
<p>The use of <code>--port 80</code> means the same if you write in spec:</p>
<pre><code>...
containers:
- name: ...
  image: nginx
  ports:
  - containerPort: 80
...
</code></pre>
<p>It doesn't do any port mapping but inform that this container will expose port 80.</p>
<p><code>...in the above case it neither creates a service</code></p>
<p>You can add <code>--expose</code> to <code>kubectl run</code> which will create a service, in this case is the same if you write in spec:</p>
<pre><code>kind: Service
...
spec:
  ports:
  - port: 80
    targetPort: 80
...
</code></pre>
<p>Note you can <strong>only</strong> specify one port with <code>--port</code>, even if you write multiple <code>--port</code>, only the last one will take effect.</p>
