0

This is my PVC


apiVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: my-pvc
spec:
    accessModes:
        - ReadWriteOnce
    resources:
        requests:
            storage: 1Gi
    storageClassName: do-block-storage

This is my Deployment Configuration

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysite
  labels:
    tier: backend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: mysite
      tier: backend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysite
        tier: backend
    spec:
      containers:
        - name: mysite
          image: my-image
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config
              mountPath: /etc/nginx/sites-enabled
            - name: my-pvc
              mountPath: /var/www/app
      volumes:
        - name: my-pvc
          persistentVolumeClaim:
            claimName: my-pvc
        - name: config
          configMap:
            name: wordpress-nginx-config
            items:
              - key: config
                path: default.conf
      imagePullSecrets:
        - name: registry-secret

This is my wordpress config Map

apiVersion: v1
kind: ConfigMap
metadata:
  name: wordpress-nginx-config
  labels:
    tier: backend
data:
  config: |
    server {
      listen 80;
      index index.php index.html;
      server_name _;
      error_log /dev/stdout info;
      access_log /dev/stdout;
      root var/www/app;
      location /.git {
         deny all;
         return 403;
      }
      location / {
          try_files $uri $uri/ /index.php?$args;
              }
      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_pass unix:/var/run/php-fpm.sock;
        }
        location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
                expires           5d;
        }
        location ^~ /.well-known {
          allow all;
          auth_basic off;
        }
    }

Visiting my service URL, I still get error 404. I will appreciate every help I can get. I deployed without the PVC and it worked, I know the issue is with my PVC configuration.

0

The problem is your are using absolute path in you mountPath: /var/www/app and relative path in your configMap: root var/www/app;.

You need to change in your configMap to use relative path or fix your mountPath in container specs.

To check if the files is in thec orrect place, you could log into container and browse to folder /var/www/app.

kubectl exec -it <container_name> sh

References: Get container shell Absolute path vs. Relative path

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.