<p>I have a simple ASP.NET core Web API. It works locally. I deployed it in Azure AKS using the following yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: sa-be
spec:
  selector:
    matchLabels:
      name: sa-be
  template:
    metadata:
      labels:
        name: sa-be
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers:
      - name: sa-be
        image: francotiveron/anapi:latest
        resources:
          limits:
            memory: &quot;64Mi&quot;
            cpu: &quot;250m&quot;
---
apiVersion: v1
kind: Service
metadata:
  name: sa-be-s
spec:
  type: LoadBalancer
  selector:
    name: sa-be
  ports:
  - port: 8080
    targetPort: 80

</code></pre>
<p>The result is:</p>
<pre><code>&gt; kubectl get service sa-be-s
NAME      TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
sa-be-s   LoadBalancer   10.0.157.200   20.53.188.247   8080:32533/TCP   4h55m



&gt; kubectl describe service sa-be-s 
Name:                     sa-be-s
Namespace:                default
Labels:                   &lt;none&gt;
Annotations:              &lt;none&gt;
Selector:                 name=sa-be
Type:                     LoadBalancer
IP Families:              &lt;none&gt;
IP:                       10.0.157.200
IPs:                      &lt;none&gt;
LoadBalancer Ingress:     20.53.188.247
Port:                     &lt;unset&gt;  8080/TCP
TargetPort:               80/TCP
NodePort:                 &lt;unset&gt;  32533/TCP
Endpoints:                10.244.2.5:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;

</code></pre>
<p>I expected to reach the Web API at <a href="http://20.53.188.247:32533/" rel="nofollow noreferrer">http://20.53.188.247:32533/</a>, instead it is reachable only at <a href="http://20.53.188.247:8080/" rel="nofollow noreferrer">http://20.53.188.247:8080/</a></p>
<p>Can someone explain</p>
<ul>
<li>Is this is he expected behaviour</li>
<li>If yes, what is the use of the NodePort (32533)?</li>
</ul>

Franco Tiveron
<p>Yes, expected.
<a href="https://nigelpoulton.com/explained-kubernetes-service-ports/" rel="nofollow noreferrer">Explained: Kubernetes Service Ports</a> - please read full article to understand what is going on in the background.</p>
<p>Loadbalancer part:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: sa-be-s
spec:
  type: LoadBalancer
  selector:
    name: sa-be
  ports:
  - port: 8080
    targetPort: 80
</code></pre>
<blockquote>
<p><strong>port</strong> is the port the cloud load balancer will listen on (8080 in our
example) and <strong>targetPort</strong> is the port the application is listening on in
the Pods/containers. Kubernetes works with your cloud’s APIs to create
a load balancer and everything needed to get traffic hitting the load
balancer on port 8080 all the way back to the Pods/containers in your
cluster listening on targetPort 80.</p>
</blockquote>
<p>now main:
<strong>Behind the scenes, many implementations create NodePorts to glue the cloud load balancer to the cluster</strong>. The traffic flow is usually like this.</p>
<p><a href="https://i.stack.imgur.com/FW9tw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FW9tw.png" alt="enter image description here" /></a></p>
