<h1>What I wanna accomplish</h1>
<p>I'm trying to connect an external HTTPS (L7) load balancer with an NGINX Ingress exposed as a zonal Network Endpoint Group (NEG). My Kubernetes cluster (in GKE) contains a couple of web application deployments that I've exposed as a ClusterIP service.</p>
<p>I know that the NGINX Ingress object can be directly exposed as a TCP load balancer. But, this is not what I want. Instead in my architecture, I want to load balance the HTTPS requests with an external HTTPS load balancer. I want this external load balancer to provide SSL/TLS termination and forward HTTP requests to my Ingress resource.</p>
<p>The ideal architecture would look like this:</p>
<p>HTTPS requests --&gt; external HTTPS load balancer --&gt; HTTP request --&gt; NGINX Ingress zonal NEG --&gt; appropriate web application</p>
<p>I'd like to add the zonal NEGs from the NGINX Ingress as the backends for the HTTPS load balancer. This is where things fall apart.</p>
<h1>What I've done</h1>
<p><strong>NGINX Ingress config</strong></p>
<p>I'm using the default NGINX Ingress config from the official kubernetes/ingress-nginx project. Specifically, this YAML file <a href="https://github.com/kubernetes/ingress-nginx/blob/master/deploy/static/provider/cloud/deploy.yaml" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/blob/master/deploy/static/provider/cloud/deploy.yaml</a>.
Note that, I've changed the NGINX-controller Service section as follows:</p>
<ul>
<li><p>Added NEG annotation</p>
</li>
<li><p>Changed the Service type from <code>LoadBalancer</code> to <code>ClusterIP</code>.</p>
</li>
</ul>
<pre><code># Source: ingress-nginx/templates/controller-service.yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
    # added NEG annotation
    cloud.google.com/neg: '{&quot;exposed_ports&quot;: {&quot;80&quot;:{&quot;name&quot;: &quot;NGINX_NEG&quot;}}}'
  labels:
    helm.sh/chart: ingress-nginx-3.30.0
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.46.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: http
    - name: https
      port: 443
      protocol: TCP
      targetPort: https
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/component: controller
---
</code></pre>
<p><strong>NGINX Ingress routing</strong></p>
<p>I've tested the path based routing rules for the NGINX Ingress to my web applications independently. This works when the NGINX Ingress is configured with a TCP Load Balancer. I've set up my application Deployment and Service configs the usual way.</p>
<p><strong>External HTTPS Load Balancer</strong></p>
<p>I created an external HTTPS load balancer with the following settings:</p>
<ul>
<li>Backend: added the zonal NEGs named <code>NGINX_NEG</code> as the backends. The backend is configured to accept HTTP requests on port 80. I configured the health check on the serving port via the TCP protocol. I added the firewall rules to allow incoming traffic from <code>130.211.0.0/22</code> and <code>35.191.0.0/16</code> as mentioned here <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/standalone-neg#traffic_does_not_reach_the_endpoints" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/how-to/standalone-neg#traffic_does_not_reach_the_endpoints</a></li>
</ul>
<h1>What's not working</h1>
<p>Soon after the external load balancer is set up, I can see that GCP creates a new endpoint under one of the zonal NEGs. But this shows as &quot;Unhealthy&quot;. Requests to the external HTTPS load balancer return a 502 error.</p>
<ul>
<li><p>I'm not sure where to start debugging this configuration in GCP logging. I've enabled logging for the health check but nothing shows up in the logs.</p>
</li>
<li><p>I configured the health check on the <code>/healthz</code> path of the NGINX Ingress controller. That didn't seem to work either.</p>
</li>
</ul>
<p>Any tips on how to get this to work will be much appreciated. Thanks!</p>
<p>Edit 1: As requested, I ran the <code>kubectl get svcneg -o yaml --namespace=&lt;namespace&gt;</code>, here's the output</p>
<pre><code>apiVersion: networking.gke.io/v1beta1
kind: ServiceNetworkEndpointGroup
metadata:
  creationTimestamp: &quot;2021-05-07T19:04:01Z&quot;
  finalizers:
  - networking.gke.io/neg-finalizer
  generation: 418
  labels:
    networking.gke.io/managed-by: neg-controller
    networking.gke.io/service-name: ingress-nginx-controller
    networking.gke.io/service-port: &quot;80&quot;
  name: NGINX_NEG
  namespace: ingress-nginx
  ownerReferences:
  - apiVersion: v1
    blockOwnerDeletion: false
    controller: true
    kind: Service
    name: ingress-nginx-controller
    uid: &lt;unique ID&gt;
  resourceVersion: &quot;2922506&quot;
  selfLink: /apis/networking.gke.io/v1beta1/namespaces/ingress-nginx/servicenetworkendpointgroups/NGINX_NEG
  uid: &lt;unique ID&gt;
