Kubernetes - How to use files from a directory in a pod?

5/11/2018

I have a builder image / container which is supposed to run tests on a directory with tests sources.

The container is run in a Kubernetes pod, in AWS EKS, through helm test. I.e. not docker, so I can't simply use -v volume mount.

I am struggling to find the right way to bring this directory to the container, in a simple way. This is a Helm template I have. All works except for the volume.

apiVersion: v1
kind: Pod
metadata:
  name: "{{ .Release.Name }}-gatling-test"
  annotations:
    "helm.sh/hook": test-success
spec:
  restartPolicy: Never
  containers:
  - name: {{ .Release.Name }}-gatling-test
    image: {{ .Values.builderImage }}
    command: ["sh", "-c", 'mvn -B gatling:test -pl csa-testing -DCSA_SERVER={{ template "project.fullname" . }} -DCSA_PORT={{ .Values.service.appPort }}']
    ## TODO: The builder image also counts with having /tmp/build, so it needs a mount: -v '${job.WORKDIR}:/tmp/build'
    volumeMounts:
    - name: mavenRepoToBuild
      mountPath: /tmp/build
    volumes:
    - name: mavenRepoToBuild
      hostPath:
        path: {{.Values.fromJenkins.WORKDIR}}

I've read on few places that it can't be done directly. So what's the easy way to do it indirectly? Zip and upload to S3 and download? Or add it to the image as a layer? Or should I create a Kubernetes volume resource?

-- Ondra Žižka
docker
docker-volume
kubernetes
kubernetes-helm

1 Answer

5/11/2018

The hostPath directory or file must be existing on all your cluster nodes.

You can attach some types on the hostPath to determine whether its files or directories.

List of types you can use on hostpath can be found in kubernetes documentation.

https://kubernetes.io/docs/concepts/storage/volumes/

Btw, what error do you get? Permission denied? You can do helm dry-run to see the rendered template.

-- Bal Chua
Source: StackOverflow