How to copy files to container in kubernetes yaml

3/7/2020

I understand that files / folders can be copied into a container using the command:

kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir

However, I am looking to do this in a yaml file

How would I go about doing this? (Assuming that I am using a deployment for the container)

-- Kyle Blue
containers
docker
kubectl
kubernetes
kubernetes-deployment

2 Answers

3/7/2020

You cannot, mapping local files from your workstation is not a feature of Kubernetes.

-- coderanger
Source: StackOverflow

3/8/2020

The way you are going is wrong direction. Kubernetes does this with serveral ways.

first, think about configmap

https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap

You can easily define the configuration files for your application running in container

If you do know the files or folders is exist on worker nodes, you can use hostPath to mount it into container with nominated nodeName: node01 in k8s yaml.

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

if the files or folders are generated temporarily, you can use emptyDir

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

-- BMW
Source: StackOverflow