Mount Storage Class in Kubernetes Kubeadm cloud controll manager
Step 1. Create New User
Attach Inline Policy.
After Create new user create secret access keys.
save this access keys
create generic secret with this command
kubectl create secret generic aws-secret \
--namespace kube-system \
--from-literal "key_id=${AWS_ACCESS_KEY_ID}" \
--from-literal "access_key=${AWS_SECRET_ACCESS_KEY}"
Step 2. Deploy EBS CSI driver
kubectl apply -k "github.com/kubernetes-sigs/aws-ebs-csi-driver/deploy/kubernetes/overlays/stable/?ref=release-1.33"
Step 3: Create a StorageClass for AWS EBS
- Create a StorageClass YAML file using nano.
nano storageclass.yaml
Paste this yaml in a nano editor.
Add the following content to the storageclass.yaml file. This example uses the gp2 storage class, which is a general-purpose SSD in AWS.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: gp2
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
fsType: ext4
encrypted: "true"
volumeBindingMode: WaitForFirstConsumer
- Apply the storageclass.yaml file.
kubectl apply -f storageclass.yaml
Step 4: Create a PersistentVolumeClaim
- Create a PersistentVolumeClaim YAML Use a text editor such as nano:
nano pvc.yaml
- Paste this yaml in a nano editor.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ebs-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: gp2
kubectl apply -f pvc.yaml
Step 5: Use the PVC in a Pod
Create a Pod YAML file using nano.
nano pod.yaml
Add the following content to the pod.yaml file. This example mounts the PVC to a directory inside the Pod.
apiVersion: v1
kind: Pod
metadata:
name: ebs-pod
spec:
containers:
- name: my-container
image: nginx
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: ebs-storage
volumes:
- name: ebs-storage
persistentVolumeClaim:
claimName: ebs-pvc
- Apply the pod.yaml file.
kubectl apply -f pod.yaml
Step 6: Verify the Setup
- Check the status of the PVC to ensure it is bound.
kubectl get pvc ebs-pvc
- Check the status of the Pod to ensure it is running
$ kubectl get pod ebs-pod
Summary
You have successfully created a StorageClass for AWS EBS, a PersistentVolumeClaim, and used it in a Pod. The PVC allows the Pod to persist data, which will remain even if the Pod is deleted.
Step 7: Cleanup
- To clean up the resources, delete the Pod, PVC, and StorageClass.
kubectl delete pod ebs-pod
- You have successfully completed Storage Class in Kubernetes runbook.