Helm删除了StorageClass,但保留了永久卷声明

时间:2018-09-10 10:28:49

标签: kubernetes google-kubernetes-engine kubernetes-helm

我正在使用头盔部署StatefulSet,下面是yaml

---
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: {{ .Values.database.mongo.storageClassName }}
  labels:
    for: for-mongo-statefulset
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
reclaimPolicy: Retain
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: mongo
spec:
  serviceName: {{ .Values.database.mongo.serviceName }}
  replicas: {{ .Values.database.mongo.replicas }}
  template:
    metadata:
      labels:
        role: mongo
        environment: prod
    spec:
      serviceAccountName: {{ .Values.serviceAccount }}
      terminationGracePeriodSeconds: 10
      containers:
        - name: mongo
          image: mongo
          command:
            - mongod
            - "--bind_ip"
            - 0.0.0.0
            - "--replSet"
            - {{ .Values.database.mongo.replicaSet }}
            - "--smallfiles"
            - "--noprealloc"
          ports:
            - containerPort: {{ .Values.database.mongo.port }}
          volumeMounts:
            - name: {{ .Values.database.mongo.storageName }}
              mountPath: /data/db
        - name: mongo-sidecar
          image: cvallance/mongo-k8s-sidecar
          env:
            - name: MONGO_SIDECAR_POD_LABELS
              value: "role=mongo,environment=prod"
            - name: KUBERNETES_MONGO_SERVICE_NAME
              value: {{ .Values.database.mongo.serviceName }}
  volumeClaimTemplates:
  - metadata:
      name: {{ .Values.database.mongo.storageName }}
    spec:
      storageClassName: {{ .Values.database.mongo.storageClassName }}
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 100Gi

helm install . -n release-name上创建StorageClassPersistentVolumePersistentVolumeClaim

如果我删除发行版helm delete release-name --purge,它将保留pv和pvc,这很好。但是,即使我在sc上指定了StorageClass,它也会删除reclaimPolicy: Retain

这是预期的行为吗?

头盔版本

Client: v2.10.0+g9ad53aa
Server: v2.10.0+g9ad53aa

Kubernetes版本

Client Version: v1.11.1
Server Version: v1.9.7-gke.5

更新

我假设reclaimPolicy既适用于StorageClass也适用于PV / PVC,感谢@Pablo清除了我对reclaimPolicy的理解

  

Reclaim Policy

     

由   存储类将具有在   类的reclaimPolicy字段,可以是Delete或   保留。如果在StorageClass对象为时未指定reclaimPolicy   创建后,默认为删除

是否有与reclaimPolicy类似的东西会告诉头盔/ kubernetes在执行StorageClass时不要删除helm delete release-name --purge

3 个答案:

答案 0 :(得分:3)

StorageClass对象中列出的回收策略用于持久卷,而不是其自身的存储类。这意味着使用该存储类创建的pv和pvc将继承该存储类中设置的回收策略。

您可以在这里找到更多信息:https://kubernetes.io/docs/concepts/storage/storage-classes/

答案 1 :(得分:1)

尝试在StorageClass reclaimPolicy上设置“删除”

https://kubernetes.io/docs/concepts/storage/storage-classes/#reclaim-policy

kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: {{ .Values.database.mongo.storageClassName }}
  labels:
    for: for-mongo-statefulset
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
reclaimPolicy: Delete

答案 2 :(得分:1)

注释"helm.sh/resource-policy": keep指示Tiller在helm delete操作期间跳过此资源。但是,此资源成为孤立的。头盔将不再以任何方式对其进行管理。如果在已经删除但保留了资源的发行版上使用helm install —replace,则会导致问题。

要明确选择删除资源,例如在覆盖图表的默认注释时,请将资源策略注释值设置为delete