Skip to content

SHORTY – Add binaries to a Kubernetes Pod using an Init container

In this short article, I want to show you, how you easily can “inject” binaries to a Kubernetes Pod / Container, without building your own customized image for it. We can do so by using Init-Containers.

Normally, when you want to add more functionality to an existing container image in form of additional tools or binaries you want to install, you have to build your own customized image on top of a container image, that already exists. But there is a small dirty workaround on that. You could also use an Init-Container instead where you download the needed binaries and “expose” them as a volume to the main container of the pod. I want to say it right away, there is a limited usecase in doing so, if you have to install a lot of other dependencies in order to get the tool to work, this will hardly work (like having Python dependencies). It’s easy enough for compiled and self-contained binaries.

In this article, we will “inject” the tool called Gomplate into our ArgoCD Repo Server pod. If you want to know how to setup and use ArgoCD, feel free to read more about it here. Gomplate is self-contained and needs no other dependencies fulfilled to work. To create an init container in the Repo server pod, we patch the deployment of it and add the following lines.

      - name: tools
        emptyDir: {}
      - name: download-additional-tools
        image: alpine:3.15
        - sh
        - -c
        - echo Downloading additional tools;
          wget -O /tools/gomplate;
          chmod 755 /tools/gomplate;
          echo Finished downloading;
        - mountPath: /tools
          name: tools
      - name: argocd-repo-server
        - mountPath: /usr/local/bin/gomplate
          name: tools
          subPath: gomplate

Now apply the patch using kubectl:

kubectl -n argocd patch deployments/argocd-repo-server --patch-file=deployment-patch.yaml                                                                                                                                                                                         
deployment.apps/argocd-repo-server patched

Checking the logs of the newly created pod, we can see, that gomplate was getting downloaded:

Downloading additional tools
Connecting to (
Connecting to (
saving to '/tools/gomplate'
gomplate               5% |*                               | 2610k  0:00:16 ETA
gomplate              20% |******                          | 9634k  0:00:07 ETA
gomplate              35% |***********                     | 16.2M  0:00:05 ETA
gomplate              51% |****************                | 23.1M  0:00:03 ETA
gomplate              66% |*********************           | 29.9M  0:00:02 ETA
gomplate              81% |**************************      | 36.8M  0:00:01 ETA
gomplate              96% |******************************  | 43.7M  0:00:00 ETA
gomplate             100% |********************************| 45.1M  0:00:00 ETA
'/tools/gomplate' saved
Finished downloading

When we open a shell into the Repo Server pod, we can find gomplate under /usr/local/bin/.

argocd@argocd-repo-server-595db59bbf-shbnw:~$ gomplate -v
gomplate version 3.11.3

Thinking a little bit ahead, using this scenario, we could now use a templating plugin within ArgoCD that itself would use Gomplate.


Leave a Reply

Your email address will not be published. Required fields are marked *