简体   繁体   English

Kubernetes-动态配置存储

[英]Kubernetes - dynamic provisioning of storage

I have a deployment configuration as follows: 我的部署配置如下:

apiVersion: extensions/v1beta1
kind: Deployment
--- REMOVED FOR BREVITY ---
      volumes:
      - gcePersistentDisk: {fsType: pd-ssd, pdName: devtasker-disk}
        name: devtasker-disk
      - gcePersistentDisk: {fsType: pd-ssd, pdName: devtasker-pg}
        name: devtasker-pg

This works fine, however it requires the persistent volumes to be created manually and then the deployment can take place. 这可以正常工作,但是需要手动创建持久卷,然后可以进行部署。

I saw in Kubernetes 1.4 they have released "Dyanmic Provisioning & Storage Classes". 我在Kubernetes 1.4中看到他们发布了“动态配置和存储类”。

I have added a storage class as follows: 我添加了一个存储类,如下所示:

kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: ssd-storage
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd

I now want to add a PVC to my deployment configuration file mentioned above. 我现在想将PVC添加到上述部署配置文件中。 The standard PVC for the above storage class goes like this: 上述存储类别的标准PVC如下所示:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations: {volume.beta.kubernetes.io/storage-class: ssd-storage}
  name: claim1
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests: {storage: 30Gi}

Im struggling to get the above PVC into my deployment configuration mentioned in the first code block above. 我正在努力将上述PVC放入上面的第一个代码块中提到的部署配置中。

I tried this: 我尝试了这个:

      volumes:
      - gcePersistentDisk: {fsType: pd-ssd, pdName: devtasker-disk}
        name: devtasker-disk
      - gcePersistentDisk: {fsType: pd-ssd, pdName: devtasker-pg}
        name: devtasker-pg
      - persistentVolumeClaim: {claimName: ssd-storage, annotations: {volume.beta.kubernetes.io/storage-class: ssd-storage}}
        name: ssd-storage

.. but I haven't had any luck with many different combinations. ..但是我没有很多不同组合的运气。 I get the following: 我得到以下内容:

error validating "kubernetes/deployment.yml": error validating data: found invalid field annotations for v1.PersistentVolumeClaimVolumeSource; if you choose to ignore these errors, turn validation off with --validate=false

Could anyone please point me in the right direction here? 有人可以在这里指出正确的方向吗?

The storage class tells how to create the PV. 存储类告诉您如何创建PV。 The PVC claim requests the actual PV from the underlining infrastructure. PVC索赔要求下划线的基础设施提供实际的PV。

Your deployment should only know about the PVC, so using your example you would end up with the following and remove the gcePersistentDisk entries: 您的部署应该只了解PVC,因此在您的示例中,您将获得以下内容并删除gcePersistentDisk条目:

volumes:
   - name: storage
     persistentVolumeClaim
       claimName: claim1
   - name: storage2
     persistentVolumeClaim
       claimName: claim2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM