Append/Extend LD_LIBRARY_PATH using Kubernetes Source Code

9/26/2018

When a pod is being scheduled, I dynamically (and transparently) mount some shared libraries folder into the client containers through Kubernetes DevicePlugins. Now, in the container I want to append/extend these dynamically mounted shared libraries to LD_LIBRARY_PATH environmental variables.

Inside the container: This can be achieved by running command on the bash "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/some/new/directory"

From the Host: I can add the export command to the pod.yaml file under pod.spec.command and args.

But, I wanted to do it transparently without the client/admin specifying it in the yaml file using Kubernetes DevicePlugins or Extended-Schedulers

I am looking method/hack by which I can append/extend the LD_LIBRARY_PATH inside the container only using Kubernetes source code.

Thanks.

-- Ganapathy Raman
kubernetes
ld

2 Answers

9/27/2018

If i understand your issue, all you need is to transparently add ld_library_path to the pod as it is scheduled. Maybe you can try to use mutatingadmission webhook. Which allows you to send patch command to kubernetes to modify the manifest. Theres a good documentation from banzai cloud. I have not tried it myself. https://banzaicloud.com/blog/k8s-admission-webhooks/

-- Bal Chua
Source: StackOverflow

9/26/2018

You can just bake into your Dockerfile and create an image that you use in Kubernetes for that. No need to hack the Kubernetes source code.

In your Dockerfile in some line:

ENV LD_LIBRARY_PATH /extra/path:$LD_LIBRARY_PATH

Then:

docker build -t <your-image-tag> .
docker push <your-image-tag>

Then, update your pod or deployment definition and deploy to Kubernetes.

Hope it helps.

-- Rico
Source: StackOverflow