Questão 6 - Storage, PV, PVC e Pod Volume
Question 6 | Storage, PV, PVC, Pod volume
Use context: kubectl config use-context k8s-c1-H
Create a new PersistentVolume named safari-pv. It should have a capacity of 2Gi, accessMode ReadWriteOnce, hostPath /Volumes/Data and no storageClassName defined.
Next create a new PersistentVolumeClaim in Namespace project-tiger named safari-pvc . It should request 2Gi storage, accessMode ReadWriteOnce and should not define a storageClassName. The PVC should bound to the PV correctly.
Finally create a new Deployment safari in Namespace project-tiger which mounts that volume at /tmp/safari-data. The Pods of that Deployment should be of image httpd:2.4.41-alpine.
Vamos criar o nosso persistent volume, pegue o exemplo na documentação
# /opt/course/6/pv.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: safari-pv
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce # Curiosidade: O hostpath somente utiliza ReadWriteOnce
hostPath: # Esteja familiarizado com esse
path: "/Volumes/Data"
# estando na pasta do arquivo
kubectl apply -f pv.yaml
Agora vamos criar um pvc no namespace especificado. Pegue o exemplo na documentação.
# /opt/course/6/pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: safari-pvc
namespace: project-tiger
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
# estando na pasta do arquivo
kubectl apply -f pvc.yaml
# E ja podemos conferir se fez o binding
k get pv,pvc -n project-tiger
NAME CAPACITY ... STATUS CLAIM ...
persistentvolume/safari-pv 2Gi ... Bound project-tiger/safari-pvc ...
NAME STATUS VOLUME CAPACITY ...
persistentvolumeclaim/safari-pvc Bound safari-pv 2Gi ...
# E vamos criar deploy que foi pedido. Vamos criar o template e editar depois
k create deploy safari -n project-tiger --image=httpd:2.4.41-alpine --dry-run=client -o yaml > /opt/course/6/deploy.yaml
Vamos editar o arquivo.
# /opt/course/6/deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: safari
name: safari
namespace: project-tiger
spec:
replicas: 1
selector:
matchLabels:
app: safari
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: safari
spec:
containers:
- image: httpd:2.4.41-alpine
name: container
volumeMounts: # add
- name: vol # add
mountPath: /tmp/safari-data # add
volumes: # add
- name: vol # add
persistentVolumeClaim: # add
claimName: safari-pvc # add
Vamos aplicar e conferir.
# estando na pasta do arquivo
kubectl apply -f deploy.yaml
#Podemos fazer um describe no pvc ou no pod para conferir se foi montado.