I have a kubernetes setup with nginx pod and php pod, with a service for the php on port 9000. The files are mounted to the host on both nginx and php:
/usr/share/nginx/html -> /data/website/current
The nginx root is:
/usr/share/nginx/html/current/public
If i access in the browser for example.com/test.html it loads, this file is located in /usr/share/nginx/html/current/public.index.html
Now if i put a test.php file in the same folder and try to access example.com/test.php i get a 404 error.
All the files that are shared are owned by user 1001 and group 1001 which is the www-data user id in php and nginx user id in the nginx containers. All the pods and services are up and running.
I must be doing something wrong somewhere, my kubernetes setup looks like this:
PHP Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-deployment
labels:
deploy: php
spec:
replicas: 1
selector:
matchLabels:
pod: php-deployment
template:
metadata:
labels:
pod: php-deployment
spec:
containers:
- name: php
imagePullPolicy: Always
image: glenelkinsdev/gofollow-php-backend:latest
ports:
- containerPort: 80
volumeMounts:
- mountPath: /usr/share/nginx/html
name: website-volume
volumes:
- name: website-volume
hostPath:
path: /data/website
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: php-service
spec:
selector:
pod: php-deployment
ports:
- protocol: TCP
port: 9000
targetPort: 9000
Nginx Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-backend-deployment
labels:
deploy: nginx-backend
spec:
replicas: 1
selector:
matchLabels:
pod: nginx-backend
template:
metadata:
labels:
pod: nginx-backend
spec:
containers:
- name: nginx
imagePullPolicy: Always
image: glenelkinsdev/gofollow-nginx-backend:latest
ports:
- containerPort: 80
volumeMounts:
- mountPath: /usr/share/nginx/html
name: website-volume
volumes:
- name: website-volume
hostPath:
path: /data/website
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: nginx-backend-service
spec:
type: NodePort
selector:
pod: nginx-backend
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30002
Nginx config:
events {
worker_connections 1024;
}
http {
server {
listen 80;
root /usr/share/nginx/html/current/public;
location / {
try_files $uri /index.php?$is_args$args;
}
location ~ ^/index.php(/|$) {
fastcgi_pass localhost:9000;
fastcgi_split_path_info ^(.+.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ .php$ {
return 404;
}
error_log /usr/share/nginx/html/log/error.log;
access_log /usr/share/nginx/html/log/access.log;
}
}
Another problem is, i seem to have to use fastcgi_pass localhost:9000; instead of fastcgi_pass php-service:9000; otherwise the pods won’t start? I get:
nginx: [emerg] host not found in upstream “php-service” in
/etc/nginx/nginx.conf:16
Kubectl output:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/mysql-deployment-55bbf4d8d8-w52lx 1/1 Running 0 16h 172.17.0.2 node1 <none> <none>
pod/nginx-backend-deployment-d969fcdf4-dggh8 1/1 Running 0 82m 172.17.0.5 node1 <none> <none>
pod/nginx-frontend-deployment-5776fc574f-plbsq 1/1 Running 0 120m 172.17.0.3 node1 <none> <none>
pod/php-deployment-7f856b4757-g7zsx 1/1 Running 0 82m 172.17.0.4 node1 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d1h <none>
service/mysql-service ClusterIP 10.99.10.232 <none> 3306/TCP 16h pod=mysql
service/nginx-backend-service NodePort 10.109.86.98 <none> 80:30002/TCP 16h pod=nginx-backend
service/nginx-frontend-service NodePort 10.106.42.107 <none> 80:30001/TCP 16h pod=nginx-frontend
service/php-service ClusterIP 10.104.223.83 <none> 9000/TCP 126m pod=php-deployment
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/mysql-deployment 1/1 1 1 16h mysql mysql:5.7 pod=mysql
deployment.apps/nginx-backend-deployment 1/1 1 1 82m nginx glenelkinsdev/gofollow-nginx-backend:latest pod=nginx-backend
deployment.apps/nginx-frontend-deployment 1/1 1 1 120m nginx nginx:latest pod=nginx-frontend
deployment.apps/php-deployment 1/1 1 1 82m php glenelkinsdev/gofollow-php-backend:latest pod=php-deployment
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/mysql-deployment-55bbf4d8d8 1 1 1 16h mysql mysql:5.7 pod=mysql,pod-template-hash=55bbf4d8d8
replicaset.apps/nginx-backend-deployment-d969fcdf4 1 1 1 82m nginx glenelkinsdev/gofollow-nginx-backend:latest pod=nginx-backend,pod-template-hash=d969fcdf4
replicaset.apps/nginx-frontend-deployment-5776fc574f 1 1 1 120m nginx nginx:latest pod=nginx-frontend,pod-template-hash=5776fc574f
replicaset.apps/php-deployment-7f856b4757 1 1 1 82m php glenelkinsdev/gofollow-php-backend:latest pod=php-deployment,pod-template-hash=7f856b4757