<p>I've been trying to use the below to expose my application to a public IP. This is being done on Azure. The public IP is generated but when I browse to it I get nothing. </p>

<p>This is a Django app which runs the container on Port 8000. The service runs at Port 80 at the moment but even if I configure the service to run at port 8000 it still doesn't work.</p>

<p>Is there something wrong with the way my service is defined?</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    app: hmweb
spec:
  ports:
    - port: 80
  selector:
    app: hmweb
    tier: frontend
  type: LoadBalancer

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hmweb-deployment
  labels:
    app: hmweb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hmweb
  template:
    metadata:
      labels:
        app: hmweb
    spec:
      containers:
      - name: hmweb
        image: nw_webimage
        envFrom:
          - configMapRef:
              name: new-config
        command: ["/bin/sh","-c"]
        args: ["gunicorn saleor.wsgi -w 2 -b 0.0.0.0:8000"]
        ports:
        - containerPort: 8000
      imagePullSecrets:
      - name: key
</code></pre>

<p>Output of kubectl describe service web (name of service:)</p>

<pre><code>Name:                     web
Namespace:                default
Labels:                   app=hmweb
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"hmweb"},"name":"web","namespace":"default"},"spec":{"ports":[{"port":...
Selector:                 app=hmweb
Type:                     LoadBalancer
IP:                       10.0.86.131
LoadBalancer Ingress:     13.69.127.16
Port:                     &lt;unset&gt;  80/TCP
TargetPort:               8000/TCP
NodePort:                 &lt;unset&gt;  31827/TCP
Endpoints:                10.244.0.112:8000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  EnsuringLoadBalancer  8m    service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   7m    service-controller  Ensured load balancer
</code></pre>

<p>The reason behind that is your service has two selector <code>app: hmweb</code> and <code>tier: frontend</code> and your deployment pods has only single label named <code>app: hmweb</code>. Hence when your service is created it could not find the pods which has both the labels and doesn't connect to any pods. Also, if you have container running on <code>8000</code> port then you must define <code>targetPort</code> which has the value of container port on which container is running, else it will take both <code>targetPort</code> and <code>port</code> value as same you defined in your service i.e. <code>port: 80</code></p>

<p>The correct yaml for your deployment is:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    app: hmweb
spec:
  ports:
    - port: 80
      targetPort: 8000
      protocol: TCP
  selector:
    app: hmweb
  type: LoadBalancer
</code></pre>

<p>Hope this helps.</p>
