Not able to access the application using Load Balancer service in Azure Kubernetes Service

9/8/2020

I have created small nginx deployment and type as LoadBalancer in Azure Kubernetes service, but I was unable to access the application using LoadBalaner service. Can some one provide the solution

I have already updated security group to allow all traffic, but no use.

Do I need to update any security group to access the application?

Please find the deployment file.

cat nginx.yml

apiVersion: v1

kind: Service

metadata:

  name: nginx-kubernetes

spec:

  type: LoadBalancer

  ports:

  - port: 8080

    targetPort: 8080

  selector:

    app: hello-kubernetes

---
apiVersion: apps/v1

kind: Deployment

metadata:

     name: nginx-kubernetes

spec:

  replicas: 3

  selector:

    matchLabels:

      app: hello-kubernetes

  template:

    metadata:

      labels:

        app: hello-kubernetes

    spec:

      containers:

      - name: hello-kubernetes

        image: nginx:latest

        ports:

        - containerPort: 8080
-- kaka
azure-aks
azure-load-balancer
kubernetes

1 Answer

9/8/2020

Nginx container is using port 80 by default and you are trying to connect to port 8080 where nothing is listening and thus getting connection refused.

Take a look here at nginx conateiner Dockerfile. What port do you see?

All you need to do to make it work is to change target port like following:

apiVersion: v1
kind: Service
metadata:
  name: nginx-kubernetes
spec:
  ports:
  - port: 8080
    targetPort: 80 
  selector:
    app: hello-kubernetes

Additionally it would be nice to change containerPort as following:

spec:
  containers:
  - name: hello-kubernetes
    image: nginx:latest
    ports:
    - containerPort: 80
-- Matt
Source: StackOverflow