Table of contents
π Kudos to you for conquering ConfigMaps and Secrets in Kubernetes yesterday.
π₯ You're on fire! π₯
What are Persistent Volumes in k8s
- In Kubernetes, a Persistent Volume (PV) is a piece of storage in the cluster that has been provisioned by an administrator. A Persistent Volume Claim (PVC) is a request for storage by a user. The PVC references the PV, and the PV is bound to a specific node. Read official documentation of Persistent Volumes.
β° Wait, wait, wait! π£ Attention all #90daysofDevOps Challengers. πͺ
- Before diving into today's task, don't forget to share your thoughts on the #90daysofDevOps challenge πͺ Fill out our feedback form (https://lnkd.in/gcgvrq8b) to help us improve and provide the best experience π Your participation and support is greatly appreciated π Let's continue to grow together π±
Today's tasks:
Task 1:
Create a Persistent Volume using a file on your node.
First create a file of volumes in your node
mkdir volumes
cd volumes
pwd
- Come to your Master server and create a file of persistent volume
# vim persistentvolume.yml
-------------------------------------------------------------------------------
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-volume
namespace: django-app
labels:
app: mysql
spec:
storageClassName: manual
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/home/ubuntu/volumes" # This path you should take from Node by creating a volumes folder
kubectl apply -f persistentvolume.yml -n django-app
kubectl get pv -n django-app
- Now that you've created a persistent volume, it's not enough to simply create it. You need to claim access to that volume by using a persistent volume claim.
# vim persistent-volume-claim.yml
-------------------------------------------------------------------------------
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
namespace: django-app
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
kubectl apply -f persistent-volume-claim.yml -n django-app
kubectl get pvc -n django-app
- Now your volumes and volume-claim should to deployment
# vim deployment.yml
-------------------------------------------------------------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deploymnet
namespace: django-app
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:8
ports:
- containerPort: 3306
env:
- name: MYSQL_DATABASE
valueFrom:
configMapKeyRef:
name: mysql-config
key: MYSQL_DATABASE
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_ROOT_PASSWORD
voumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
kubectl apply -f deployment.yml -n django-app
kubectl get pods -n django-app
- Go to your node and use this command
cd volumes
ls
Task 2:
Now, I'd like to run a pod by selecting any pod from the node.
goto node and do
# docker ps
- To enter into the pod use this command
# docker exec -it <container id> bash
- Use this command for to enter into you database
# mysql -u root -p
and enter your password
- If you want to see your database use this command
# show databases;
Happy Learning
Thanks For Reading! :)
-Sri Parthuππ₯
Β