【问题标题】:Multiple Volume mounts with Kubernetes: one works, one doesn't使用 Kubernetes 挂载多个卷:一个有效,一个无效
【发布时间】:2016-05-28 09:16:58
【问题描述】:

我正在尝试创建一个带有单个容器的 Kubernetes pod,该容器上安装了两个外部卷。我的 .yml pod 文件是:

apiVersion: v1
kind: Pod
metadata:
  name: my-project
  labels:
    name: my-project
spec:
  containers:
    - image: my-username/my-project
      name: my-project
      ports:
        - containerPort: 80
          name: nginx-http
        - containerPort: 443
          name: nginx-ssl-https
      imagePullPolicy: Always
      volumeMounts:
        - mountPath: /home/projects/my-project/media/upload
          name: pd-data
        - mountPath: /home/projects/my-project/backups
          name: pd2-data
  imagePullSecrets:
    - name: vpregistrykey
  volumes:
    - name: pd-data
      persistentVolumeClaim:
        claimName: pd-claim
    - name: pd2-data
      persistentVolumeClaim:
        claimName: pd2-claim

我正在使用 Persistent Volumes 和 Persisten Volume Claims,例如: PV

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pd-disk
  labels:
    name: pd-disk
spec:
  capacity:
    storage: 250Gi
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: "pd-disk"
    fsType: "ext4"

PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pd-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 250Gi

我最初使用以下命令创建了磁盘: $ gcloud compute disks create --size 250GB pd-disk 第二个磁盘和第二个 PV 和 PVC 也是如此。当我创建 pod 时,一切似乎都正常,没有抛出任何错误。现在出现了奇怪的部分:其中一条路径被正确安装(并且因此是持久的),而每次我重新启动 pod 时,另一条路径被删除......

我尝试从头开始重新创建所有内容,但没有任何改变。此外,从 pod 描述来看,两个卷似乎都已正确安装:

$ kubectl describe pod my-project
Name:       my-project
...
Volumes:
  pd-data:
    Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  pd-claim
    ReadOnly: false
  pd2-data:
    Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  pd2-claim
    ReadOnly: false

感谢任何帮助。谢谢。

【问题讨论】:

  • 你用的是什么版本的kubernetes,你是怎么重启pod的?
  • 我使用的是 Kubernetes v1,为了重新启动 pod,我使用的是 kubectl delete -f my-project.yml,然后是 kubectl create -f my-project.yml
  • kubectl version 的输出是什么?
  • Client Version: version.Info{Major:"1", Minor:"1", GitVersion:"v1.1.4", GitCommit:"a5949fea3a91d6a50f40a5684e05879080a4c61d", GitTreeState:"clean"} Server Version: version.Info{Major:"1", Minor:"1", GitVersion:"v1.1.7", GitCommit:"e4e6878293a339e4087dae684647c9e53f1cf9f0", GitTreeState:"clean"}
  • 如果您能够解决此问题,您可以在此处为可能遇到相同问题的其他社区成员发布自我回答。

标签: kubernetes persistent-storage


【解决方案1】:

Kubernetes documentation 声明:

卷不能挂载到其他卷或与其他卷有硬链接 卷

我遇到了同样的问题,就我而言,问题是两个卷安装都有重叠的安装路径,即都以 /var/ 开头。

修复后安装没有问题。

【讨论】:

    【解决方案2】:

    我没有发现任何直接问题会导致上述行为发生!但我宁愿要求您尝试使用“部署”而不是许多 here 建议的“Pod”,尤其是在使用 PV 和 PVC 时。 Deployment 负责许多事情以维持“期望状态”。我在下面附上了我的代码供您参考,它有效,即使在删除/终止/重新启动之后,两个卷也是持久的,因为这是由部署的所需状态管理的。

    我的代码与您的代码有两个不同之处:

    1. 我有一个部署对象而不是 pod
    2. 我正在为我的卷使用 GlusterFs。

    部署 yml。

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: nginx
      namespace: platform
      labels:
        component: nginx
    spec:
      replicas: 2
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 1
      template:
        metadata:
          labels:
            component: nginx
        spec:
          nodeSelector:
            role: app-1
          containers:
            - name: nginx
              image: vip-intOAM:5001/nginx:1.15.3
              imagePullPolicy: IfNotPresent
              volumeMounts:
              - mountPath: "/etc/nginx/conf.d/"
                name: nginx-confd
              - mountPath: "/var/www/"
                name: nginx-web-content
          volumes:
          - name: nginx-confd
            persistentVolumeClaim:
              claimName: glusterfsvol-nginx-confd-pvc
          - name: nginx-web-content
            persistentVolumeClaim:
              claimName: glusterfsvol-nginx-web-content-pvc
    

    我的一个 PV

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: glusterfsvol-nginx-confd-pv
    spec:
      capacity:
        storage: 1Gi
      accessModes:
        - ReadWriteOnce
      glusterfs:
        endpoints: gluster-cluster
        path: nginx-confd
        readOnly: false
      persistentVolumeReclaimPolicy: Retain
      claimRef:
        name: glusterfsvol-nginx-confd-pvc
        namespace: platform
    

    上面的PVC

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: glusterfsvol-nginx-confd-pvc
      namespace: platform
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
    

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 2020-09-28
      • 2018-11-19
      • 1970-01-01
      • 1970-01-01
      • 2015-11-27
      • 2023-03-08
      • 2022-10-19
      • 2020-07-28
      相关资源
      最近更新 更多