How do I upload my own binary (Python module) as a resource for my Kubernetes application?

3/9/2020

I have my own Python module (an '.so' file that I'm able to import locally) that I want to make available to my application running in Kubernetes. I am wholly unfamiliar with Kubernetes and Helm, and the documentation and attempts I've made so far haven't gotten me anywhere.

I looked into ConfigMaps, trying kubectl.exe create configmap mymodule --from-file=MyModule.so, but kubectl says "Request entity too large: limit is 3145728". (My binary file is ~6mb.) I don't know if this is even the appropriate way to get my file there. I've also looked at Helm Charts, but I see nothing about how to package up a file to upload. Helm Charts look more like a way to configure deployment of existing services.

What's the appropriate way to package up my file, upload it, and use it within my application (ensuring that Python will be able to import MyModule successfully when running in my AKS cluster)?

-- user655321
dockerfile
kubernetes
kubernetes-helm
python

2 Answers

3/9/2020

Kubernetes is a container orchestration engine. A binary / package from that perspective is part of the application running within a container. As such, normally you would add your package to the container during its build process and then deploy new version of the container.

Details will depend on your application and build pipeline, but generally in some way (using package repository or copying the package manually) you would make the package available on the build agent and then copy it into the container and install within the dockerfile.

-- Daniel
Source: StackOverflow

3/9/2020

The python module should be added to the container image that runs in Kubernetes, not to Kubernetes itself.

The current container image running in Kubernetes has a build process, usually controlled by a Dockerfile. That container image is then published to an image repository where the container runtime in Kubernetes can pull the image in from and run the container.

If you don't currently build this container, you may need to create your own build process to add the python module to the existing container. In a Dockerfile you use the FROM old/image:1.7.1 and then add your content.

FROM old/image:1.7.1
COPY MyModule.so /app/

Publish the new container image to an ECR (Elastic Container Registry) so it is available for use in your AKS cluster.

The only change you might need to make in Kubernetes then is to set the image for the deployment to the newly published image.

Here is a simple end to end guide for a python application.

-- Matt
Source: StackOverflow