spec: {}
status:
  conditions:
  - lastTransitionTime: &quot;2021-05-07T19:04:08Z&quot;
    message: &quot;&quot;
    reason: NegInitializationSuccessful
    status: &quot;True&quot;
    type: Initialized
  - lastTransitionTime: &quot;2021-05-07T19:04:10Z&quot;
    message: &quot;&quot;
    reason: NegSyncSuccessful
    status: &quot;True&quot;
    type: Synced
  lastSyncTime: &quot;2021-05-10T15:02:06Z&quot;
  networkEndpointGroups:
  - id: &lt;id1&gt;
    networkEndpointType: GCE_VM_IP_PORT
    selfLink: https://www.googleapis.com/compute/v1/projects/&lt;project&gt;/zones/us-central1-a/networkEndpointGroups/NGINX_NEG
  - id: &lt;id2&gt;
    networkEndpointType: GCE_VM_IP_PORT
    selfLink: https://www.googleapis.com/compute/v1/projects/&lt;project&gt;/zones/us-central1-b/networkEndpointGroups/NGINX_NEG
  - id: &lt;id3&gt;
    networkEndpointType: GCE_VM_IP_PORT
    selfLink: https://www.googleapis.com/compute/v1/projects/&lt;project&gt;/zones/us-central1-f/networkEndpointGroups/NGINX_NEG
</code></pre>

zerodark
<p>As per my understanding, your issue is - “when an external load balancer is set up,  GCP creates a new endpoint under one of the zonal NEGs and it shows &quot;Unhealthy&quot; and requests to the external HTTPS load balancer which return a 502 error”.</p>
<p>Essentially, the Service's annotation, cloud.google.com/neg: '{&quot;ingress&quot;: true}', enables container-native load balancing. After creating the Ingress, an HTTP(S) load balancer is created in the project, and NEGs are created in each zone in which the cluster runs. The endpoints in the NEG and the endpoints of the Service are kept in sync.
Refer to the link [1].</p>
<p>New endpoints generally become reachable after attaching them to the load balancer, provided that they respond to health checks. You might encounter 502 errors or rejected connections if traffic cannot reach the endpoints.</p>
<p>One of your endpoints in zonal NEG is showing unhealthy so please confirm the status of other endpoints and how many endpoints are spread across the zones in the backend.
If all backends are unhealthy, then your firewall, Ingress, or service might be misconfigured.</p>
<p>You can run following command to check if your endpoints are healthy or not  and refer link [2] for the same -
gcloud compute network-endpoint-groups list-network-endpoints NAME \ --zone=ZONE</p>
<p>To troubleshoot traffic that is not reaching the endpoints, verify that health check firewall rules allow incoming TCP traffic to your endpoints in the 130.211.0.0/22 and 35.191.0.0/16 ranges. But as you mentioned you have configured this rule correctly. Please refer link [3] for health check Configuration.</p>
<p>Run the Curl command against your LB IP to check for responses -<br />
Curl [LB IP]</p>
<p>[1] <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress-xlb" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/concepts/ingress-xlb</a></p>
<p>[2] <a href="https://cloud.google.com/load-balancing/docs/negs/zonal-neg-concepts#troubleshooting" rel="nofollow noreferrer">https://cloud.google.com/load-balancing/docs/negs/zonal-neg-concepts#troubleshooting</a></p>
<p>[3] <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#health_checks" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#health_checks</a></p>
