<p>i'm working on a new idea for which I've created a setup as follows on Azure Kubernetes:</p>
<ol>
<li>1 cluster</li>
<li>1 node pool in said cluster</li>
<li>1 deployment which creates 2 pods in the pool</li>
<li>1 load balancer service balancing requests between the 2 pods</li>
</ol>
<p>I'm trying to submit a json request into the loadbalancer from outside the cluster with an AKS IP, to which i encounter 502 Bad Gateway issues.</p>
<p>This is my deployment file</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-1
spec:
  selector:
    matchLabels:
      app: deployment-1
  replicas: 2
  template:
    metadata:
      labels:
        app: deployment-1
    spec:
      containers:
      - name: api-1
        image: dummy
        imagePullPolicy: Always
        ports:
          - containerPort: 5000
      nodeSelector:
        agentpool: analytics1

---
apiVersion: v1
kind: Service
metadata:
  name: service-1
  annotations:
    service.beta.kubernetes.io/azure-dns-label-name: dummy
    service.beta.kubernetes.io/azure-load-balancer-internal: &quot;true&quot;
spec:
  type: LoadBalancer
  ports:
  - port: 5000
  selector:
    app: deployment-1
</code></pre>
<p>Checking if services are running.</p>
<pre><code>LAMU02Y36ZHJG5J% kubectl get svc
NAME                TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
cloud-api-v4-svc    LoadBalancer   10.0.63.65    10.240.0.5    80:30054/TCP     37d
kubernetes          ClusterIP      10.0.0.1      &lt;none&gt;        443/TCP          47d
service-1           LoadBalancer   10.0.55.129   10.240.0.9    5000:30507/TCP   41h
</code></pre>
<p>i use this LoadBalancer IP (10.240.0.9) to create an ingress service as below.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-1
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
spec:
  rules:
    - host: service-1.a3333fc09cb44a6b86b8.eastus.aksapp.io
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: service-1
              port:
                number: 5000
</code></pre>
<p>And this is after ingress is created.</p>
<pre><code>LAMU02Y36ZHJG5J% kubectl get ingress
NAME         CLASS    HOSTS                                               ADDRESS      PORTS   AGE
ingress-1   &lt;none&gt;   service-1.a333fc09cb44a6b86b8.eastus.aksapp.io   20.84.1.20   80      65m
</code></pre>
<p>So i think things are good, and then i go ahead to create my AKS application gateway so it's accessible from any IP. what i specified for the AKS App gateway.
backend pool IP - 20.84.1.20  with port 80 ( which is the Ingress IP. i'm not sure if this is where i'm going wrong)</p>
<p>After configuring, now when i try to access the App gateway IP as is, i get a 502 Bad Gateway error. I'm very new to AKS</p>

<p>I don't see below annotations in your Ingress..</p>
<p>Can you add them and try?</p>
<pre><code>appgw.ingress.kubernetes.io/use-private-ip: &quot;false&quot; 
kubernetes.io/ingress.class: azure/application-gateway
</code></pre>
<p>This is where you can see more details in <a href="https://learn.microsoft.com/en-us/azure/application-gateway/ingress-controller-troubleshoot" rel="nofollow noreferrer">Troubleshoot common questions or issues with Ingress Controller</a>.</p>
