How to run binary using kuberneates config-map

8/23/2019

I used config map with files but i am experimenting with portable services like supervisor d and other internal tools.

we have golang binary that can be run in any image. what i am trying is to run these binary using configmap.

Example :- We have a internal tool written in Go(size is less than 7MB) can be store in config map and we want to mount that config map inside kuberneates pod and want to run it inside pod

Question :- does anyone use it ? Is it a good approach ? What is the best practice ?

-- evalsocket
configmap
kubernetes

2 Answers

8/23/2019

I too faced similar issue while storing elastic.jks keystore binary file in k8s pod.

AFAIK there are two options:

  • Make use of configmap to store binary data. Check this out.

OR

  • Store your binary file remotely somewhere like in s3 bucket and pull that binary before running actual pod using initContainers concept.
apiVersion: v1
kind: Pod
metadata:
  name: alpine
  namespace: default
spec:
  containers:
  - name: myapp-container
    image: alpine:3.1
    command: ['sh', '-c', 'if [ -f /jks/elastic.jks ]; then sleep 99999; fi']
    volumeMounts:
    - name: jksdata
      mountPath: /jks
  initContainers:
  - name: init-container
    image: atlassian/pipelines-awscli
    command: ["/bin/sh","-c"]
    args: ['aws s3 sync s3://my-artifacts/$CLUSTER /jks/']
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: jksdata
      mountPath: /jks
    env:
    - name: CLUSTER
      value: dev-elastic
  volumes:
  - name: jksdata
    emptyDir: {}
  restartPolicy: Always

As @amit-kumar-gupta mentioned the configmap size constraint.

I recommend the second way.

Hope this helps.

-- mchawre
Source: StackOverflow

8/23/2019

I don't believe you can put 7MB of content in a ConfigMap. See here for example. What you're trying to do sounds like a very unusual practice. The standard practice to run binaries in Pods in Kubernetes is to build a container image that includes the binary and configure the image or the Pod to run that binary.

-- Amit Kumar Gupta
Source: StackOverflow