<p>i am trying deploy a simple python flask application in digital ocean Kubernetes cluster using below deployment and service configuration. flask app is using 8080 port while running the code and same is used to expose through load balancer.</p>
<p>flask app</p>
<pre><code>    if __name__ == '__main__':
        app.run(debug=True, host='0.0.0.0', port=8080)
</code></pre>
<p>deployment</p>
<pre><code>    ubuntu@ubuntu-22lts:~$ cat deployment.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: unit7-app-deploy
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: unit-app
      template:
        metadata:
          labels:
            app: unit-app
        spec:
          containers:
          - name: unit-app
            image: &lt;username&gt;/flask-app:latest
            imagePullPolicy: IfNotPresent
            resources:
              limits:
                memory: &quot;128Mi&quot;
                cpu: &quot;500m&quot;
            ports:
            - containerPort: 8080
</code></pre>
<p>and service for load balance creation</p>
<pre><code>    apiVersion: v1
    kind: Service
    metadata:
      name: unit7-app-service
    spec:
      selector:
        app: unit7-app-deploy
      ports:
      - port: 8080
        targetPort: 8080
        protocol: TCP
      type: LoadBalancer
</code></pre>
<p>Now I am trying to access my app through Kubernetes external IP and 8080 port which is not working. pods logs are showing that my flaks is running.</p>
<pre><code>    ubuntu@ubuntu-22lts:~$ kubectl --kubeconfig=k8s-1-27-2-do-0-blr1-cluster1-kubeconfig.yaml logs -f unit7-app-deploy-6568dss8-ddsds
     * Serving Flask app 'run'
     * Debug mode: on
    WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
     * Running on all addresses (0.0.0.0)
     * Running on http://127.0.0.1:8080
     * Running on http://10.244.0.214:8080
</code></pre>
<p>where am I wrong. Kindly help me.</p>

Maria628
<p>Just in case this is part of your issue, your Service's selector does not match your Deployment's label.<br />
The selector in your service should match the labels in your deployment to establish the correct connection.</p>
<p>In your Deployment:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: unit7-app-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: unit-app
</code></pre>
<p>The label for the pods being deployed is <code>app: unit-app</code>.</p>
<p>But in your Service:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: unit7-app-service
spec:
  selector:
    app: unit7-app-deploy
</code></pre>
<p>Here, the service selector is looking for pods with label <code>app: unit7-app-deploy</code>.</p>
<p>The selector in the service configuration should match the label you defined in your Deployment configuration for the pods, which is <code>app: unit-app</code>.<br />
For instance, service configuration should look like:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: unit7-app-service
spec:
  selector:
    app: unit-app # Change from 'unit7-app-deploy' to 'unit-app'
  ports:
  - port: 8080
    targetPort: 8080
    protocol: TCP
  type: LoadBalancer
</code></pre>
<p>That mismatch is likely the reason your load balancer is not working correctly, as it is not able to find the correct pods to send traffic to.</p>
