Home > Blockchain >  Azure AKS Application Gateway 502 bad gateway
Azure AKS Application Gateway 502 bad gateway

Time:08-12

I have been following the tutorial here: All the instances in one or more of your backend pools are unhealthy

Since this appeared to indicate that the backend pools are unreachable, it was strange at first so I tried to look at the logs of one of the pods based on the hello-app images you were using and noticed this right away:

> kubectl logs one-api-77f9b4b9f-6sv6f
2022/08/12 00:22:04 Server listening on port 8080

Hence, my immediate thought was that maybe in the Docker image that you are using, nothing is configured to listen on port 80, which is the port you are using in your kubernetes resources definition.

After updating your Deployment and Service definitions to use port 8080 instead of 80, everything worked perfectly fine and I started getting the following response in my browser:

Hello, world!
Version: 1.0.0
Hostname: one-api-d486fbfd7-pm8kt

Below you can find the updated YAML file that I used to successfully deploy all the resources:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: one-api
  namespace: default
  annotations:
    imageregistry: "gcr.io/google-samples/hello-app:1.0"
spec:
  replicas: 3
  selector:
    matchLabels:
      run: one-api
  template:
    metadata:
      labels:
        run: one-api
    spec:
      containers:
        - image: gcr.io/google-samples/hello-app:1.0
          imagePullPolicy: IfNotPresent
          name: one-api
          ports:
            - containerPort: 8080
              protocol: TCP

---
apiVersion: v1
kind: Service
metadata:
  name: one-api
  namespace: default
spec:
  ports:
    - port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    run: one-api
  type: NodePort

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: two-api
  namespace: default
  annotations:
    imageregistry: "gcr.io/google-samples/hello-app:1.0"
spec:
  replicas: 3
  selector:
    matchLabels:
      run: two-api
  template:
    metadata:
      labels:
        run: two-api
    spec:
      containers:
        - image: gcr.io/google-samples/hello-app:1.0
          imagePullPolicy: IfNotPresent
          name: two-api
          ports:
            - containerPort: 8080
              protocol: TCP

---
apiVersion: v1
kind: Service
metadata:
  name: two-api
  namespace: default
spec:
  ports:
    - port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    run: two-api
  type: NodePort

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: strata-2022
  labels:
    app: my-docker-apps
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: one-api
                port:
                  number: 8080
          - path: /two-api
            pathType: Prefix
            backend:
              service:
                name: two-api
                port:
                  number: 8080
  • Related