I'm trying to define a deployment on Kubernetes about a web application.
As you can see in follow deployment manifest there is a pod with two containers inside:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: app
name: web
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: app
strategy:
type: Recreate
template:
metadata:
labels:
app: app
spec:
containers:
- name: sylius-php-fpm
image: php-fpm:v4
imagePullPolicy: Never
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
- name: nginx
image: nginx:alpine
imagePullPolicy: Always
ports:
- containerPort: 80
name: http
protocol: TCP
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
restartPolicy: Always
volumes:
- name: nginx-config-volume
configMap:
name: nginx-config
I have defined a volume with follow configMap about nginx configuration:
kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-config
data:
default.conf: |
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /srv/app/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_read_timeout 300;
proxy_read_timeout 300;
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;
}
client_max_body_size 6m;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
Also i use ksync to sync source code between development environment and Kubernetes cluster. So i have exposed nginx on 80 port and cgi on 9000 port defining services in this way:
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: app
spec:
ports:
- name: http
port: 80
targetPort: 80
selector:
app: app
type: ClusterIP
------
apiVersion: v1
kind: Service
metadata:
name: php-fpm
labels:
app: app
spec:
ports:
- name: http
port: 9000
targetPort: 9000
selector:
app: app
type: ClusterIP
and define port-forward to access to web server from local environment like so:
kubectl port-forward web-68b788956d-98zcs 80:80
I don't understand why when i try to visit 127.0.0.1 i receive a timeout occured error
It seems that nginx doesn't communicate with php-fpm container
I say that because if i try to see an html file inside root path server it works fine, but index.php in the same directory doesn't works.
Also when i try to ping php-fpm from nginx container
How can i do to solve my problem? Anyone can help me please?
Thank you in advance to everyone and sorry for long post.