I have a pod called mypod0 with two persistent volumes.

mypd0, mypd1 (provided through two persistent volume claims myclaim0, myclaim1) mounted into mypod0 at /dir0, /dir1 as shown in the pod definition below.

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

Now I also have another pod mypod1 already running in the cluster. Is there a way to dynamically/programmatically (using fabric8, Kubernetes-client) to unmount (detach) mypd1 from mypod0, and then attach the volume mypd1 into mypod1 (without restarting any of the pods mypod0, mypod1). Any hint will be appreciated.

1

There are 1 answers

2
Mikołaj Głodziak On BEST ANSWER

As Jonas mentioned in the comment, this action is not possible:

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

Look at the definition of 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.

However, you can dynamically create new storage volumes. Kubernetes supports 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.