Static Volume Provisioning in Oracle Container Engine for Kubernetes(OKE) with Container Storage Interface(CSI)

Rohit Chaware
3 min readSep 9, 2021

Static volume provisioning is useful when you have an existing block volume and you want to make it available in your OKE cluster.

Let’s say the OCID of the block volume which we want to make available to the OKE cluster is `ocid1.volume.oc1.iad.aaaaaaaaaa`, it is of size: 50 Gi and it is in availability domain(AD) US-ASHBURN-AD-1.

Steps for static provisioning:

  1. Create a PersistentVolume
  2. Create a PersistentVolumeClaim
  3. Create a pod to use the PersistentVolumeClaim

1. Create a PersistentVolume

  • Use the OCID of the block volume, its size and AD in the following PV manifest: oci_static_pv.yaml
# oci_static_pv.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: static-pv
annotations:
pv.kubernetes.io/provisioned-by: blockvolume.csi.oraclecloud.com
spec:
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: failure-domain.beta.kubernetes.io/zone
operator: In
values:
- US-ASHBURN-AD-1
storageClassName: oci-bv
persistentVolumeReclaimPolicy: Retain
capacity:
storage: 50Gi
accessModes:
- ReadWriteOnce
csi:
driver: blockvolume.csi.oraclecloud.com
fsType: ext4
volumeHandle: ocid1.volume.oc1.iad.aaaaaaaaaa

Run the command:

+ kubectl apply -f oci_static_pv.yaml
persistentvolume/static-pv created
+ kubectl describe pv static-pv
Name: static-pv
Labels: <none>
Annotations: pv.kubernetes.io/provisioned-by: blockvolume.csi.oraclecloud.com
Finalizers: [kubernetes.io/pv-protection]
StorageClass: oci-bv
Status: Available
Claim:
Reclaim Policy: Retain
Access Modes: RWO
VolumeMode: Filesystem
Capacity: 50Gi
Node Affinity:
Required Terms:
Term 0: failure-domain.beta.kubernetes.io/zone in [US-ASHBURN-AD-1]
Message:
Source:
Type: CSI (a Container Storage Interface (CSI) volume source)
Driver: blockvolume.csi.oraclecloud.com
FSType: ext4
VolumeHandle: ocid1.volume.oc1.iad.aaaaaaaaaa
ReadOnly: false
VolumeAttributes: <none>
Events: <none>

2. Create a PersistentVolumeClaim

  • To ensure this PVC gets bind to the PV created in first step, you can choose to set volumeName to <name_of_the_pv> as shown below in oci_static_pvc.yaml.
# oci_static_pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: static-pvc
spec:
volumeName: static-pv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
storageClassName: oci-bv

Run the command:

+ kubectl apply -f oci_static_pvc.yaml
persistentvolumeclaim/static-pvc created

+ kubectl describe pvc static-pvc
Name: static-pvc
Namespace: default
StorageClass: oci-bv
Status: Bound
Volume: static-pv
Labels: <none>
Annotations: pv.kubernetes.io/bind-completed: yes
Finalizers: [kubernetes.io/pvc-protection]
Capacity: 50Gi
Access Modes: RWO
VolumeMode: Filesystem
Mounted By: <none>
Events: <none

3. Create a pod to use the PersistentVolumeClaim

# pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: app
image: busybox:latest
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
volumeMounts:
- name: persistent-storage
mountPath: /data
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: static-pvc

Validate:

+ kubectl apply -f pod.yaml
pod/test-pod created

+ kubectl describe pod test-pod
Name: test-pod
Namespace: default
Priority: 0
Node: 10.0.10.220/10.0.10.220
Start Time: Mon, 12 Oct 2020 16:30:52 +0530
Labels: <none>
Annotations: Status: Running
IP: 10.244.0.137
IPs:
IP: 10.244.0.137
Containers:
app:
Container ID: docker://cf44d8301ed086d63d177a0ba8818f610b858a507c9c61083aba8e1e1ad08f14
Image: busybox:latest
Image ID: docker-pullable://busybox
Port: <none>
Host Port: <none>
Command:
/bin/sh
Args:
-c
while true; do echo $(date -u) >> /data/out.txt; sleep 5; done
State: Running
Started: Mon, 12 Oct 2020 16:32:02 +0530
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/data from persistent-storage (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-mgnbz (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
persistent-storage:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: static-pvc
ReadOnly: false
default-token-mgnbz:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-mgnbz
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled <unknown> default-scheduler Successfully assigned default/test-pod to 10.0.10.220
Normal SuccessfulAttachVolume 49s attachdetach-controller AttachVolume.Attach succeeded for volume "static-pv"
Normal Pulling 15s kubelet, 10.0.10.220 Pulling image "busybox:latest"
Normal Pulled 15s kubelet, 10.0.10.220 Successfully pulled image "busybox:latest"
Normal Created 15s kubelet, 10.0.10.220 Created container app
Normal Started 15s kubelet, 10.0.10.220 Started container app

--

--

Rohit Chaware

Rohit is a Senior Member of Technical Staff at Oracle, India.