I am trying to prepare my application so that I can deploy it via kuberentes in the cloud. Therefore I installed minikube to get accostumed with how to set up an ingress. Therefore I followed the ingress documentation by kubernetes. (NOTE: I did not expose my frontend service like they do in the beginning of the tutorial, as I understood it’s not needed for an ingress).
But after hours of desperate debugging and no useful help by ChatGPT I am still not able to resolve my bug. Whenever I try to access my application via my costum host (example.com), I get InvalidHostHeader
as a response.
For simplicities sake right now my application simply has one deployment with one pod that runs a vuejs frontend. My frontend-deployment.yaml
looks like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
labels:
app: frontend
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: XXXXXXXXXXX
imagePullPolicy: Always
ports:
- name: http
containerPort: 8080
My frontend-service.yaml
:
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
ports:
- name: http
port: 8080
targetPort: http
selector:
app: frontend
type: ClusterIP
I use the default NGINX ingress controller of minikube. And my ingress.yaml
looks like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
name: http
Obviously, I configure my /etc/hosts
file to map my minikube ip address to example.com
Any help and also suggestions on best practices/improvements on the structure of the yaml files is welcome!
2
Answers
I fixed it. Interestingly, it was not about Kubernetes itself. The issue was the configuration of my ingress annotations (plus my vue.config file)
I got the needed annotations from here
For now, I fixed the issue of invalid host name on the vue side by simply allowing all hosts like this in the vue.config
this is obviosly only for local development!
An invalid host header error occurs may be of different reasons as mentioned below:
host name is correct using the kubectl describe command.
You can also refer to the blog by managedkube and another blog written by Avinash Thakur for further information.