Kubernetes - connect Laravel with nginx

11/11/2019

I'm trying to create pods there Kubernetes, all are successfully created, but an application is not visible to nginx. nginx is only viewing the default html file and not the project file.

Nginx.yaml configuration file, where I create configuration, service, and deployment

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf
data:
  nginx.conf: |

    server {
        listen 80;
        index index.php index.html;
        root /usr/share/nginx/html;

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass app-service:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        location / {
            try_files $uri $uri/ /index.php$query_string$args;
            gzip_static on;
        }
    }

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.17.0-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /etc/nginx/conf.d
          readOnly: true
          name: nginx-conf

      volumes:
      - name: nginx-conf
        configMap:
          name: nginx-conf
          items:
            - key: nginx.conf
              path: nginx.conf

---

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: nginx

In the app.yaml file, I download an image of docker, configuration or database access, and configuration creation, service, and deployment.

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-conf
  labels:
    name: app-conf
data:
  env: |
    APP_NAME=SSO
    APP_ENV=local
   ...
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
spec:
  replicas: 1
  selector: 
    matchLabels:
      app: app

  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name: sso
        image: docker.io/guten/laravel-minikube:2
        imagePullPolicy: Always
        command: ["/bin/sh", "-c", "ln -s /var/www /usr/share/nginx; /var/www/entrypoint.sh; php-fpm;"]
        ports:
        - containerPort: 80
        envFrom:
        - configMapRef:
            name: app-conf
        env:
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        volumeMounts:
        - name: app-conf
          subPath: .env
          mountPath: /var/www/.env

      volumes:
      - name: app-conf
        configMap:
          name: app-conf
          items:
            - key: env
              path: .env

---

apiVersion: v1
kind: Service
metadata:
  name: app-service
  labels:
    app: app-service
spec:
  type: NodePort
  ports:
    - protocol: TCP
      port: 9000
      nodePort: 30080
  selector:
    app: app
-- Wellington Pereira
kubernetes
laravel
nginx

0 Answers