set environment variables within a mountPath in Kubernetes - kubernetes

we have deployed an application in Kubernetes as deployment and stored the logs in a folder named /podlogs. whenever the pod has taken the restart, it will create a new folder named with the latest pod name inside the app-log folder and store the actual log files. For example this new folder could be /podlogs/POD_Name
Previously we have mounted /podlogs to ELK and azure blob containers.
By using the subPath, we would like to also mount the /podlogs/POD_Name to a second mount.
How can we pass the env variable in the mount path along with the subPath?

See the DownwardAPI https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/
It is possible to expose the pod name as a env variable or to mount
It is conceivable you could then mount or expose this to the ELK container

Related

Adding configMap as a volume to a container in an OCP deployment

I have a deployment of 3 containers in OCP. In one of them there is a configuration file which I want to mount to the container via configMap. I created a configMap and tried to mount it to the container but it didn't work.
I use 'csanchez jenkins kubernetes' plugin, so the deployment is configured in a yml file and written in xml format. I found this in the docs of the csanchez plugin, tried to add the necessary field to the container field, but it did not worked.
I want to connect it to a single container and not to the pod, because the path of the config file is the same in another one, but the config file differs.
I tried to add to the container field:
<volumeMounts>
<org.csanchez.jenkins.plugins.kubernetes.volumes.configMapVolume>
<mountPath>/opt/selenium/config.json</mountPath>
<configMapName>selenium-config-map</configMapName>
</org.csanchez.jenkins.plugins.kubernetes.volumes.configMapVolume>
</volumeMounts>
I tried to switch volumeMounts with volumes and it also didn't work.

Kubernetes: Merge files from a volume into a target directory, without using subPath

Using subPath, I can mount individual files from a volume into a container directory while still retaining the other files already present in the directory.
However, subPath requires creating an entry in the manifest for each file to be mounted.
I want to mount all files in a volume without naming each file explicitly in the manifest.
As far as possible I do not want to use init containers.
Is this possible in Kubernetes?

Loading secrets as ENV from init container

We are storing secrets in GCP Secret Manager, during an app deployment we using an init container which fetches secrets and places them in volume (path). Going forward we need the requirement is to load the secrets as env variable on the main container needing the secrets from the init container, instead of the paths. How can it be achieved ? Any workaround ?
Thank you !
You can copy from GSM into a Kubernetes Secret and then use that in a normal envFrom or you can have the init container write a file into a shared emptyDir volume and then change the command on the main container to be something like command: [bash, -c, "source /shared/env && exec original command"]. The latter requires you rewrite the command fully though which is annoying.

Passing an external file as an argument to a Kubernetes POD

I have a requirement of deploying a container in Kubernetes. The image that I have created expects certain arguments, one of which is a file that is placed at an external location, say Github.
How would I be able to mount the path of this external file so that when I deploy this container and pass the arguments and file can be passed to the container.
Currently, the complete path of the file is given
args: ["update","--changesetFile","https://github.com/lbg-gcp-foundation/ep-liquibase-db-propagation/blob/db-prop-pipeline/resources/release1.0/customer/ddl/db.changelog.customer.ddl.rel1.sql","--url=jdbc:cloudspanner:/projects/eplus-cus-02-ide-d08b/instances/spn-01/databases/spd-01","--labels","base","--tag","0.0.1-test"]
how to mount this path "https://github.com/lbg-gcp-foundation/ep-liquibase-db-propagation/blob/db-prop-pipeline/resources/release1.0/customer/ddl/db.changelog.customer.ddl.rel1.sql"
There was a thing called gitRepo as a mountable Volume, but that is deprecated now. https://kubernetes.io/docs/concepts/storage/volumes/#gitrepo
As the link above states, you should use an init container to clone the repo an mount it as an emptyDir.
A curl might also be sufficient to get the file.

How to mimic Docker ability to pre-populate a volume from a container directory with Kubernetes

I am migrating my previous deployment made with docker-compose to Kubernetes.
In my previous deployment, some containers do have some data made at build time in some paths and these paths are mounted in persistent volumes.
Therefore, as the Docker volume documentation states,the persistent volume (not a bind mount) will be pre-populated with the container directory content.
I'd like to achieve this behavior with Kubernetes and its persistent volumes, How can I do ? Do I need to add some kind of logic using scripts in order to copy my container's files to the mounted path when data is not present the first time the container starts ?
Possibly related question: Kubernetes mount volume on existing directory with files inside the container
I think your options are
ConfigMap (are "some data" configuration files?)
Init containers (as mentioned)
CSI Volume Cloning (clone combining an init or your first app container)
there used to be a gitRepo; deprecated in favour of init containers where you can clone your config and data from
HostPath volume mount is an option too
An NFS volume is probably a very reasonable option and similar from an approach point of view to your Docker Volumes
Storage type: NFS, iscsi, awsElasticBlockStore, gcePersistentDisk and others can be pre-populated. There are constraints. NFS probably the most flexible for sharing bits & bytes.
FYI
The subPath might be of interest too depending on your use case and
PodPreset might help in streamlining the op across the fleet of your pods
HTH