<p>Sorry if it's a naive question. Please correct me if my understanding is wrong.</p>
<p>Created POD using this command:</p>
<pre><code>kubectl run nginx --image=nginx --port=8888
</code></pre>
<p>My understand of this command, nginx (application) container will be exposed/available at port 8888</p>
<pre><code>kubectl get pods -o wide
NAME    READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          10m   10.244.1.2   node01   &lt;none&gt;           &lt;none&gt;
</code></pre>
<p>curl -v 10.244.1.2:8888    ===&gt; i am wondering why this failed ?</p>
<pre><code>*   Trying 10.244.1.2:8888...
* TCP_NODELAY set
* connect to 10.244.1.2 port 8888 failed: Connection refused
* Failed to connect to 10.244.1.2 port 8888: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.244.1.2 port 8888: Connection refused
</code></pre>
<p>curl -v 10.244.1.2     ===&gt; to my surprise this returned 200 success response</p>
<pre><code>* Trying 10.244.1.2:80...
* TCP_NODELAY set
* Connected to 10.244.1.2 (10.244.1.2) port 80 (#0)
&gt; GET / HTTP/1.1
&gt; Host: 10.244.1.2
&gt; User-Agent: curl/7.68.0
&gt; Accept: */*
&gt; 
* Mark bundle as not supporting multiuse
&lt; HTTP/1.1 200 OK
</code></pre>
<p>If the application is still referring default 80 port, I am wondering about the significance of container port 8888 ?
OK, so it may be used to expose the POD to the outside world.</p>
<p>Let's see that, I went ahead and created service for the POD:</p>
<pre><code>kubectl expose pod nginx --port=80 --target-port=8888
</code></pre>
<p>kubectl get svc</p>
<pre><code>NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
nginx        ClusterIP   10.96.214.161   &lt;none&gt;        80/TCP    13m
</code></pre>
<p>$ curl -v 10.96.214.161       ==&gt; here default port (80) didn't work</p>
<pre><code>*   Trying 10.96.214.161:80...
* TCP_NODELAY set
* connect to 10.96.214.161 port 80 failed: Connection refused
* Failed to connect to 10.96.214.161 port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.96.214.161 port 80: Connection refused
</code></pre>
<p>$ curl -v 10.96.214.161:8888    ==&gt; target port didn't work either</p>
<pre><code>*   Trying 10.96.214.161:8888...
* TCP_NODELAY set
....waiting forever
</code></pre>
<p>Which port do I need to use to make it work? Am I missing anything?</p>

Molay
<p>By default, <code>nginx</code> server listen to the port 80. You can see it in their docker image <a href="https://hub.docker.com/layers/nginx/library/nginx/1.18.0-alpine/images/sha256-d7038eae37cfa36cd8e286f6d6daf0df7a445a2da327517b3cde4ba1833adc0c?context=explore" rel="nofollow noreferrer">ref</a>.</p>
<p>With <code>kubectl run nginx --image=nginx --port=8888</code> what you have done here is you have expose another port along with 80. But the server is still listening on the <code>80</code> port.</p>
<p>So, try with target port <code>80</code>. For this reason when you tried with other than port <code>80</code> it's not working. Try with set <code>--target-port=8888</code> to <code>--target-port=80</code>.</p>
<p>Or, If you want to change the server port you need to use configmap along with pod to pass custom config to the server.</p>
