GKE:如何挂载持久卷

时间:2018-04-30 10:02:47

标签: kubernetes google-kubernetes-engine

我正在尝试在GKE上运行具有持久存储的应用程序。

我尝试过使用动态永久存储,但这会让我对光盘的权利不足。

当我创建StorageClass时,PersistentVolume& PersistentVolumeClaim

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: documentation-7-x-storageclass
  labels:
     product: "documentation-7-x"
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-standard
  zone: europe-west1-b

apiVersion: v1
kind: PersistentVolume
metadata:
  name: documentation-7-x-volume
  labels:
     product: "documentation-7-x"
spec:
  capacity:
    storage: 500Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: documentation-7-x-storageclass
  persistentVolumeReclaimPolicy: Retain
  gcePersistentDisk: 
    fsType: "ext4" 
    pdName: "documentationstorage"
  mountOptions:
  - dir_mode=0777
  - file_mode=0777

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: documentation-7-x-volume-claim
  labels:
     product: "documentation-7-x"  
spec:
  volumeName: documentation-7-x-volume
  storageClassName: documentation-7-x-storageclass
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

这些是在GKE上正确创建的。

kubectl get pv
NAME                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM                                    STORAGECLASS                     REASON    AGE
documentation-7-x-volume   500Gi      RWO            Retain           Bound     default/documentation-7-x-volume-claim   documentation-7-x-storageclass             3m

但是当我在我的应用程序中使用创建声明时,我收到错误。

# Create a deployment for the Documentation
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: documentation-7-x
  labels:
    product: "documentation-7-x"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: documentation-7-x
      product: "documentation-7-x"
  template:
    metadata:
      labels:
        app: documentation-7-x
        product: "documentation-7-x"
    spec: 
      volumes:
      - name: documentation-7-x-volume
        persistentVolumeClaim:
          claimName: documentation-7-x-volume-claim
      containers:
      - name: documentation-7-x
        image: atlassian/confluence-server:6.3.2
        imagePullPolicy: Always
        ports:
        - containerPort: 8090
        # Mount the volume claimed above
        volumeMounts:
        - name: documentation-7-x-volume
          mountPath: /var/atlassian/application-data/confluence
---
# Create service for the Documentation
apiVersion: v1
kind: Service
metadata:
  name: documentation-7-x-service
  labels:
    product: "documentation-7-x"
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 8090
  selector:
    app: documentation-7-x
    product: "documentation-7-x"

错误:

MountVolume.MountDevice failed for volume "documentation-7-x-volume" : mount failed: exit status 32 Mounting command: systemd-run Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/fontoxmldocumentstorage --scope -- mount -t ext4 -o dir_mode=0777,file_mode=0777,defaults /dev/disk/by-id/google-fontoxmldocumentstorage /var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/fontoxmldocumentstorage Output: Running scope as unit: run-r49218112baa6471a8b4a3e2b4ad68aaa.scope mount: wrong fs type, bad option, bad superblock on /dev/sdb, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so.

我在AKS上尝试了与azure文件相同的概念,这项工作没有任何问题。

我在GKE上缺少哪一步?

UPDATE 我找到了运行dmesg | tail命令的地方并得到了:

[ 9793.897427] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[ 9797.046199] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[ 9802.139814] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[ 9811.333114] EXT4-fs (sdb): Unrecognized mount option "file_mode=0777" or missing value
[ 9828.747800] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[ 9862.074279] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[ 9927.399967] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[10050.664769] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[10173.955638] EXT4-fs (sdb): Unrecognized mount option "file_mode=0777" or missing value
[10297.281253] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value

似乎并非所有提供商都支持相同的挂载选项。

1 个答案:

答案 0 :(得分:0)

[10050.664769] EXT4-fs (sdb): Unrecognized mount option "dir_mode=0777" or missing value
[10173.955638] EXT4-fs (sdb): Unrecognized mount option "file_mode=0777" or missing value

这些错误与提供程序无关,它们与文件系统类型有关。

Kubernetes调用系统来安装具有已定义的FS类型和选项的卷。您设置了ext4个文件系统,但对于[234] FS,它是impossible to set dir_modefile_mode个选项。