Create a PersistentVolumeClaim
Use the following claim.json file to create a PersistentVolumeClaim:
$ cat claim.json
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "myvol"
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "4Gi"
}
},
"storageClassName": "ceph-xfs"
}
}
$ kubectl apply -f claim.json
Check the status of the PersistentVolumeClaim
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
myvol Bound pvc-8987ad38-3888-4dd8-94c1-39868792c37e 4Gi RWO ceph-xfs 35m
Create a ReplicationController that uses the Ceph backed PVC
Use the following pod.yaml file to create a ReplicationController:
$ cat pod.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: server
spec:
replicas: 1
selector:
role: server
template:
metadata:
labels:
role: server
spec:
containers:
- name: server
image: nginx
volumeMounts:
- mountPath: /var/lib/www/html
name: myvol
volumes:
- name: myvol
persistentVolumeClaim:
claimName: myvol
$ kubectl apply -f pod.yaml
Check the status of the ReplicationController pod
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
csi-rbdplugin-hsnjl 3/3 Running 0 6d9h
csi-rbdplugin-md8zd 3/3 Running 0 6d9h
csi-rbdplugin-nhc6t 3/3 Running 0 6d9h
csi-rbdplugin-provisioner-549c6b54c6-2ts2x 6/6 Running 0 6d9h
csi-rbdplugin-provisioner-549c6b54c6-8f7v9 6/6 Running 0 6d9h
csi-rbdplugin-provisioner-549c6b54c6-l59nr 6/6 Running 1 6d9h
server-48g2s 1/1 Running 0 39m
$ kubectl describe pod server-48g2s
Name: server-48g2s
Namespace: default
Priority: 0
Node: node06ob100/172.27.100.105
...
Volumes:
myvol:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: myvol
ReadOnly: false
default-token-bptwd:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-bptwd
Optional: false
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 41m default-scheduler Successfully assigned default/server-48g2s to node06ob100
Normal SuccessfulAttachVolume 41m attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-8987ad38-3888-4dd8-94c1-39868792c37e"
Normal Pulling 41m kubelet Pulling image "nginx"
Normal Pulled 41m kubelet Successfully pulled image "nginx" in 7.936656052s
Normal Created 41m kubelet Created container server
Normal Started 41m kubelet Started container server
Log in to the container and check that the volume is mounted
$ kubectl exec -it server-48g2s -- bash
root@server-48g2s:/#
root@server-48g2s:/# df -h
Filesystem Size Used Avail Use% Mounted on
...
/dev/rbd0 4.0G 33M 4.0G 1% /var/lib/www/html
root@server-48g2s:/# exit
Now our pod has an RBD mount!