<p>I am learning how to use an ingress to expose my application GKE v1.19.
I followed the tutorial on GKE docs for Service, Ingress, and BackendConfig to get to the following setup. However, my backend services still become UNHEALTHY after some time. My aim is to overwrite the default &quot;/&quot; health check path for the ingress controller.</p>
<p>I have the same health checks defined in my deployment.yaml file under livenessProbe and readinessProbe and they seem to work fine since the Pod enters running stage. I have also tried to curl the endpoint and it returns a 200 status.</p>
<p>I have no clue why are my service is marked as unhealthy despite them being accessible from the NodePort service I defined directly. Any advice or help would be appreciated. Thank you.</p>
<p>I will add my yaml files below:</p>
<p><strong>deployment.yaml</strong></p>
<pre><code>....
      livenessProbe:
          httpGet:
            path: /api
            port: 3100
          initialDelaySeconds: 180
      readinessProbe:
          httpGet:
            path: /api
            port: 3100
          initialDelaySeconds: 180
.....

</code></pre>
<p><strong>backendconfig.yaml</strong></p>
<pre><code>apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
metadata:
  name: backend-config
  namespace: ns1
spec:
  healthCheck:
    checkIntervalSec: 30
    port: 3100
    type: HTTP #case-sensitive
    requestPath: /api
</code></pre>
<p><strong>service.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  annotations:
    cloud.google.com/backend-config: '{&quot;default&quot;: &quot;backend-config&quot;}'
  name: service-ns1
  namespace: ns1
  labels:
    app: service-ns1
spec:
  type: NodePort
  ports:
  - protocol: TCP
    port: 3100
    targetPort: 3100
  selector:
    app: service-ns1
</code></pre>
<p><strong>ingress.yaml</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ns1-ingress
  namespace: ns1
  annotations:
    kubernetes.io/ingress.global-static-ip-name: ns1-ip
    networking.gke.io/managed-certificates: ns1-cert
    kubernetes.io/ingress.allow-http: &quot;false&quot; 
spec:
  rules:
  - http:
      paths:
      - path: /api/*
        backend:
          serviceName: service-ns1
          servicePort: 3100

</code></pre>

user782400
<p>The ideal way to use the ‘BackendConfig’ is when the serving pods for your service contains multiple containers, if you're using the Anthos Ingress controller or if you need control over the port used for the load balancer's health checks, then you should use a BackendConfig CDR to define <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#health_checks" rel="nofollow noreferrer">health check</a> parameters. Refer to the <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#health_checks" rel="nofollow noreferrer">1</a>.</p>
<p>When a backend service's health check parameters are inferred from a serving Pod's readiness probe, GKE does not keep the readiness probe and health check synchronized. Hence any changes you make to the <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#interpreted_hc" rel="nofollow noreferrer">readiness probe</a> will not be copied to the health check of the corresponding backend service on the load balancer as per <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#interpreted_hc" rel="nofollow noreferrer">2</a>.</p>
<p>In your scenario, the backend is healthy when it follows path  ‘/’ but showing unhealthy when it uses path ‘/api’, so there might be some misconfiguration in your ingress.</p>
<p>I would suggest you to add the annotations: ingress.kubernetes.io/rewrite-target: /api
so the path mentioned in spec.path will be rewritten to /api before the request is sent to the backend service.</p>
