kubernates with nginx / PHP-fpm not working

3/1/2021

I am trying to create autoscaling using Kubernetes, I have a Laravel system, I am deploying this system to Kubernetes using these YAML files configMap.yam

kind: ConfigMap
apiVersion: v1
metadata:
  name: qsinav-nginx-config
data:
  default.conf: |
        server {
            listen 80 default_server;
            listen [::]:80 default_server;
            server_name _;
            root        /var/www/html/Test/qSinav-starter/public;

         
            location / {
              try_files $uri $uri/ /index.php?$query_string;
                }


        location ~ ^/index\.php(/|$) {
              
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
            
 
         fastcgi_index            index.php;
         fastcgi_pass             127.0.0.1:9000;
         include                  fastcgi_params;
         fastcgi_param   PATH_INFO       $fastcgi_path_info;
         fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;


            internal;
            }

            location ~ \.php$ {
              return 404;
            }

            client_max_body_size 6m;

            error_log  /var/log/nginx/error.log;
            access_log /var/log/nginx/access.log;
        }

this is yaml file for building nginx / php-fpm containers

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: app
  name: qsinav6
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name: sylius-php-fpm
        image: bitnami/php-fpm
        imagePullPolicy: Never
        ports:
        - containerPort: 9000
          name: http
          protocol: TCP
        volumeMounts:
        - name: qsinav-nginx-config-volume
          mountPath: /etc/nginx/conf.d/default.conf
          subPath: default.conf
        - name: qsinav-www-storage
          mountPath: /var/www/html/Test/qSinav-starter
        resources:
            requests:
                cpu: 100m
          
      - name: nginx2
        image: nginx:alpine
        imagePullPolicy: Always
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        volumeMounts:
        - name: qsinav-nginx-config-volume
          mountPath: /etc/nginx/conf.d/default.conf
          subPath: default.conf
        - name: qsinav-www-storage
          mountPath: /var/www/html/Test/qSinav-starter
        resources:
            requests:
                cpu: 100m
      restartPolicy: Always
      serviceAccountName: ""
      volumes:
      - name: qsinav-www-storage
        
        persistentVolumeClaim:
          claimName: qsinav-pv-www-claim
      - name: qsinav-nginx-config-volume
        configMap:
          name: qsinav-nginx-config

and here is how I am exposing the service

 kubectl expose deployment qsinav6 --type=LoadBalancer --name=qsinav-service

and here is the result of

kubectl get services

qsinav-service                            LoadBalancer   10.106.113.217   10.106.113.217   9000:32071/TCP,80:30078/TCP   12m

now when I am trying to access my system by the browser I am trying to access using this url as it provided by services

10.106.113.217

but the problem is my system is not working properly , it seems like some times working and most time I have

File not found.

I don't know where is wrong, but it is sometimes working and I can access the system, but then I get a file not found error from Nginx

-- Muhammad ahmad
docker
kubernetes
laravel
nginx
php

0 Answers