I am new in Kubernetes.
I had a working setup of separate servers for frontend and backend, all before Kubernetes.
A frontend webserver which served a static build of a React App, and a backend server which had docker containers for PHP APIs.
The URL of the backend server was for example my-backend-docker-server.foo
The backend server exposed a PHP API container, where the PHP port 9000 was exposed to 8087.
The frontend server used the PHP from that backend server like:
location ~ \.php {
# ...
fastcgi_pass my-backend-docker-server.foo:8087;
}
So this all worked.
Now I want to move all docker containers to a Kubernetes cluster.
I was able to do a Pod -> Service -> Ingress setup, I was able to have a new URL like php-api-on-kubernetes.foo, and when I call the URL in the browser, the output of the index.php from the PHP container shows up.
The Idea is now, that I just change the fastcgi_pass in the nginx configuration of the frontend webserver like:
location ~ \.php {
# ...
# fastcgi_pass my-backend-docker-server.foo:8087;
fastcgi_pass php-api-on-kubernetes.foo:80;
}
But the frontend call receives a 502 (Bad Gateway) error, and the nginx log on the frontend server logs:
upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream
I tried 2 variants of ingress
First, which I am able to see the output of the PHP container over the new URL.
# see https://kubernetes.github.io/ingress-nginx/user-guide/fcgi-services/
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}
data:
SCRIPT_FILENAME: "/home/api/public/index.php"
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Release.Name }}
annotations:
nginx.ingress.kubernetes.io/backend-protocol: "FCGI"
nginx.ingress.kubernetes.io/fastcgi-index: "index.php"
nginx.ingress.kubernetes.io/fastcgi-params-configmap: {{ .Release.Name }}
spec:
ingressClassName: nginx
rules:
- host: {{ .Values.host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ .Release.Name }}
port:
name: fastcgi
Since it logged that nginx error, I compared it more with the old backend server. I saw that the content of the PHP container was not accessible from a browser. Because there is also no webserver serving the content. So I tried to match, and did another ingress without nginx.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Release.Name }}
spec:
rules:
- host: {{ .Values.host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ .Release.Name }}
port:
name: fastcgi
This is the Service by the way
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}
spec:
selector:
app: {{ .Release.Name }}
ports:
- port: 9000
targetPort: 9000
name: fastcgi
Now when calling the new backend URL, I receive 502 Bad Gateway nginx output.
When I call the old backend URL, I receive ERR_CONNECTION_RESET (It should have always been like this, but without any problems).
So there is still a difference. Maybe it has something to do with a magic global ingress controller? As I said, I am still new into Kubernetes.
But still, I dont know how to fix the upstream error. I googled, asked ChatGPT, I dont know how to fix this error. I don't see/understand where I have to change a FastCGI protocol version on Kubernetes side.
The PHP image is just the same.
Any ideas?