How Deploy Drupal 7 using Kubernetes with a persistent store?

6/23/2020

I'm trying to deploy Drupal 7 in Kubernetes, It fails with an error Fatal error: require_once(): Failed opening required '/var/www/html/modules/system/system.install' (include_path='.:/usr/local/lib/php') in /var/www/html/includes/install.core.inc on line 241.

Here is K8S deployment manifest:

--- 
apiVersion: v1
kind: PersistentVolumeClaim
metadata: 
  name: drupal-pvc
  annotations:
    pv.beta.kubernetes.io/gid: "drupal-gid"
spec: 
  accessModes: 
    - ReadWriteOnce
  resources: 
    requests: 
      storage: 5Gi
--- 
apiVersion: v1
kind: Service
metadata: 
  name: drupal-service
spec: 
  ports: 
    - name: http
      port: 80
      protocol: TCP
  selector: 
    app: drupal
  type: LoadBalancer
--- 
apiVersion: extensions/v1beta1
kind: Deployment
metadata: 
  labels: 
    app: drupal
  name: drupal
spec: 
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: drupal
    spec: 
      initContainers:
        - name: init-sites-volume
          image: drupal:7.72
          command: ['/bin/bash', '-c']
          args: ['cp -r /var/www/html/sites/ /data/; chown www-data:www-data /data/ -R']
          volumeMounts:
          - mountPath: /data
            name: vol-drupal
      containers: 
        - image: drupal:7.72
          name: drupal
          ports: 
            - containerPort: 80
          volumeMounts:
          - mountPath: /var/www/html/modules
            name: vol-drupal
            subPath: modules
          - mountPath: /var/www/html/profiles
            name: vol-drupal
            subPath: profiles
          - mountPath: /var/www/html/sites
            name: vol-drupal
            subPath: sites
          - mountPath: /var/www/html/themes
            name: vol-drupal
            subPath: themes 

      volumes:
        - name: vol-drupal
          persistentVolumeClaim: 
            claimName: drupal-pvc

However, when I remove the volumeMounts from the drupal container, it works. I need to use volumes in order to persist the website data, can any one suggest a fix?

Update: I have also added the manifest for the persistence volume.

-- Johny Simmons
drupal
drupal-7
kubernetes

1 Answer

6/23/2020

check if you could write to mounted volume.

# kubectl exec -it drupal-zxxx -- sh
$ ls -alhtr /var/www/html/modules
$ cd /var/www/html/modules
$ touch test.txt

because storage configured with a group ID (GID) allows writing only by Pods using the same GID. Mismatched or missing GIDs cause permission denied errors.

alternatively you could try out an operator for drupal: https://github.com/geerlingguy/drupal-operator

Also helm chart is another option: https://bitnami.com/stack/drupal/helm

-- Amila Kumaranayaka
Source: StackOverflow