<p>I am running Kubernetes in GKE and I created a default ingress for one of my services, however I am unable to access my service, because ingress default healthcheck (the one that expects to receive a 200 return code when it queries the root path: <code>/</code>) is not working.</p>

<p>The reason for this is that my service is returning 400 on the root path (<code>/</code>), because it expects to receive a request with a specific <code>Host</code> header, like: <code>Host: my-api.com</code>. How do I configure my ingress to add this header to the root healthcheck?</p>

<p>Note: I managed to configure this in the GCP console, but I would like to know how can I configure this on my yaml, so that I won't have to remember to do this if I have to recreate my ingress.</p>

<p>Ingress:</p>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  namespace: backend
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "backend"
    networking.gke.io/managed-certificates: "api-certificate"
spec:
  rules:
  - host: my-api.com
    http:
      paths:
      - path: /*
        backend:
          serviceName: backend-service
          servicePort: http

</code></pre>

<p>Service:</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: backend-service
  namespace: backend
  annotations:
    beta.cloud.google.com/backend-config: '{"ports": {"80":"backend-web-backend-config"}}'
spec:
  selector:
    app: backend-web
  ports:
  - name: http
    targetPort: 8000
    port: 80
  type: NodePort
</code></pre>

<p>Backend Config:</p>

<pre><code>apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
metadata:
  name: backend-web-backend-config
  namespace: backend
spec:
  timeoutSec: 120
</code></pre>

<p>Deployment:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: backend-web
  namespace: backend
  labels:
    app: backend-web
spec:
  selector:
    matchLabels:
      app: backend-web
  template:
    metadata:
      labels:
        app: backend-web
    spec:
      containers:
      - name: web
        image: backend:{{VERSION}}
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 8000
            protocol: TCP
        command: ["run"]
        resources:
          requests:
            memory: "800Mi"
            cpu: 150m
          limits:
            memory: "2Gi"
            cpu: 1
        livenessProbe:
          httpGet:
            httpHeaders:
              - name: Accept
                value: application/json
            path: "/healthcheck"
            port: 8000
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 30
        readinessProbe:
          httpGet:
            httpHeaders:
              - name: Accept
                value: application/json
            path: "/healthcheck"
            port: 8000
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 30

</code></pre>

<p>You are using a GCE Ingress, there is no way yet to have such configuration using a GCE Ingress. 
I have seen that Google will release a new feature "user defined request headers" for GKE, which will allow you to specify additional headers that the load balancer adds to requests. This new feature will solve your problem, but we will have to wait until Google release it, and as per what I can see it will be on 1.7 version [1].</p>

<p>With this being said, there is one alternative left, use NGINX Ingress Controller  instead of GCE Ingress. NGINX support headers changes[2], but this means that you will have to re-deploy your Ingress. </p>

<p>[1] <a href="https://github.com/kubernetes/ingress-gce/issues/566#issuecomment-524312141" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-gce/issues/566#issuecomment-524312141</a></p>

<p>[2] <a href="https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers/</a></p>
