【问题标题】:Kubernetes persistent storage causing files to disappear inside containerKubernetes 持久存储导致文件在容器内消失
【发布时间】:2016-12-05 15:23:44
【问题描述】:

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

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

工作流程

1 - 创建谷歌计算盘

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

2 - 将新创建的google计算盘注册到kubernetes集群实例

kubectl create -f gce-volumes.yaml

3 - 创建 Drupal pod

kubectl create -f drupal-deployment.yaml

定义文件的灵感来自于wordpressexample,我的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

【问题讨论】:

    标签: drupal kubernetes drupal-8


    【解决方案1】:

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

    如果您的内容是动态的,并且您希望将这些文件保存在 persistentStorage 中,这是执行此操作的方法,但是您首先需要填充 persistentStorage

    一种解决方案是将文件放在基础映像的不同文件夹中,并在运行 Pod 时将它们复制过来,但是每次启动 Pod 时都会发生这种情况,并且可能会覆盖您的更改,除非您的副本脚本首先检查文件夹是否为空。

    另一种选择是让Job 只执行一次(在运行 Drupal Pod 并挂载此存储之前)。

    注意:

    GKEPersistentStorage 只允许ReadWriteOnce(只能挂载在单个 Pod 上)或ReadOnlyMany(即只读但可以挂载在多个 Pod 上)并且不能同时以不同的模式挂载,所以最后你只能运行其中一个 Pod。 (即它不会扩展)

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 2021-04-22
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      相关资源
      最近更新 更多