- Prepare a cluster (Single node, kubeadm, k3s, etc)
- Open browser tabs to https://kubernetes.io/docs/, https://github.com/kubernetes/ and https://kubernetes.io/blog/ (these are permitted as per the current guidelines)
Note: Leverage the docs to help you. It's unlikey you will need to recall the nuances from memory - https://kubernetes.io/docs/concepts/storage/storage-classes/
- Create a
storageclass
object namedaws-ebs
with the following specification:- The
provisioner
should bekubernetes.io/azure-disk
- The
reclaimPolicy
isDelete
allowVolumeExpansion
set tofalse
- The
- Create a
persistentvolume
based on this storage class- Note, it will not initialize unless AWS integration is configured, but the objective is to get the YAML correct.
Answer
Apply the following YAML to create the Storage Class
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: managed-premium-new
provisioner: kubernetes.io/azure-disk
reclaimPolicy: Delete
parameters:
storageaccounttype: Premium_LRS
kind: Managed
Apply the following YAML to create a Persistent Volume based on the Storage Class
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: azure-managed-disk-new
spec:
accessModes:
- ReadWriteOnce
storageClassName: managed-premium-new
resources:
requests:
storage: 5Gi
validate with:
kubectl get pvc
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-test 5Gi RWO Recycle Available aws-ebs 5
In this exercise, we will not be using storageClass
objects
- Create a
persistentVolume
object of typehostPath
with the following parameters:- 1GB Capacity
- Path on the host is /tmp
storageClassName
is ManualaccessModes
isReadWriteOnce
- Create a
persistentVolumeClaim
to the aforementionedpersistentVolume
- Create a
pod
workload to leverage this `persistentVolumeClaim
Answer
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-hostpath-1gb
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: manual
hostPath:
path: /tmp
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-hostpath-claim
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 512Mi
storageClassName: manual
---
apiVersion: v1
kind: Pod
metadata:
name: pod-with-pvc
spec:
volumes:
- name: myvol
persistentVolumeClaim:
claimName: pvc-hostpath-claim
containers:
- name: busybox
image: busybox
args:
- sleep
- "1000000"
volumeMounts:
- mountPath: "/mnt/readonly"
name: myvol
Validate with:
kubectl get po,pv,pvc
NAME READY STATUS RESTARTS AGE
pod/pod-with-pvc 1/1 Running 0 2m7s
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pv-hostpath-1gb 1Gi RWO Recycle Bound default/pvc-hostpath-claim manual 2m7s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/pvc-hostpath-claim Bound pv-hostpath-1gb 1Gi RWO manual 2m7s