动态地或以编程方式从 kubernetes pod 卸载/分离持久卷声明并将其分配(mount /attach)到另一个 pod

dynamically or programmatically unmount / detach a persistent volum claim from a kubernetes pod and assign (mount /attach ) it to another pod

我有一个名为 mypod0 的 pod,它有两个持久卷。

mypd0mypd1(通过两个持久卷声明 myclaim0myclaim1 提供)安装到 mypod0/dir0/dir1 如下面的 pod 定义所示。

apiVersion: v1
kind: Pod
metadata:
  name: mypod0
spec:
  containers:
    - name: mycontainer
      image: myimage
      volumeMounts:
      - mountPath: "/dir0"
        name: mypd
-   mountPath: "/dir1"
-   name: mypd1
  volumes:
    - name: mypd0
      persistentVolumeClaim:
        claimName: myclaim0
    - name: mypd1
      persistentVolumeClaim:
        claimName: myclaim1

现在我在集群中 运行 已经有另一个 pod mypod1。有没有办法 dynamically/programmatically(使用 fabric8,Kubernetes-client)从 mypod0 卸载(分离)mypd1,然后附加卷mypd1 变为 mypod1(无需重新启动任何 pods mypod0mypod1)。任何提示将不胜感激。

如评论中Jonas所述,此操作是不可能的:

Nope, this is not possible. Pod-manifests is intended to be seen as immutable and pods as disposable resources.

pods的定义:

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers. A Pod's contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it contains one or more application containers which are relatively tightly coupled. In non-cloud contexts, applications executed on the same physical or virtual machine are analogous to cloud applications executed on the same logical host.

但是,您可以动态创建新的存储卷。 Kubernetes 支持 Dynamic Volume Provisioning:

Dynamic volume provisioning allows storage volumes to be created on-demand. Without dynamic provisioning, cluster administrators have to manually make calls to their cloud or storage provider to create new storage volumes, and then create PersistentVolume objects to represent them in Kubernetes. The dynamic provisioning feature eliminates the need for cluster administrators to pre-provision storage. Instead, it automatically provisions storage when it is requested by users.