Pass configMap as argument in a Kubernetes deployment

8/9/2020

I have a Dockerfile that starts a java process with this command CMD java -jar application.jar serve /path-to-file/setting.yaml

Now, I want to make the settings.yaml to be configMap, so, I can manage it in kubernetes instead of building a new docker image every time I have updated a setting.

My question is: is possible to achieve this now that I won't be passing setting.yaml in the Dockerfile but a kubernetes yaml as a confiMap?

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
  containers:
  - name: java-container
    image: javaimage:1.0
    command: [""]
    args: ["pass the file here"]
<!-- end snippet -->

is it possible to pass the file in a kubernetes deployment as configMap on args[""]

-- Muzi Jack
docker
dockerfile
kubernetes
openshift

1 Answer

8/16/2020

First, you would create a ConfigMap:

cat <<EOF >file.yaml
[...]
EOF
kubectl create -n my-namespace configmap my-app-config --from-file=settings.yaml=file.yaml

Then, based on the path of the configuration file loaded in the CMD of your container image, you would mount that ConfigMap to the proper location:

containers:
- name: app
  [ ... ]
  volumeMounts:
  - name: config-volume
    path: /path-to-file/settings.yaml
    subPath: settings.yaml
[ ... ]
volumes:
- name: config-volume
  configMap:
    name: my-app-config
-- SYN
Source: StackOverflow