How do I inject binary files into a v1.7 pod

7/13/2018

I have a 3rd party docker image that I want to use (https://github.com/coreos/dex/releases/tag/v2.10.0). I need to inject some customisation into the pod (CSS stylesheet and PNG images).

I haven't found a suitable way to do this yet. Configmap binaryData is not available before v1.10 (or 9, can't remember off the top of my head). I could create a new image and COPY the PNG files into the image, but I don't want the overhead of maintaining this new image - far safer to just use the provided image.

Is there an easy way of injecting these 2/3 files I need into the pod I create?

-- agentgonzo
kubernetes

2 Answers

7/13/2018

You could mount your custom files into a volume, and additionally define a set of commands to run on pod startup (see here) to copy your files to their target path.

You of course need to also run the command that starts your service, in addition to the ones that copy your files.

-- Gabriel Ruiu
Source: StackOverflow

7/13/2018

One way would be to mount 1 or more volumes into the desired locations within the pod, seemingly /web/static. This however would overwrite the entire directly so you would need to supply all the files not just those you wish to overwrite.

Example:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - image: dex:2.10.0
    name: dex
    volumeMounts:
    - mountPath: /web/static # the mount location within the container
      name: dex-volume
  volumes:
  - name: dex-volume
    hostPath:
      path: /destination/on/K8s/node # path on host machine

There are a number of types of storage types for different cloud providers so take a look at https://kubernetes.io/docs/concepts/storage/volumes/ and see if theres something a little more specific to your environment rather than storing on disk.

For what it's worth, creating your own image would probably be the simplest solution.

-- justcompile
Source: StackOverflow