drupal - Kubernetes持久存储导致文件在容器内消失

标签 drupal kubernetes drupal-8

尝试使用apache drupal image在Kubernetes上创建一个Drupal容器。

当在/var/www/html上安装持久卷并使用docker exec -it <drupal-container-name> bash检查Drupal容器时,没有可见的文件。因此,无法提供任何文件。

工作流程

1-创建Google计算磁盘

gcloud compute disks create --size=20GB --zone=us-central1-c drupal-1

2-将新创建的Google计算磁盘注册到kubernetes集群实例
kubectl create -f gce-volumes.yaml

3-创建Drupal pods
kubectl create -f drupal-deployment.yaml

定义文件是从wordpress example(我的drupal-deployment.yaml)启发而来的:
apiVersion: v1
kind: Service
metadata:
  name: drupal
  labels:
    app: drupal
spec:
  ports:
    - port: 80
  selector:
    app: drupal
    tier: frontend
  type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dp-pv-claim
  labels:
    app: drupal
spec:
  accessModes:
    - ReadWriteOnce
  resources:
      requests:
          storage: 20Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: drupal
  labels:
    app: drupal
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: drupal
        tier: frontend
    spec:
      containers:
      - name: drupal
        image: drupal:8.2.3-apache
        ports:
        - name: drupal
          containerPort: 80
        volumeMounts:
        - name: drupal-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: drupal-persistent-storage
        persistentVolumeClaim:
          claimName: dp-pv-claim

gce-volumes.yaml:
apiVersion: v1
kind: PersistentVolume
metadata:
  name: drupal-pv-1
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: drupal-1
    fsType: ext4

是什么导致文件消失?如何成功将Drupal安装文件持久保存在容器内的/var/www/html上?

最佳答案

您正在persistentStorage处挂载/var/www/html,因此,如果您在基础镜像中的该位置具有文件,则该文件夹将被挂载替换,并且基础镜像中的文件将不再可用。

如果您的内容是动态的,并且您想将这些文件保存在persistentStorage中,这就是这样做的方法,但是最初需要填充persistentStorage

一种解决方案是将文件放在基础镜像的其他文件夹中,并在运行Pod时将其复制,但是每次启动Pod时都会发生,并且可能会覆盖您的更改,除非您的复制脚本首先检查如果文件夹为空。

另一个选择是让Job仅执行一次(在运行Drupal Pod并装入此存储之前)。

注意:

GKEPersistentStorage仅允许ReadWriteOnce(只能安装在一个Pod上)或ReadOnlyMany(即可读,但可以安装在许多Pod上),并且不能同时以不同的模式安装,因此最终只能运行这些 pod 之一。 (即,不会缩放)

关于drupal - Kubernetes持久存储导致文件在容器内消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40977573/

相关文章:

php - Drupal 8.8.5 上奇怪的文件/文件夹权限错误

kubernetes - 无法使用 ingress 连接到 pod

java - Kubernetes 中 Java 应用程序的启动 CPU 限制

Drupal 8 突然重定向到/core/install.php

javascript - Drupal 未定义 - jQuery (Drupal 8)

javascript - 为什么这个 .js 脚本停止工作并导致浏览器卡住?

drupal用户登录重定向

drupal - 如何在 drupal 7 中启用/禁用修订

kubernetes - 如何让我的 kubernetes 获取最新的 docker 镜像?

javascript - 如何使用 jQuery 修改动态创建的内容