Introduction to Persistent Volumes in Kubernetes
Kubernetes Persistent Volumes (PVs) provide a way to persist data across pod restarts and deployments. One popular option for PVs is AWS Elastic Block Store (EBS). In this article, we will explore how to use EBS with Kubernetes PVs.
Prerequisites
- AWS account with EBS enabled
- Kubernetes cluster running on AWS
- kubectl command-line tool installed
Creating an EBS Volume
To create an EBS volume, you can use the AWS CLI or the AWS Management Console. Here is an example of how to create a 10GB EBS volume using the AWS CLI:
aws ec2 create-volume --volume-type gp2 --size 10 --availability-zone us-west-2aCreating a Kubernetes Persistent Volume
To create a Kubernetes PV, you need to create a YAML file that defines the PV. Here is an example YAML file that defines a PV using an EBS volume:
apiVersion: v1
kind: PersistentVolume
metadata:
name: ebs-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
awsElasticBlockStore:
volumeID: vol-12345678
fsType: ext4You can then apply this YAML file using the kubectl command-line tool:
kubectl apply -f ebs-pv.yamlUsing the Persistent Volume in a Pod
To use the PV in a pod, you need to create a YAML file that defines the pod and the PV claim. Here is an example YAML file that defines a pod that uses the EBS PV:
apiVersion: v1
kind: Pod
metadata:
name: ebs-pod
spec:
containers:
- name: ebs-container
image: ubuntu
volumeMounts:
- name: ebs-pvc
mountPath: /mnt
volumes:
- name: ebs-pvc
persistentVolumeClaim:
claimName: ebs-pvcYou also need to create a YAML file that defines the PV claim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ebs-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10GiYou can then apply these YAML files using the kubectl command-line tool:
kubectl apply -f ebs-pod.yaml
kubectl apply -f ebs-pvc.yaml
0 Comments
Share your thoughts
Your email address will not be published. Required fields are marked *
To leave a comment, please sign in to your account.