Passing an external file as an argument to a Kubernetes POD - kubernetes

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.

Related

set environment variables within a mountPath in 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

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?

How can I use an initContainer to set an environment variable or modify the launch command of the main container?

I have an application that needs to know it's assigned NodePort. Unfortunately it is not possible to write a file to a mountable volume and then read that file in the main container. Therefore, i'm looking for a way to either have the initContainer set an environment variable that gets passed to the main container or to modify the main pod's launch command to add an additional CLI argument. I can't seem to find any examples or documentation that would lead me to this answer. TIA.
There's no direct way so you have to get creative. For example you can make a shared emptyDir mount that both containers can access, have the initContainer write export FOO=bar to that file, and then change the main container command to something like [bash, -c, "source /thatfile && exec originalcommand"]

Is there a way to specify a tar file of docker image in manifest file for kubernetes?

Is there a way to specify a tar file of a docker image in a deployment manifest file for kubernetes? The nodes have access to a mounted network drive that will have the tar file. There's a post where the image is loaded by docker on each node, but I was wondering if there's a way just to specify the tar file and have Kubernetes do the loading and running.
--edit--
To be more exact, say I have a mounted network drive on each node, is there a way with just the manifest file to instruct kubernetes to load that image directly from tar file and not have to put it into a docker registry.
In general, no, Kubernetes can only access container images from a registry, not from a network drive, see documentation.
However, you could have a private registry inside your cluster (see docs). You could also have the images locally on the nodes (pre-pulled images) and have Kubernetes access them from there by setting imagePullPolicy to Never (see docs).
You have provided quite limited information about your environment and how it would looks like.
Two things comes to my mind.
Use initContainer to download this file using wget or similar.
Init containers are exactly like regular containers, except:
Init containers always run to completion.
Each init container must complete successfully before the next one starts.
That way you can be sure that tar file will be downloaded before your application will start. Example can be found here
Use Mount Volume
In your deployment, statefulset, pod (not sure what you are using), you can Mount Volume into pod. After that you will be able to inside pod specified path from volume. Please keep in mind that you have to use proper access modes.
To run .tar file you can use some bash commands like in this documentation.

Kubernetes - Share single file between containers (within the same pod)

I have an API that describes itself through an openapi3 file. This app is contained in a pod that also has a sidecar app that is supposed to read this file at startup time.
My probleme is how my sidecar app can read the openapi file from the other container ?
I know I could do it using a volume (emptyDir) and modify the command so my api copies the file at startup time. I'd rather not go this route. I have been looking for a feature, where I define a volume which is mapped to an existing folder in my app, but without being empty. Is there such a thing ?
One of the simplest approaches is to use emptyDir: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
In your container that generates the file that needs to be shared, mount emptyDir volume with write access and copy the file there. In your sidecar that needs to read the file, mount the same volume as read only and read the file.
With this pattern, all containers in the pod can have access to the same file system with read / write as needed.