<p>I have been following the tutorial here:
<a href="https://learn.microsoft.com/en-us/azure/application-gateway/tutorial-ingress-controller-add-on-new#code-try-4" rel="nofollow noreferrer">MS Azure</a></p>
<p>This is fine. However deploying a local config file I get a &quot;502 Gate Way&quot; error. This config has been fine and works as expected.</p>
<p>Can anyone see anything obvious with this: At this point I don't know where to start.</p>
<p>I am trying to achieve using the ingress controller that is Application gateway. Then add deployments and apply additional ingress rules</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: one-api
  namespace: default
  annotations:
    imageregistry: &quot;gcr.io/google-samples/hello-app:1.0&quot;
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: 80
              protocol: TCP

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

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: two-api
  namespace: default
  annotations:
    imageregistry: &quot;gcr.io/google-samples/hello-app:1.0&quot;
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: 80
              protocol: TCP

---
apiVersion: v1
kind: Service
metadata:
  name: two-api
  namespace: default
spec:
  ports:
    - port: 80
      protocol: TCP
      targetPort: 80
  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: 80
          - path: /two-api
            pathType: Prefix
            backend:
              service:
                name: two-api
                port:
                  number: 80
</code></pre>
<p>Output of: <code>kubectl describe ingress strata-2022</code></p>
<pre><code>Name:             strata-2022
</code></pre>
<p>Labels:           app=my-docker-apps
Namespace:        default
Address:          51.142.191.83
Ingress Class:    
Default backend:  
Rules:
Host        Path  Backends</p>
<hr />
<ul>
<li>
<pre><code>      /          one-api:80 (10.224.0.15:80,10.224.0.59:80,10.224.0.94:80)
      /two-api   two-api:80 (10.224.0.13:80,10.224.0.51:80,10.224.0.82:80)
</code></pre>
</li>
</ul>
<p>Annotations:  kubernetes.io/ingress.class: azure/application-gateway
Events:       </p>
<p><code>kubectl describe ingress</code></p>
<pre><code>Name:             strata-2022
Labels:           app=my-docker-apps
Namespace:        default
Address:          51.142.191.83
Ingress Class:    &lt;none&gt;
Default backend:  &lt;default&gt;
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /          one-api:80 (10.224.0.15:80,10.224.0.59:80,10.224.0.94:80)
              /two-api   two-api:80 (10.224.0.13:80,10.224.0.51:80,10.224.0.82:80)
Annotations:  kubernetes.io/ingress.class: azure/application-gateway
Events:       &lt;none&gt;
</code></pre>
<p>Commands used to create AKS using Azure CLI.</p>
<p><code>az aks create -n myCluster -g david-tutorial --network-plugin azure --enable-managed-identity -a ingress-appgw --appgw-name testApplicationGateway --appgw-subnet-cidr &quot;10.225.0.0/16&quot; --generate-ssh-keys</code></p>
<p>// Get credentials and switch to this context</p>
<p><code>az aks get-credentials -n myCluster -g david-tutorial</code></p>
<p>// This line is from the tutorial -- this works as expected</p>
<p>//kubectl apply -f <a href="https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/aspnetapp.yaml" rel="nofollow noreferrer">https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/aspnetapp.yaml</a></p>
<p>// This is what i ran. It works locally</p>
<p><code>kubectl apply -f nano new-deploy.yaml</code></p>
<p>// Get address</p>
<p><code>kubectl get ingress</code></p>
<p><code>kubectl get configmap</code></p>

user3067684
<p>I tried recreating the same setup on my end, and I could identify the following issue right after running the same <code>az aks</code> create command: All the instances in one or more of your backend pools are unhealthy.
<a href="https://i.stack.imgur.com/ZOAsO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZOAsO.png" alt="All the instances in one or more of your backend pools are unhealthy" /></a></p>
<p>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:</p>
<pre><code>&gt; kubectl logs one-api-77f9b4b9f-6sv6f
2022/08/12 00:22:04 Server listening on port 8080
</code></pre>
<p>Hence, my immediate thought was that maybe in the Docker image that you are using, nothing is configured to listen on port <code>80</code>, which is the port you are using in your kubernetes resources definition.</p>
<p>After updating your Deployment and Service definitions to use port <code>8080</code> instead of <code>80</code>, everything worked perfectly fine and I started getting the following response in my browser:</p>
<pre><code>Hello, world!
Version: 1.0.0
Hostname: one-api-d486fbfd7-pm8kt
</code></pre>
<p>Below you can find the updated YAML file that I used to successfully deploy all the resources:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: one-api
  namespace: default
  annotations:
    imageregistry: &quot;gcr.io/google-samples/hello-app:1.0&quot;
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: &quot;gcr.io/google-samples/hello-app:1.0&quot;
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
</code></pre>
