-
Create a persistent volume claim
alpha-claim
in the namespace default with:- storageClass:
local-path
- access mode:
ReadWriteOnce
- Capacity:
1Gi
- storageClass:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: alpha-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 1Gi
or
kubectl apply -f pvc.yaml
- Create a pod called
volume-user
that uses the imageregistry.sighup.io/workshop/nginx:alpine
that mounts this volume on/usr/share/nginx/html
.
apiVersion: v1
kind: Pod
metadata:
name: volume-user
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: alpha-claim
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
or
kubectl apply -f pod.yaml
- Enter the pod
volume-user
and create a fileindex.html
inside the mounted directory with arbitrary content.
kubectl exec -it volume-user -- bash
root@volume-user:/# touch /usr/share/nginx/html/index.html
root@volume-user:/# echo 'hello' > /usr/share/nginx/html/index.html
exit
kubectl exec -it volume-user -- cat /usr/share/nginx/html/index.html
- Delete and recreate the pod
kubectl delete pod volume-user
kubectl apply -f pod.yaml
kubectl exec -it volume-user -- cat /usr/share/nginx/html/index.html
- Check that the file
/usr/share/nginx/html/index.html
inside the pod is still present.