简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM