How do i add local directory to deployment in EKS?

2/17/2022

I have mysql deployment.yaml, in which i have some data at mysql/data directory which is in local. I want mount this data in deployment. After referring blogs some recommend hostpath. Since we are not doing ssh into nodes, i cant recommend or use hostpath. is there any way i can do with pv with EBS or any other way ? Thanks in advance.

-- Akshay Awate
kubernetes

1 Answer

2/17/2022

Here's a minimum spec using EKS default gp2 storage class to get you started.

apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  clusterIP: None
  selector:
    app: mysql
  ports:
  - port: 3306
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql
spec:
  storageClassName: gp2
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 5Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  containers:
  - name: mysql
    image: mysql:8.0.28
    imagePullPolicy: IfNotPresent
    env:
    - name: MYSQL_ROOT_PASSWORD
      value: password
    ports:
    - containerPort: 3306
    volumeMounts:
    - name: mysql
      mountPath: /var/lib/mysql
  volumes:
  - name: mysql
    persistentVolumeClaim:
      claimName: mysql

You can connect to the mysql via kubectl run -it --rm --image=mysql:8.0.28 --restart=Never mysql-client -- mysql -h mysql -ppassword

-- gohm'c
Source: StackOverflow