<p>I have this configMap defined :</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
  labels:
    app: my-config
data:
  myConfiguration.json: |
    {
    &quot;configKey&quot;: [
        {
          &quot;key&quot; : &quot;value&quot;
        },
        {
          &quot;key&quot; : &quot;value&quot;
        }
    }
</code></pre>
<p>and this is how i use it in my pod :</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: someimage
  name: someimage
spec:
  selector:
    matchLabels:
      app: someimage
  replicas: 1
  template:
    metadata:
      labels:
        app: someimage
    spec:
      containers:
        - image: someimage
          name: someimage
          command:
            - mb
            - --configfile
            - /configFolder/myConfig.json
          ports:
            - containerPort: 2525
          volumeMounts:
            - name: config-volume
              mountPath: /configFolder
      hostname: somehost
      restartPolicy: Always
      nodeSelector:
        beta.kubernetes.io/os: linux
      volumes:
        - name: config-volume
          configMap:
            name: my-config
            items:
              - key: myConfiguration.json
                path: myConfiguration.json
</code></pre>
<p>my question is : is it possible to keep the value of the myconfiguration (the json string) in a separate file, separated from the configmap? in order to keep it clean? How would i need to change the deployment and the configmap yaml definitions so i do not have to change the application?</p>
<p>Important : i cannot use any separate templating tool.</p>
<p>thanks</p>

<p>Yes you can! Using Kustomize.</p>
<p>Kustomize is kubectl sub-command introduced in 1.14, and it has a lot of features that will help customize your deployments.</p>
<p>To do that you'll have to use <code>ConfigMaps Generators</code>. This will require an additional file <code>kustomization.yml</code>.</p>
<p>So if your deployment yaml file is <code>deployment.yaml</code> and your configMap's name is <code>my-config</code>, then the <code>kustomization.yaml</code> should look something like this</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yaml
configMapGenerator:
- name: my-config
  files:
  - myConfiguration.json
  - myConfiguration2.json # you can use multiple files
</code></pre>
<p>To run kustomize you'll have to use <code>kubectl apply</code> with the <code>-k</code> option.</p>
<p>Edit: Kustomize will append the value of the hash of you ConfigMaps into their names. Having that it will be able to track changes on you configurations and trigger a redeploy for you whenever they change.</p>
<p>So no need for deleting your pods whenever you configMaps are altered.</p>
