Skip to content

Latest commit

 

History

History
70 lines (53 loc) · 893 Bytes

pv-pvc.md

File metadata and controls

70 lines (53 loc) · 893 Bytes

Creating a Persistent volume

vi pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: first-pv
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /tmp/data

kubectl apply -f pv.yaml

Creating a Persistent Volume Claim (PVC)

vi pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc
spec:
  storageClassName: manual
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

kubectl apply -f pvc.yaml

Using a volume in a pod

vi pvpod.yaml

kind: Pod
apiVersion: v1
metadata:
  name: pvc-pod
spec:
  containers:
    - name: test1
      image: nginx
      volumeMounts:
      - mountPath: "/data"
        name: vol1
  volumes:
    - name: vol1
      persistentVolumeClaim:
        claimName: pvc

kubectl apply -f pvpod.yaml