我们如何创建基于Azure磁盘的持久卷声明并从Kubernetes中的POD使用它们?

时间:2019-10-02 02:15:36

标签: azure kubernetes azure-aks azure-kubernetes

我找不到在POD创建或PVC创建期间可以传递有关Azure存储帐户的秘密的示例。一个示例确实有帮助。我遵循了示例here,但没有用。

2 个答案:

答案 0 :(得分:1)

要将Azure磁盘用作永久卷,有两种形式,一种是动态磁盘,另一种是静态磁盘。您可以按照DynamicStatic中的步骤,根据需要基于Azure磁盘创建持久卷。

答案 1 :(得分:1)

创建pvc:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azure-managed-disk
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: managed-premium
  resources:
    requests:
      storage: 5Gi

如果您使用的是非常老的AKS \,而不是AKS,则还需要创建存储类:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-premium
parameters:
  cachingmode: ReadOnly
  kind: Managed
  storageaccounttype: Premium_LRS
provisioner: kubernetes.io/azure-disk
reclaimPolicy: Delete
volumeBindingMode: Immediate

使用pvc:

kind: Pod
apiVersion: v1
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: nginx:1.15.5
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 250m
        memory: 256Mi
    volumeMounts:
    - mountPath: "/mnt/azure"
      name: volume
  volumes: // this is where you reference the pvc
  - name: volume
    persistentVolumeClaim:
      claimName: azure-managed-disk