2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Match Up PVC to Pod (OpenShift)

Posted at

OpenShift をはじめとする Kubernetes では、Pod への Volume Mount に PersistentVolumeClaim (PVC) を使用します。Pod から見た、現在使用してる PVC の確認は oc get pod -o yaml 等で可能ですが、PVC から見た、どの Pod が PVC を使用しているかの確認は、思いのほか面倒ではあります。

ここでは、Red Hat OpenShift on IBM Cloud (ROKS) 4.11 を使用して、PVC と Pod の Match Up の例をご紹介します。

List of PVC in Project (Namespace)

PVC の一覧は、以下で取得可能です。

$ oc get pvc
NAME       STATUS   VOLUME    CAPACITY   ACCESS MODES  STORAGECLASS                AGE
my-pvc-01  Bound    my-pv-01  500Mi      RWX           ibmc-vpc-block-10iops-tier  243d
my-pvc-02  Bound    my-pv-02  500Mi      RWX           ibmc-vpc-block-10iops-tier  243d
my-pvc-03  Bound    my-pv-03  10Gi       RWX           ibmc-vpc-block-10iops-tier  135d

ここでは、PVC NAME のみを取得するために、以下の Syntax を使用します。

$ oc get pvc -o custom-columns=:.metadata.name --no-headers
my-pvc-01
my-pvc-02
my-pvc-03

Match Up PVC to Pod

PVC NAME と Pod Manifest の .spec.volumes[].persistentVolumeClaim.claimName が一致する Pod を抽出することで Match UP が可能です。
以下の例では、my-pvc-01my-pvc-02 は1つの Pod が、my-pvc-03 は6つの Pod が使用していることが分かります。

$ for PVC in $(oc get pvc -o custom-columns=:.metadata.name --no-headers)
do
        echo "PVC :"
        echo "$PVC"
        echo "POD(s) :"
        oc get pod -o json | jq --arg PVC $PVC -rc '.items[] | select(.spec.volumes[].persistentVolumeClaim.claimName == $PVC) | .metadata.name'
        echo
done

PVC :
my-pvc-01
POD(s) :
my-pod-01-7b479865f4-wf5k9

PVC :
my-pvc-02
POD(s) :
my-pod-02-5b68586569-skzm7

PVC :
my-pvc-03
POD(s) :
my-pod-01-7b479865f4-wf5k9
my-pod-02-5b68586569-skzm7
my-pod-03-7c55c8f787-66s7v
my-pod-04-5fc5dbcdb8-vwwnv
my-pod-05-7cc8f49c6c-rr4kv
my-pod-06-7b997949b-vqsfv

この例を応用することで、SecretConfigMap 等の Ephemeral Volume の確認も可能です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?