I have a dockerized symfony project and I'm trying to delpoy it in GPC on Kubernetes cluster. In development I use docker-compose and I have two sepparate containers for php-fpm and nginx.
When I run docker-compose up --build, it all works fine, but when I try to create a kubernetes cluster I get this error after I run kubectl apply -f nginx.deployment.yaml:
nginx: [emerg] host not found in upstream "php-fpm" in /etc/nginx/conf.d/default.conf:11
This is the nginx default.conf file:
server {
listen 80;
server_name localhost;
root /app/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
internal;
}
location ~ \.php$ {
return 404;
}
}
Please note
fastcgi_pass php-fpm:9000;
which references the php-fpm container.
Dockerfile for nginx:
ARG VERSION
# Dev image
FROM nginx:${VERSION}-alpine as dev
# Copy nginx config
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf
# Prod image
FROM dev as prod
# Copy assets
COPY ./assets /app/public
Here it is the nginx.deployment.yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f ../docker-compose.yml
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: nginx
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: kompose convert -f ../docker-compose.yml
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: nginx
spec:
containers:
- image: myDockerHubRegistry/symfony-nginx:0.2
name: nginx
ports:
- containerPort: 80
resources: {}
volumeMounts:
- mountPath: /app/public
name: nginx-claim
restartPolicy: Always
volumes:
- name: nginx-claim
persistentVolumeClaim:
claimName: nginx-claim
status: {}
I also tried to put nginx and php-fpm on the same deployment, but I still get the same error.
What am I missing?
php-fpm
for that name to resolve. – David Maze