Creating a pod/container in kubernetes - how to copy a bunch of files into it

1/30/2019

Sorry if this is a noob question:

I am creating a pod in a kubernetes cluster using a pod defintion yaml file.

This pod defines just one container. I'd like to ... copy a few files to a particular directory in the container.

sort of like in docker-compose:

volumes:
      - ./testHelpers/certs:/var/private/ssl/certs

Is it possible to do that at this point (point of defining the pod?)

If not, what could my alternatives be?

PS - I understand that the sample from docker-compose is very different since this maps local directory to a directory in container

-- Greg Balajewicz
kubernetes

2 Answers

1/30/2019

It's better to use volumes in pod definition. Initialize the pod before the container runs

Apart from this, you can also use ConfigMap to store certs and other config files you needed and than can access them in the container as volumes. More details here

-- Vikram Jakhar
Source: StackOverflow

1/30/2019

You should create a config map, you can do it from files or a directory.

kubectl create configmap my-config --from-file=configuration/

And then mount the config map as directory:

apiVersion: v1
kind: Pod
metadata:
  name: configmap-pod
spec:
  containers:
    - name: test
      image: busybox
      volumeMounts:
        - name: my-config
          mountPath: /etc/config
  volumes:
    - name: my-config
      configMap:
        name: my-config
-- Oz123
Source: StackOverflow