Is there a recommended way of copying files from a pod periodically. I have a pod with an empty storage and no persistence volume. So wanted to periodically copy some log files from the pod containers to a nfs share. I can run a cronjob and invoke kubectl copy but wondering if there is a better way of doing this?
I think the better way for your case is to mount the NFS volume on your Pod to directly write the logs on it : https://kubernetes.io/docs/concepts/storage/volumes/#nfs
Run a cronjob as a scheduled job to copy the files to target location
Related
We have created a deployment in the EKS cluster. Underlying pods are supposed to have existing content inside a particular directory which was created through the Dockerfile copy command. But when the pod is created an external EFS volume is mounted on the same directory path due to some application requirements. When we login to the pod and check the contents we found that the existing files have been overwritten by the EFS volume contents. We would like to have both the file contents in place once the EFS volume is mounted on the Pod. Please help us to achieve this.
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)
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
You cannot, mapping local files from your workstation is not a feature of Kubernetes.
I want to transfer my files generated by one of the pod of my application to the Kubernetes cronjob pod.
Is there any method to transfer files between the two pods of a cluster?
Create a persistent-volume and mount the same volume to both the containers
You can use hostdir if you don't want to persist data. however, you can use PVC and any type of shared volume to store data which can be accessible by both pods cronjobs & pod.
I am trying to setup the AKS in which I have used azure disk to mount the source code of the application. When I am using kubectl describe pods command then also it is showing as mounted but I dont know how may I copy the code into that?
I got some recommendations that use kubectl cp command but my pod name is changing each time whenever I am deploying so please let me know what should i do?
you'd need to copy files to the disk directly (not to the pod). you can use your pod or worker node to do that. You can use kubectl cp to copy files to the pod and then move it to the mounted disk like you normally would. or you can ssh to the worker node and copy files over ssh to the node and put files to the mounted disk.
I have mounted a hostpath volume in a Kubernetes container. Now I want to mount a configmap file onto the hostpath volume.
Is that possible?
Not really, a larger question would be would you'd want to do that?
The standard way to add configurations in Kubernetes is using ConfigMaps. They are stored in etcd and the size limit is 1MB. When your pod comes up the configuration is mounted on a pod mount point that you can specify in the pod spec.
You may want the opposite which is to use a hostPath that has some configuration and that's possible. Say, that you want to have some config that is larger than 1MB (which is not usual) and have your pod use it. The gotcha here is that you need to put this hostPath and the files in all your cluster nodes where your pod may start.
No. The volume mounts are all about pushing data into pods or persisting data that originates in a pod, and aren't usually a bidirectional data transfer mechanism.
If you want to see what's in a ConfigMap, you can always kubectl get configmap NAME -o yaml to dump it out.
(With some exceptions around things like the Docker socket, hostPath volumes aren't that common in non-Minikube Kubernetes installations, especially once you get into multi-host setups, and I'd investigate other paths to do whatever you're using it for now.)