AKS load balancer service accessible on wrong port

Viewed 128

I have a simple ASP.NET core Web API. It works locally. I deployed it in Azure AKS using the following yaml:

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: "64Mi"
            cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
  name: sa-be-s
spec:
  type: LoadBalancer
  selector:
    name: sa-be
  ports:
  - port: 8080
    targetPort: 80

The result is:

> 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



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

I expected to reach the Web API at http://20.53.188.247:32533/, instead it is reachable only at http://20.53.188.247:8080/

Can someone explain

  • Is this is he expected behaviour
  • If yes, what is the use of the NodePort (32533)?
1 Answers

Yes, expected. Explained: Kubernetes Service Ports - please read full article to understand what is going on in the background.

Loadbalancer part:

apiVersion: v1
kind: Service
metadata:
  name: sa-be-s
spec:
  type: LoadBalancer
  selector:
    name: sa-be
  ports:
  - port: 8080
    targetPort: 80

port is the port the cloud load balancer will listen on (8080 in our example) and targetPort 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.

now main: Behind the scenes, many implementations create NodePorts to glue the cloud load balancer to the cluster. The traffic flow is usually like this.

enter image description here

Related