使用Kubernetes进行多卷安装:一个工作,一个不工作

时间:2016-02-16 21:46:54

标签: kubernetes persistent-storage

我正在尝试使用单个容器创建一个Kubernetes容器,该容器上安装了两个外部卷。我的.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描述中,两个卷似乎都已正确安装:

$ 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

感谢任何帮助。感谢。

2 个答案:

答案 0 :(得分:0)

我没有看到发生上述行为的任何直接问题!但是,我想请您尝试的是使用“部署”而不是建议的“ {Pod”,但建议使用许多here,尤其是在使用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

答案 1 :(得分:0)

Kubernetes documentation指出:

  

卷无法装载到其他卷上,或具有到其他卷的硬链接   卷

我遇到了同样的问题,在我的情况下,问题是两个卷挂载都有重叠的mountPath,即都是以/ var /开头。

它们在安装后没有问题。