EKS Storage - Storage Classes, Persistent Volume Claims¶
Step-01: Introduction¶
- We are going to create a MySQL Database with persistence storage using AWS EBS Volumes
| Kubernetes Object | YAML File |
|---|---|
| Storage Class | 01-storage-class.yml |
| Persistent Volume Claim | 02-persistent-volume-claim.yml |
| Config Map | 03-UserManagement-ConfigMap.yml |
| Deployment, Environment Variables, Volumes, VolumeMounts | 04-mysql-deployment.yml |
| ClusterIP Service | 05-mysql-clusterip-service.yml |
Kubernetes Manifests¶
#04-mysql-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.6
env:
- name: MYSQL_ROOT_PASSWORD
value: dbpassword11
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
- name: usermanagement-dbcreation-script
mountPath: /docker-entrypoint-initdb.d #https://hub.docker.com/_/mysql Refer Initializing a fresh instance
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: ebs-mysql-pv-claim
- name: usermanagement-dbcreation-script
configMap:
name: usermanagement-dbcreation-script
Step-02: Create following Kubernetes manifests¶
Create Storage Class manifest¶
- https://kubernetes.io/docs/concepts/storage/storage-classes/#volume-binding-mode
- Important Note:
WaitForFirstConsumermode will delay the volume binding and provisioning of a PersistentVolume until a Pod using the PersistentVolumeClaim is created.
Create Persistent Volume Claims manifest¶
# Create Storage Class & PVC
kubectl apply -f kube-manifests/
# List Storage Classes
kubectl get sc
# List PVC
kubectl get pvc
# List PV
kubectl get pv
Create ConfigMap manifest¶
- We are going to create a
usermgmtdatabase schema during the mysql pod creation time which we will leverage when we deploy User Management Microservice.
Create MySQL Deployment manifest¶
- Environment Variables
- Volumes
- Volume Mounts
Create MySQL ClusterIP Service manifest¶
- At any point of time we are going to have only one mysql pod in this design so
ClusterIP: Nonewill use thePod IP Addressinstead of creating or allocating a separate IP forMySQL Cluster IP service.
Step-03: Create MySQL Database with all above manifests¶
# Create MySQL Database
kubectl apply -f kube-manifests/
# List Storage Classes
kubectl get sc
# List PVC
kubectl get pvc
# List PV
kubectl get pv
# List pods
kubectl get pods
# List pods based on label name
kubectl get pods -l app=mysql
Step-04: Connect to MySQL Database¶
# Connect to MYSQL Database
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -pdbpassword11
# Verify usermgmt schema got created which we provided in ConfigMap
mysql> show schemas;
AWS EKS - Elastic Kubernetes Service - Masterclass¶
Step-05: References¶
- We need to discuss references exclusively here.
- These will help you in writing effective templates based on need in your environments.
- Few features are still in alpha stage as on today (Example:Resizing), but once they reach beta you can start leveraging those templates and make your trials.
- EBS CSI Driver: https://github.com/kubernetes-sigs/aws-ebs-csi-driver
- EBS CSI Driver Dynamic Provisioning: https://github.com/kubernetes-sigs/aws-ebs-csi-driver/tree/master/examples/kubernetes/dynamic-provisioning
- EBS CSI Driver - Other Examples like Resizing, Snapshot etc: https://github.com/kubernetes-sigs/aws-ebs-csi-driver/tree/master/examples/kubernetes
- k8s API Reference Doc: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#storageclass-v1-storage-k8s-io
🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99
$84.99
81% OFF
APRIL2026
Enroll Now on Udemy
🎉 Offer
