Deploy Lemp Stack on Kubernetes Cluster

Hi,

My configuration seems correct but the kubernetes service is always in pending. So the task is failed

This is the frontend confguration :

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

}

http {
  server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    # Set nginx to serve files from the shared volume!
    root /var/www/html;
    index index.html index.htm index.php;
    server_name _;

    location / {
      rewrite .* /index.php;
    }

    location ~ \.php$ {
      include fastcgi_params;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
      fastcgi_param REQUEST_METHOD \$request_method;
    }
  }
}

apiVersion: v1
kind: PersistentVolume
metadata:
name: nginx-pv
labels:
app: nginx-volume
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
storageClassName: standard
hostPath:
path: “/mnt/data”

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-pv-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
storage: 2Gi

apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: app
name: nginx-wp-dp
spec:
replicas: 1
selector:
matchLabels:
app: app
strategy:
type: Recreate
template:
metadata:
labels:
app: app
spec:
containers:
- name: nginx-container
image: nginx:latest

    env:
    - name: MYSQL_DATABASE
      valueFrom:
        secretKeyRef:
          name: mysql-db-url
          key: database
    - name: MYSQL_USER
      valueFrom:
        secretKeyRef:
          name: mysql-user-pass
          key: username
    - name: MYSQL_ROOT_PASSWORD
      valueFrom:
        secretKeyRef:
          name: mysql-root-pass
          key: password
    - name: MYSQL_PASSWORD
      valueFrom:
        secretKeyRef:
          name: mysql-user-pass
          key: password            
    - name: MYSQL_HOST
      valueFrom:
        secretKeyRef:
          name: mysql-host
          key: host
    volumeMounts:
    - name: shared-files
      mountPath: /var/www/html
    - name: nginx-config-volume
      mountPath: /etc/nginx/nginx.conf
      subPath: nginx.conf
    ports:
    - containerPort: 80
      name: http
      protocol: TCP
  - name: php-fpm-container
    image: wordpress:php7.2-fpm
    env:
      - name: MYSQL_DATABASE
        valueFrom:
          secretKeyRef:
            name: mysql-db-url
            key: database
      - name: MYSQL_USER
        valueFrom:
          secretKeyRef:
            name: mysql-user-pass
            key: username
      - name: MYSQL_ROOT_PASSWORD
        valueFrom:
          secretKeyRef:
            name: mysql-root-pass
            key: password
      - name: MYSQL_PASSWORD
        valueFrom:
          secretKeyRef:
            name: mysql-user-pass
            key: password            
      - name: MYSQL_HOST
        valueFrom:
          secretKeyRef:
            name: mysql-host
            key: host
    volumeMounts:
    - name: shared-files
      mountPath: /var/www/html
  volumes:
  - name: nginx-persistent-storage
    persistentVolumeClaim:
      claimName: nginx-pv-claim
  - name: shared-files
    emptyDir: {}
  - name: nginx-config-volume
    configMap:
      name: nginx-config

apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: app
spec:
ports:

  • port: 80
    targetPort: 80
    nodePort: 30008
    type: LoadBalancer
    selector:
    app: app
    Please advice

Hi @chawki Can you please DM me your template ? Please attach the template file with the message.

Please find attached.
frontend.pdf (22.5 KB) backend.pdf (17.8 KB)

@chawki putting it pending for you. Can you please try again once.

hello, @chawki
That’s not the issue. Loadbalancer will be in the pending state until it’ll not get assigned the external IP address. but still you can access your application in the nodeport which is 30008 for testing.

Hi @Inderpreet.

I tried again but is failed.

Can you please double check?

@chawki
You did a mistake at
/** MySQL hostname */

It should getenv('MYSQL_HOST ')

1 Like

You are right. I misspelled the parameter :frowning:

My error is the same as you can see in my first post. Clearly this is a validation error.
any way i’ll not continue with this task :frowning:

@Inderpreet @rahul456

After deploying both the frontend and backend and making changes in wp-config.php file, when I try to access the wordpress website it’s displaying php code in the browser.

I really don’t know what am I doing wrong.

@Nautilus, your php is not configured correctly to work with nginx.