I am new to Kubernetes and trying to create Volume in it like we create in Docker Compose.
Docker Compose:
version: '3'
services:
my-service:
container_name: my-container
image: my-image:0.0.1
volumes:
- ./src/main/resources:/src/main/resources
ports:
- "8082:8082"
I’m creating /src/main/resources volume
in Docker Container. Now I want to create volume like this in k8's
. What I’ve tried is:
My Deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 2
selector:
matchLabels:
app: my-label
template:
metadata:
name: my-pod
labels:
app: my-label
spec:
containers:
- name: my-container
image: my-image:0.0.1
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /src/main/resources
name: my-volume
volumes:
- name: my-volume
hostPath:
path: /home/my-user/src/main/resources
---
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: LoadBalancer
selector:
app: my-label
ports:
- port: 8082
targetPort: 8082
nodePort: 31802
Above is successfully creating the volume but it is not pasting the contents of /home/my-user/src/main/resources
in volume /src/main/resources
. I’ve checked it using command kubectl exec -it pod-name -- /bin/sh
.
Guide me how can I create volume in k8’s with the content?