Deploy Nginx PhpFPm kubernetes

Below is my configmap and pod yaml files

First, create a ConfigMap whose contents are used

as the nginx.conf file in the web server.

This server uses /var/www/html as its

root document directory. When the server gets a

request for *.php, it will forward that request

to our PHP-FPM container.

apiVersion: v1

kind: ConfigMap

metadata:

name: nginx-config

data:

nginx.conf: |

events {

}

http {

  server {

    listen 8092 default_server;

    listen [::]:8092 default_server;

    

    # Set nginx to serve files from the shared volume!

    root /var/www/html;

    server_name _;

    location / {

      try_files $uri $uri/ =404;

    }

    location ~ \.php$ {

      include fastcgi_params;

      fastcgi_param REQUEST_METHOD $request_method;

      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

      fastcgi_pass 127.0.0.1:9000;

    }

  }

}

apiVersion: v1

kind: Pod

metadata:

name: nginx-phpfpm

spec:

containers:

  • name: nginx-container

    image: nginx:latest

    volumeMounts:

    • name: nginx-config-volume

      mountPath: /etc/nginx/nginx.conf

      subPath: nginx.conf

    volumeMounts:

    • mountPath: /var/www/html

      name: shared-files

  • name: php-fpm-container

    image: php:7.0-fpm

    volumeMounts:

    • mountPath: /var/www/html

      name: shared-files

volumes:

  • name: nginx-config-volume

    configMap:

    name: nginx-config

volumes:

  • name: shared-files

    emptyDir: {}

It failed stating Volume is not named as ‘nginx-config-volume’

Because you’ve specified two volumes field and by default it chose second volumes field that is “shared-files”.
It should be like

volumes:
 - name: nginx-config-volume
   configMap:
       name: nginx-config
- name: shared-files
  emptyDir: {}

You did for same in the volumeMounts.

1 Like