我使用 k8s/client-go 库来控制和开发我的应用程序(https://github.com/kubernetes/client-go)。
使用持久卷声明的子路径时出现问题。例如,我有两个 pod 并将每个容器的数据挂载到 2 个子路径ORG1/DIR1
和ORG2/DIR2
持久卷声明(efs file
),详细信息如下:
apiVersion: v1
kind: Pod
metadata:
name: my-lamp-site
spec:
containers:
- name: mysql
image: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "rootpasswd"
volumeMounts:
- mountPath: /var/lib/mysql
name: site-data
subPath: ORG1/DIR1
- name: php
image: php:7.0-apache
volumeMounts:
- mountPath: /var/www/html
name: site-data
subPath: ORG1/DIR2
volumes:
- name: site-data
persistentVolumeClaim:
claimName: hpc-vinhha-test
而当我调用删除这个 pod 时,目前 k8s 只删除 pod,core lib 不删除 pod 上的数据persistent volume claim
。这样,PVC的数据就会变成垃圾,变得越来越大。
我想删除子路径中的所有数据ORG1/DIR1
以及ORG1/DIR2
删除 pod 时。
这是 pvc 的文件 yaml:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"efs-claim","namespace":"default"},"spec":{"accessModes":["ReadWriteMany"],"resources":{"requests":{"storage":"5Gi"}},"storageClassName":"efs-sc"}}
pv.kubernetes.io/bind-completed: "yes"
pv.kubernetes.io/bound-by-controller: "yes"
creationTimestamp: "2020-07-10T04:02:51Z"
finalizers:
- kubernetes.io/pvc-protection
name: efs-claim
namespace: default
resourceVersion: "887409"
selfLink: /api/v1/namespaces/default/persistentvolumeclaims/efs-claim
uid: ab66c2f7-744c-4d6f-a508-2bc90f0b1897
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storageClassName: efs-sc
volumeMode: Filesystem
volumeName: efs-pv-shared
status:
accessModes:
- ReadWriteMany
capacity:
storage: 5Gi
phase: Bound
那么,你能帮我解决这个问题吗?因为我是 k8s 和 aws-efs 的新手。所以,我对此没有太多经验:(
非常感谢。