2016-12-05 70 views
0

尝试使用apache drupal image在Kubernetes上创建Drupal容器。Kubernetes持久性存储导致文件在容器内消失

当在/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 - 新创建的谷歌计算磁盘注册到kubernetes群集实例

kubectl create -f gce-volumes.yaml 

3 - 创建的Drupal荚

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 

是什么造成的文件消失?我怎样才能成功地持续在容器内的/var/www/html Drupal安装文件?

回答

1

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

如果您的内容是动态的,并且您希望将这些文件保存在persistentStorage中,则可以这样做,但最初您需要填入persistentStorage

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

另一种选择是有一个Job做到这一点只有一次

注意(你运行你的Drupal波德之前装入此存储。):

GKEPersistentStorage只允许ReadWriteOnce(只能安装在单个Pod)或ReadOnlyMany(即只能读取,但可以安装在多个Pod上),并且不能同时安装不同模式,因此最终只能运行其中一个Pod。 (即它不会缩放)