【问题标题】:How Deploy Drupal 7 using Kubernetes with a persistent store?如何使用 Kubernetes 和持久存储部署 Drupal 7?
【发布时间】:2020-06-23 19:52:07
【问题描述】:

我正在尝试在 Kubernetes 中部署 Drupal 7,但失败并出现错误 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

这是 K8S 部署清单:

--- 
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

但是,当我从 drupal 容器中删除 volumeMounts 时,它可以工作。我需要使用卷来保存网站数据,有人可以提出解决方法吗?

更新:我还添加了持久化卷的清单。

【问题讨论】:

    标签: kubernetes drupal drupal-7


    【解决方案1】:

    检查您是否可以写入已安装的卷。

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

    因为配置了组 ID (GID) 的存储只允许使用相同 GID 的 Pod 写入。不匹配或缺少 GID 会导致权限被拒绝错误。

    或者,您可以尝试使用 drupal 的运算符: https://github.com/geerlingguy/drupal-operator

    还有 helm chart 是另一种选择: https://bitnami.com/stack/drupal/helm

    【讨论】:

    • 感谢您的回复。出于某种原因,我无法将 shell 安装到容器中,但上面的代码适用于 drupal:8.6 图像。我已将 GID 添加到 PVC(上面更新了代码),但仍然是同样的问题。
    猜你喜欢
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多