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: /
) is not working.
The reason for this is that my service is returning 400 on the root path (/
), because it expects to receive a request with a specific Host
header, like: Host: my-api.com
. How do I configure my ingress to add this header to the root healthcheck?
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.
Ingress:
---
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
Service:
---
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
Backend Config:
apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
metadata:
name: backend-web-backend-config
namespace: backend
spec:
timeoutSec: 120
Deployment:
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
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].
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.
[1] https://github.com/kubernetes/ingress-gce/issues/566#issuecomment-524312141
[2] https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers/