<p>I have a python app</p>
<pre><code>from flask import Flask, jsonify

app = Flask(__name__)


@app.route(&quot;/&quot;)
def index():
    return jsonify({&quot;hey&quot;:&quot;test6&quot;})
</code></pre>
<p>And a deployment.yaml file</p>
<pre><code>    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mqttdemob
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: mqttdemob
      strategy: {}
      template:
        metadata:
          labels:
            app: mqttdemob
        spec:
          containers:
          - image: ****/fluxdemo:main-584db7b6-1687862454 # {&quot;$imagepolicy&quot;: &quot;flux-system:mqttdemob&quot;}
            name: app
            ports:
            - containerPort: 6000
</code></pre>
<p>And a service.yaml file</p>
<pre><code>    apiVersion: v1
    kind: Service
    metadata:
      name: mqttdemob
    spec:
      selector:
        app: mqttdemob
      ports:
        - protocol: TCP
          port: 6000
          targetPort: 6000
          nodePort: 30400
      externalIPs:
        - 1.2.4.122
      type: NodePort
</code></pre>
<p>When I deploy using these files I would want the Flask app to run on port 6000 which then would be forwarded to 30400.</p>
<p>But when I run</p>
<p><code>kubectl exec &lt;pod name&gt; -- netstat -tulpn</code></p>
<p>It outputs</p>
<pre><code> Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
 tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      1/python
</code></pre>
<p>Such that it is not using port 6000 but port 5000.</p>
<p>What am I doing wrong and how can I make sure that Flask will use port 6000 instead of 5000?</p>

Kspr
<p><code>containerPort</code> is only informational and doesn't configure the port your app is running on.</p>
<p>You flask application is using its default port.
Try changing it in you main file where you are starting your server using:</p>
<pre class="lang-py prettyprint-override"><code>port = 6000 #you can change it to any unused port.
if __name__ == '__main__':
    app.run(host='0.0.0.0', port)
</code></pre>
<ul>
<li>unused in the above case means the port which is currently not in use.</li>
</ul>
