Ioan Kats
Ioan Kats

Reputation: 521

Docker Volume on Kubernetes Cluster

I am trying to deploy a docker image on a kubernetes cluster.

What I want to achieve on the cluster is the same output as I achieve when I run this command locally (The output will be some generated files)

sudo docker run \
  --env ACCEPT_EULA="I_ACCEPT_THE_EULA" \
  --volume /my-folder:/opt/data \
  --volume /my-folder:/opt/g2 \
  test/installer:3.0.0

What I have created for the deployment on the kubernetes side is this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  namespace: default
spec:
  template:
    metadata:
      name: test
      labels:
        app: test
    spec:
      volumes:
        - name: nfs-volume
          nfs:
            # URL for the NFS server
            server: SERVER_HOSTNAME
            path: PATH
      containers:
      - name: test-container
        image: DOCKER_IMAGE
        resources:
          requests:
            memory: "1Gi"
            cpu: "1000m"
          limits:
            memory: "2Gi"
            cpu: "2000m"
        env:
          - name: ACCEPT_EULA
            value: "I_ACCEPT_THE_EULA"
        volumeMounts:
          - name: nfs-volume
            mountPath: /var/nfs
  replicas: 1
  selector:
    matchLabels:
      app: test
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

The problem that I have is wrt/ to these two arguments, I can not understand how to perform the related actions on the k8 side. Any suggestions ?

--volume /my-folder:/opt/data
--volume /my-folder:/opt/g2

Currently I get errors like: cp: cannot create directory '/opt/test': Permission denied

Upvotes: 1

Views: 281

Answers (1)

Bijan
Bijan

Reputation: 6772

try this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  namespace: default
spec:
  template:
    metadata:
      name: test
      labels:
        app: test
    spec:
      volumes:
        - name: my-folder
          hostPath:
            path: /my-folder
      containers:
      - name: test-container
        image: test/installer:3.0.0
        resources:
          requests:
            memory: "1Gi"
            cpu: "1000m"
          limits:
            memory: "2Gi"
            cpu: "2000m"
        env:
          - name: ACCEPT_EULA
            value: "I_ACCEPT_THE_EULA"
        volumeMounts:
          - name: nfs-volume
            mountPath: /var/nfs
          - name:  my-folder
            mountPath: /opt/data
          - name:  my-folder
            mountPath: /opt/g2
  replicas: 1
  selector:
    matchLabels:
      app: test
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

Upvotes: 1

Related Questions