-
Notifications
You must be signed in to change notification settings - Fork 19
State Persistence
Yasser Sinjab edited this page Apr 9, 2019
·
5 revisions
Create PersistentVolumeClaim named "xpvc" with access mode ReadWriteOnce and resources 2 GB:
nano pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: xpvc
spec:
storageClassName: normal
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
kubectl apply -f pvc.yaml
Create busybox that run a command 'cp /etc/passwd /etc/xvolume/' pod. Map "/etc/xvolume" in the pod to persistent volume using the previous PersistentVolumeClaim "xpvc":
kubectl run busybox1 --image=busybox --restart=Never -o yaml --dry-run -- /bin/sh -c 'cp /etc/passwd /etc/xvolume/' > pod1.yam
kubectl apply -f pod1.yaml
# Edit pod.yaml and add volumes and volumeMounts
...
spec:
volumes:
- name: xpv
persistentVolumeClaim:
claimName: xpvc
...
# volumeMounts for the container
...
volumeMounts:
- mountPath: "/etc/xvolume"
name: xpv
...
Create the same as the previous pod with same configuration but override the command to 'cat /etc/xvolume/passwd':
kubectl run busybox2 --image=busybox --restart=Never -o yaml --dry-run -- /bin/sh -c 'cat /etc/xvolume/passwd' > pod2.yaml
kubectl apply -f pod2.yaml
kubectl logs busybox2