Kubernetes - How to define ConfigMap built using a file in a yaml?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















At present I am creating a configmap from the file config.json by executing:



kubectl create configmap jksconfig --from-file=config.json


I would want the ConfigMap to be created as part of the deployment and tried to do this:



apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |-
{{ .Files.Get "config.json" | indent 4 }}


But doesn't seem to work. What should be going into configmap.yaml so that the same configmap is created?



---UPDATE---



when I do a helm install dry run:



# Source: mychartv2/templates/jks-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |


Note: I am using minikube as my kubernetes cluster










share|improve this question

























  • You showed a file from the chart/templates directory. If you have the chart then why you don't install the chart by helm? And also your deployment.yaml inside helm chart should have properly written.

    – Shudipta Sharma
    Nov 22 '18 at 11:47











  • I am able to use the configmap , I am looking for a way to create the configmap using yaml and not manually using the command kubectl create configmap

    – Chillax
    Nov 22 '18 at 12:25











  • It seems your configmap file has helm chart template. Why you don't use $ helm install command to create your needs. Helm will replace the template {{ .Files.Get "config.json" | indent 4 }} with the content of file config.json.

    – Shudipta Sharma
    Nov 22 '18 at 13:57











  • Indeed, I am using helm install. But it is not replacing the content as expected with the content of the file config.json nor throwing an error

    – Chillax
    Nov 22 '18 at 14:20











  • I think I got a soln. But first you need to show the output of $ helm install <chart> --dry-run --debug to see if the content is correctly indented or not

    – Shudipta Sharma
    Nov 22 '18 at 14:39


















2















At present I am creating a configmap from the file config.json by executing:



kubectl create configmap jksconfig --from-file=config.json


I would want the ConfigMap to be created as part of the deployment and tried to do this:



apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |-
{{ .Files.Get "config.json" | indent 4 }}


But doesn't seem to work. What should be going into configmap.yaml so that the same configmap is created?



---UPDATE---



when I do a helm install dry run:



# Source: mychartv2/templates/jks-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |


Note: I am using minikube as my kubernetes cluster










share|improve this question

























  • You showed a file from the chart/templates directory. If you have the chart then why you don't install the chart by helm? And also your deployment.yaml inside helm chart should have properly written.

    – Shudipta Sharma
    Nov 22 '18 at 11:47











  • I am able to use the configmap , I am looking for a way to create the configmap using yaml and not manually using the command kubectl create configmap

    – Chillax
    Nov 22 '18 at 12:25











  • It seems your configmap file has helm chart template. Why you don't use $ helm install command to create your needs. Helm will replace the template {{ .Files.Get "config.json" | indent 4 }} with the content of file config.json.

    – Shudipta Sharma
    Nov 22 '18 at 13:57











  • Indeed, I am using helm install. But it is not replacing the content as expected with the content of the file config.json nor throwing an error

    – Chillax
    Nov 22 '18 at 14:20











  • I think I got a soln. But first you need to show the output of $ helm install <chart> --dry-run --debug to see if the content is correctly indented or not

    – Shudipta Sharma
    Nov 22 '18 at 14:39














2












2








2








At present I am creating a configmap from the file config.json by executing:



kubectl create configmap jksconfig --from-file=config.json


I would want the ConfigMap to be created as part of the deployment and tried to do this:



apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |-
{{ .Files.Get "config.json" | indent 4 }}


But doesn't seem to work. What should be going into configmap.yaml so that the same configmap is created?



---UPDATE---



when I do a helm install dry run:



# Source: mychartv2/templates/jks-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |


Note: I am using minikube as my kubernetes cluster










share|improve this question
















At present I am creating a configmap from the file config.json by executing:



kubectl create configmap jksconfig --from-file=config.json


I would want the ConfigMap to be created as part of the deployment and tried to do this:



apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |-
{{ .Files.Get "config.json" | indent 4 }}


But doesn't seem to work. What should be going into configmap.yaml so that the same configmap is created?



---UPDATE---



when I do a helm install dry run:



# Source: mychartv2/templates/jks-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
data:
config.json: |


Note: I am using minikube as my kubernetes cluster







kubernetes minikube kubernetes-helm configmap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 14:52







Chillax

















asked Nov 22 '18 at 11:01









ChillaxChillax

1,354123463




1,354123463













  • You showed a file from the chart/templates directory. If you have the chart then why you don't install the chart by helm? And also your deployment.yaml inside helm chart should have properly written.

    – Shudipta Sharma
    Nov 22 '18 at 11:47











  • I am able to use the configmap , I am looking for a way to create the configmap using yaml and not manually using the command kubectl create configmap

    – Chillax
    Nov 22 '18 at 12:25











  • It seems your configmap file has helm chart template. Why you don't use $ helm install command to create your needs. Helm will replace the template {{ .Files.Get "config.json" | indent 4 }} with the content of file config.json.

    – Shudipta Sharma
    Nov 22 '18 at 13:57











  • Indeed, I am using helm install. But it is not replacing the content as expected with the content of the file config.json nor throwing an error

    – Chillax
    Nov 22 '18 at 14:20











  • I think I got a soln. But first you need to show the output of $ helm install <chart> --dry-run --debug to see if the content is correctly indented or not

    – Shudipta Sharma
    Nov 22 '18 at 14:39



















  • You showed a file from the chart/templates directory. If you have the chart then why you don't install the chart by helm? And also your deployment.yaml inside helm chart should have properly written.

    – Shudipta Sharma
    Nov 22 '18 at 11:47











  • I am able to use the configmap , I am looking for a way to create the configmap using yaml and not manually using the command kubectl create configmap

    – Chillax
    Nov 22 '18 at 12:25











  • It seems your configmap file has helm chart template. Why you don't use $ helm install command to create your needs. Helm will replace the template {{ .Files.Get "config.json" | indent 4 }} with the content of file config.json.

    – Shudipta Sharma
    Nov 22 '18 at 13:57











  • Indeed, I am using helm install. But it is not replacing the content as expected with the content of the file config.json nor throwing an error

    – Chillax
    Nov 22 '18 at 14:20











  • I think I got a soln. But first you need to show the output of $ helm install <chart> --dry-run --debug to see if the content is correctly indented or not

    – Shudipta Sharma
    Nov 22 '18 at 14:39

















You showed a file from the chart/templates directory. If you have the chart then why you don't install the chart by helm? And also your deployment.yaml inside helm chart should have properly written.

– Shudipta Sharma
Nov 22 '18 at 11:47





You showed a file from the chart/templates directory. If you have the chart then why you don't install the chart by helm? And also your deployment.yaml inside helm chart should have properly written.

– Shudipta Sharma
Nov 22 '18 at 11:47













I am able to use the configmap , I am looking for a way to create the configmap using yaml and not manually using the command kubectl create configmap

– Chillax
Nov 22 '18 at 12:25





I am able to use the configmap , I am looking for a way to create the configmap using yaml and not manually using the command kubectl create configmap

– Chillax
Nov 22 '18 at 12:25













It seems your configmap file has helm chart template. Why you don't use $ helm install command to create your needs. Helm will replace the template {{ .Files.Get "config.json" | indent 4 }} with the content of file config.json.

– Shudipta Sharma
Nov 22 '18 at 13:57





It seems your configmap file has helm chart template. Why you don't use $ helm install command to create your needs. Helm will replace the template {{ .Files.Get "config.json" | indent 4 }} with the content of file config.json.

– Shudipta Sharma
Nov 22 '18 at 13:57













Indeed, I am using helm install. But it is not replacing the content as expected with the content of the file config.json nor throwing an error

– Chillax
Nov 22 '18 at 14:20





Indeed, I am using helm install. But it is not replacing the content as expected with the content of the file config.json nor throwing an error

– Chillax
Nov 22 '18 at 14:20













I think I got a soln. But first you need to show the output of $ helm install <chart> --dry-run --debug to see if the content is correctly indented or not

– Shudipta Sharma
Nov 22 '18 at 14:39





I think I got a soln. But first you need to show the output of $ helm install <chart> --dry-run --debug to see if the content is correctly indented or not

– Shudipta Sharma
Nov 22 '18 at 14:39












3 Answers
3






active

oldest

votes


















4














Your config.json file should be inside your mychart/ directory, not inside mychart/templates



Chart Template Guide



configmap.yaml



apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
config.json: |-
{{ .Files.Get "config.json" | indent 4}}


config.json



{
"val": "key"
}


helm install --dry-run --debug mychart



[debug] Created tunnel using local port: '52091'     

[debug] SERVER: "127.0.0.1:52091"

...

NAME: dining-saola
REVISION: 1
RELEASED: Fri Nov 23 15:06:17 2018
CHART: mychart-0.1.0
USER-SUPPLIED VALUES:
{}

...

---
# Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: dining-saola-configmap
data:
config.json: |-
{
"val": "key"
}


EDIT:




But I want it the values in the config.json file to be taken from values.yaml. Is that possible?




configmap.yaml



apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
config.json: |-
{
{{- range $key, $val := .Values.json }}
{{ $key | quote | indent 6}}: {{ $val | quote }}
{{- end}}
}


values.yaml



json:
key1: val1
key2: val2
key3: val3


helm install --dry-run --debug mychart



# Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mangy-hare-configmap
data:
config.json: |-
{
"key1": "val1"
"key2": "val2"
"key3": "val3"
}





share|improve this answer


























  • This did work for one of my use cases. So marking as accepted answer. But I want it the values in the config.json file to be taken from values.yaml. Is that possible?

    – Chillax
    Dec 12 '18 at 11:29











  • Are you trying to get the values from values.yaml file inside your json configmap?

    – edbighead
    Dec 12 '18 at 14:15











  • If so, i've added one more example to my answer.

    – edbighead
    Dec 12 '18 at 14:36



















1














Soln 01:




  • insert your config.json file content into a template

  • then use this template into your data against config.json

  • then run $ helm install command


finally,



{{define "config"}}
{
"a": "A",
"b": {
"b1": 1
}
}
{{end}}

apiVersion: v1
kind: ConfigMap
metadata:
name: jksconfig
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: "my-app"
heritage: "{{ .Release.Service }}"
release: "{{ .Release.Name }}"
data:
config.json: {{ (include "config" .) | trim | quote }}





share|improve this answer































    0














    Here is an example of a ConfigMap that is attached to a Deployment:



    ConfigMap:



    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: jksconfig
    data:
    config.json: |-
    {{ .Files.Get "config.json" | indent 4 }}


    Deployment:



    ---
    apiVersion: apps/v1beta2
    kind: Deployment
    metadata:
    name: jksapp
    labels:
    app: jksapp
    spec:
    selector:
    matchLabels:
    app: jksapp
    template:
    metadata:
    labels:
    app: jksapp
    containers:
    - name: jksapp
    image: jksapp:1.0.0
    ports:
    - containerPort: 8080
    volumeMounts:
    - name: jksconfig
    mountPath: /path/to/config.json
    volumes:
    - name: config
    configMap:
    name: jksconfig





    share|improve this answer
























    • I was able to use the ConfigMap in my deployment. All I want is to know how to get the values from a config.json file ( I am creating it manually now) Also if I pasted the file contents instead of {{ .Files.Get "config.json" | indent 4 }} - that works too

      – Chillax
      Nov 22 '18 at 12:24











    • You use as you would any file on a path. You paste your file content bellow the line config.json: |-.

      – Urosh T.
      Nov 22 '18 at 12:34











    • I was looking for a way to import the data from the file config.json rather than having to paste the contents in the yaml file

      – Chillax
      Nov 22 '18 at 12:58











    • Is it in a key:value format?

      – Urosh T.
      Nov 22 '18 at 13:08











    • It is not in key:value format

      – Chillax
      Nov 22 '18 at 13:31












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429486%2fkubernetes-how-to-define-configmap-built-using-a-file-in-a-yaml%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    Your config.json file should be inside your mychart/ directory, not inside mychart/templates



    Chart Template Guide



    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {{ .Files.Get "config.json" | indent 4}}


    config.json



    {
    "val": "key"
    }


    helm install --dry-run --debug mychart



    [debug] Created tunnel using local port: '52091'     

    [debug] SERVER: "127.0.0.1:52091"

    ...

    NAME: dining-saola
    REVISION: 1
    RELEASED: Fri Nov 23 15:06:17 2018
    CHART: mychart-0.1.0
    USER-SUPPLIED VALUES:
    {}

    ...

    ---
    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: dining-saola-configmap
    data:
    config.json: |-
    {
    "val": "key"
    }


    EDIT:




    But I want it the values in the config.json file to be taken from values.yaml. Is that possible?




    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {
    {{- range $key, $val := .Values.json }}
    {{ $key | quote | indent 6}}: {{ $val | quote }}
    {{- end}}
    }


    values.yaml



    json:
    key1: val1
    key2: val2
    key3: val3


    helm install --dry-run --debug mychart



    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: mangy-hare-configmap
    data:
    config.json: |-
    {
    "key1": "val1"
    "key2": "val2"
    "key3": "val3"
    }





    share|improve this answer


























    • This did work for one of my use cases. So marking as accepted answer. But I want it the values in the config.json file to be taken from values.yaml. Is that possible?

      – Chillax
      Dec 12 '18 at 11:29











    • Are you trying to get the values from values.yaml file inside your json configmap?

      – edbighead
      Dec 12 '18 at 14:15











    • If so, i've added one more example to my answer.

      – edbighead
      Dec 12 '18 at 14:36
















    4














    Your config.json file should be inside your mychart/ directory, not inside mychart/templates



    Chart Template Guide



    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {{ .Files.Get "config.json" | indent 4}}


    config.json



    {
    "val": "key"
    }


    helm install --dry-run --debug mychart



    [debug] Created tunnel using local port: '52091'     

    [debug] SERVER: "127.0.0.1:52091"

    ...

    NAME: dining-saola
    REVISION: 1
    RELEASED: Fri Nov 23 15:06:17 2018
    CHART: mychart-0.1.0
    USER-SUPPLIED VALUES:
    {}

    ...

    ---
    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: dining-saola-configmap
    data:
    config.json: |-
    {
    "val": "key"
    }


    EDIT:




    But I want it the values in the config.json file to be taken from values.yaml. Is that possible?




    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {
    {{- range $key, $val := .Values.json }}
    {{ $key | quote | indent 6}}: {{ $val | quote }}
    {{- end}}
    }


    values.yaml



    json:
    key1: val1
    key2: val2
    key3: val3


    helm install --dry-run --debug mychart



    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: mangy-hare-configmap
    data:
    config.json: |-
    {
    "key1": "val1"
    "key2": "val2"
    "key3": "val3"
    }





    share|improve this answer


























    • This did work for one of my use cases. So marking as accepted answer. But I want it the values in the config.json file to be taken from values.yaml. Is that possible?

      – Chillax
      Dec 12 '18 at 11:29











    • Are you trying to get the values from values.yaml file inside your json configmap?

      – edbighead
      Dec 12 '18 at 14:15











    • If so, i've added one more example to my answer.

      – edbighead
      Dec 12 '18 at 14:36














    4












    4








    4







    Your config.json file should be inside your mychart/ directory, not inside mychart/templates



    Chart Template Guide



    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {{ .Files.Get "config.json" | indent 4}}


    config.json



    {
    "val": "key"
    }


    helm install --dry-run --debug mychart



    [debug] Created tunnel using local port: '52091'     

    [debug] SERVER: "127.0.0.1:52091"

    ...

    NAME: dining-saola
    REVISION: 1
    RELEASED: Fri Nov 23 15:06:17 2018
    CHART: mychart-0.1.0
    USER-SUPPLIED VALUES:
    {}

    ...

    ---
    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: dining-saola-configmap
    data:
    config.json: |-
    {
    "val": "key"
    }


    EDIT:




    But I want it the values in the config.json file to be taken from values.yaml. Is that possible?




    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {
    {{- range $key, $val := .Values.json }}
    {{ $key | quote | indent 6}}: {{ $val | quote }}
    {{- end}}
    }


    values.yaml



    json:
    key1: val1
    key2: val2
    key3: val3


    helm install --dry-run --debug mychart



    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: mangy-hare-configmap
    data:
    config.json: |-
    {
    "key1": "val1"
    "key2": "val2"
    "key3": "val3"
    }





    share|improve this answer















    Your config.json file should be inside your mychart/ directory, not inside mychart/templates



    Chart Template Guide



    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {{ .Files.Get "config.json" | indent 4}}


    config.json



    {
    "val": "key"
    }


    helm install --dry-run --debug mychart



    [debug] Created tunnel using local port: '52091'     

    [debug] SERVER: "127.0.0.1:52091"

    ...

    NAME: dining-saola
    REVISION: 1
    RELEASED: Fri Nov 23 15:06:17 2018
    CHART: mychart-0.1.0
    USER-SUPPLIED VALUES:
    {}

    ...

    ---
    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: dining-saola-configmap
    data:
    config.json: |-
    {
    "val": "key"
    }


    EDIT:




    But I want it the values in the config.json file to be taken from values.yaml. Is that possible?




    configmap.yaml



    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ .Release.Name }}-configmap
    data:
    config.json: |-
    {
    {{- range $key, $val := .Values.json }}
    {{ $key | quote | indent 6}}: {{ $val | quote }}
    {{- end}}
    }


    values.yaml



    json:
    key1: val1
    key2: val2
    key3: val3


    helm install --dry-run --debug mychart



    # Source: mychart/templates/configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: mangy-hare-configmap
    data:
    config.json: |-
    {
    "key1": "val1"
    "key2": "val2"
    "key3": "val3"
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 12 '18 at 14:35

























    answered Nov 23 '18 at 13:07









    edbigheadedbighead

    805513




    805513













    • This did work for one of my use cases. So marking as accepted answer. But I want it the values in the config.json file to be taken from values.yaml. Is that possible?

      – Chillax
      Dec 12 '18 at 11:29











    • Are you trying to get the values from values.yaml file inside your json configmap?

      – edbighead
      Dec 12 '18 at 14:15











    • If so, i've added one more example to my answer.

      – edbighead
      Dec 12 '18 at 14:36



















    • This did work for one of my use cases. So marking as accepted answer. But I want it the values in the config.json file to be taken from values.yaml. Is that possible?

      – Chillax
      Dec 12 '18 at 11:29











    • Are you trying to get the values from values.yaml file inside your json configmap?

      – edbighead
      Dec 12 '18 at 14:15











    • If so, i've added one more example to my answer.

      – edbighead
      Dec 12 '18 at 14:36

















    This did work for one of my use cases. So marking as accepted answer. But I want it the values in the config.json file to be taken from values.yaml. Is that possible?

    – Chillax
    Dec 12 '18 at 11:29





    This did work for one of my use cases. So marking as accepted answer. But I want it the values in the config.json file to be taken from values.yaml. Is that possible?

    – Chillax
    Dec 12 '18 at 11:29













    Are you trying to get the values from values.yaml file inside your json configmap?

    – edbighead
    Dec 12 '18 at 14:15





    Are you trying to get the values from values.yaml file inside your json configmap?

    – edbighead
    Dec 12 '18 at 14:15













    If so, i've added one more example to my answer.

    – edbighead
    Dec 12 '18 at 14:36





    If so, i've added one more example to my answer.

    – edbighead
    Dec 12 '18 at 14:36













    1














    Soln 01:




    • insert your config.json file content into a template

    • then use this template into your data against config.json

    • then run $ helm install command


    finally,



    {{define "config"}}
    {
    "a": "A",
    "b": {
    "b1": 1
    }
    }
    {{end}}

    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: jksconfig
    labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    app: "my-app"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
    data:
    config.json: {{ (include "config" .) | trim | quote }}





    share|improve this answer




























      1














      Soln 01:




      • insert your config.json file content into a template

      • then use this template into your data against config.json

      • then run $ helm install command


      finally,



      {{define "config"}}
      {
      "a": "A",
      "b": {
      "b1": 1
      }
      }
      {{end}}

      apiVersion: v1
      kind: ConfigMap
      metadata:
      name: jksconfig
      labels:
      chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
      app: "my-app"
      heritage: "{{ .Release.Service }}"
      release: "{{ .Release.Name }}"
      data:
      config.json: {{ (include "config" .) | trim | quote }}





      share|improve this answer


























        1












        1








        1







        Soln 01:




        • insert your config.json file content into a template

        • then use this template into your data against config.json

        • then run $ helm install command


        finally,



        {{define "config"}}
        {
        "a": "A",
        "b": {
        "b1": 1
        }
        }
        {{end}}

        apiVersion: v1
        kind: ConfigMap
        metadata:
        name: jksconfig
        labels:
        chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        app: "my-app"
        heritage: "{{ .Release.Service }}"
        release: "{{ .Release.Name }}"
        data:
        config.json: {{ (include "config" .) | trim | quote }}





        share|improve this answer













        Soln 01:




        • insert your config.json file content into a template

        • then use this template into your data against config.json

        • then run $ helm install command


        finally,



        {{define "config"}}
        {
        "a": "A",
        "b": {
        "b1": 1
        }
        }
        {{end}}

        apiVersion: v1
        kind: ConfigMap
        metadata:
        name: jksconfig
        labels:
        chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        app: "my-app"
        heritage: "{{ .Release.Service }}"
        release: "{{ .Release.Name }}"
        data:
        config.json: {{ (include "config" .) | trim | quote }}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 18:00









        Shudipta SharmaShudipta Sharma

        1,242414




        1,242414























            0














            Here is an example of a ConfigMap that is attached to a Deployment:



            ConfigMap:



            ---
            apiVersion: v1
            kind: ConfigMap
            metadata:
            name: jksconfig
            data:
            config.json: |-
            {{ .Files.Get "config.json" | indent 4 }}


            Deployment:



            ---
            apiVersion: apps/v1beta2
            kind: Deployment
            metadata:
            name: jksapp
            labels:
            app: jksapp
            spec:
            selector:
            matchLabels:
            app: jksapp
            template:
            metadata:
            labels:
            app: jksapp
            containers:
            - name: jksapp
            image: jksapp:1.0.0
            ports:
            - containerPort: 8080
            volumeMounts:
            - name: jksconfig
            mountPath: /path/to/config.json
            volumes:
            - name: config
            configMap:
            name: jksconfig





            share|improve this answer
























            • I was able to use the ConfigMap in my deployment. All I want is to know how to get the values from a config.json file ( I am creating it manually now) Also if I pasted the file contents instead of {{ .Files.Get "config.json" | indent 4 }} - that works too

              – Chillax
              Nov 22 '18 at 12:24











            • You use as you would any file on a path. You paste your file content bellow the line config.json: |-.

              – Urosh T.
              Nov 22 '18 at 12:34











            • I was looking for a way to import the data from the file config.json rather than having to paste the contents in the yaml file

              – Chillax
              Nov 22 '18 at 12:58











            • Is it in a key:value format?

              – Urosh T.
              Nov 22 '18 at 13:08











            • It is not in key:value format

              – Chillax
              Nov 22 '18 at 13:31
















            0














            Here is an example of a ConfigMap that is attached to a Deployment:



            ConfigMap:



            ---
            apiVersion: v1
            kind: ConfigMap
            metadata:
            name: jksconfig
            data:
            config.json: |-
            {{ .Files.Get "config.json" | indent 4 }}


            Deployment:



            ---
            apiVersion: apps/v1beta2
            kind: Deployment
            metadata:
            name: jksapp
            labels:
            app: jksapp
            spec:
            selector:
            matchLabels:
            app: jksapp
            template:
            metadata:
            labels:
            app: jksapp
            containers:
            - name: jksapp
            image: jksapp:1.0.0
            ports:
            - containerPort: 8080
            volumeMounts:
            - name: jksconfig
            mountPath: /path/to/config.json
            volumes:
            - name: config
            configMap:
            name: jksconfig





            share|improve this answer
























            • I was able to use the ConfigMap in my deployment. All I want is to know how to get the values from a config.json file ( I am creating it manually now) Also if I pasted the file contents instead of {{ .Files.Get "config.json" | indent 4 }} - that works too

              – Chillax
              Nov 22 '18 at 12:24











            • You use as you would any file on a path. You paste your file content bellow the line config.json: |-.

              – Urosh T.
              Nov 22 '18 at 12:34











            • I was looking for a way to import the data from the file config.json rather than having to paste the contents in the yaml file

              – Chillax
              Nov 22 '18 at 12:58











            • Is it in a key:value format?

              – Urosh T.
              Nov 22 '18 at 13:08











            • It is not in key:value format

              – Chillax
              Nov 22 '18 at 13:31














            0












            0








            0







            Here is an example of a ConfigMap that is attached to a Deployment:



            ConfigMap:



            ---
            apiVersion: v1
            kind: ConfigMap
            metadata:
            name: jksconfig
            data:
            config.json: |-
            {{ .Files.Get "config.json" | indent 4 }}


            Deployment:



            ---
            apiVersion: apps/v1beta2
            kind: Deployment
            metadata:
            name: jksapp
            labels:
            app: jksapp
            spec:
            selector:
            matchLabels:
            app: jksapp
            template:
            metadata:
            labels:
            app: jksapp
            containers:
            - name: jksapp
            image: jksapp:1.0.0
            ports:
            - containerPort: 8080
            volumeMounts:
            - name: jksconfig
            mountPath: /path/to/config.json
            volumes:
            - name: config
            configMap:
            name: jksconfig





            share|improve this answer













            Here is an example of a ConfigMap that is attached to a Deployment:



            ConfigMap:



            ---
            apiVersion: v1
            kind: ConfigMap
            metadata:
            name: jksconfig
            data:
            config.json: |-
            {{ .Files.Get "config.json" | indent 4 }}


            Deployment:



            ---
            apiVersion: apps/v1beta2
            kind: Deployment
            metadata:
            name: jksapp
            labels:
            app: jksapp
            spec:
            selector:
            matchLabels:
            app: jksapp
            template:
            metadata:
            labels:
            app: jksapp
            containers:
            - name: jksapp
            image: jksapp:1.0.0
            ports:
            - containerPort: 8080
            volumeMounts:
            - name: jksconfig
            mountPath: /path/to/config.json
            volumes:
            - name: config
            configMap:
            name: jksconfig






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 11:56









            Urosh T.Urosh T.

            77821420




            77821420













            • I was able to use the ConfigMap in my deployment. All I want is to know how to get the values from a config.json file ( I am creating it manually now) Also if I pasted the file contents instead of {{ .Files.Get "config.json" | indent 4 }} - that works too

              – Chillax
              Nov 22 '18 at 12:24











            • You use as you would any file on a path. You paste your file content bellow the line config.json: |-.

              – Urosh T.
              Nov 22 '18 at 12:34











            • I was looking for a way to import the data from the file config.json rather than having to paste the contents in the yaml file

              – Chillax
              Nov 22 '18 at 12:58











            • Is it in a key:value format?

              – Urosh T.
              Nov 22 '18 at 13:08











            • It is not in key:value format

              – Chillax
              Nov 22 '18 at 13:31



















            • I was able to use the ConfigMap in my deployment. All I want is to know how to get the values from a config.json file ( I am creating it manually now) Also if I pasted the file contents instead of {{ .Files.Get "config.json" | indent 4 }} - that works too

              – Chillax
              Nov 22 '18 at 12:24











            • You use as you would any file on a path. You paste your file content bellow the line config.json: |-.

              – Urosh T.
              Nov 22 '18 at 12:34











            • I was looking for a way to import the data from the file config.json rather than having to paste the contents in the yaml file

              – Chillax
              Nov 22 '18 at 12:58











            • Is it in a key:value format?

              – Urosh T.
              Nov 22 '18 at 13:08











            • It is not in key:value format

              – Chillax
              Nov 22 '18 at 13:31

















            I was able to use the ConfigMap in my deployment. All I want is to know how to get the values from a config.json file ( I am creating it manually now) Also if I pasted the file contents instead of {{ .Files.Get "config.json" | indent 4 }} - that works too

            – Chillax
            Nov 22 '18 at 12:24





            I was able to use the ConfigMap in my deployment. All I want is to know how to get the values from a config.json file ( I am creating it manually now) Also if I pasted the file contents instead of {{ .Files.Get "config.json" | indent 4 }} - that works too

            – Chillax
            Nov 22 '18 at 12:24













            You use as you would any file on a path. You paste your file content bellow the line config.json: |-.

            – Urosh T.
            Nov 22 '18 at 12:34





            You use as you would any file on a path. You paste your file content bellow the line config.json: |-.

            – Urosh T.
            Nov 22 '18 at 12:34













            I was looking for a way to import the data from the file config.json rather than having to paste the contents in the yaml file

            – Chillax
            Nov 22 '18 at 12:58





            I was looking for a way to import the data from the file config.json rather than having to paste the contents in the yaml file

            – Chillax
            Nov 22 '18 at 12:58













            Is it in a key:value format?

            – Urosh T.
            Nov 22 '18 at 13:08





            Is it in a key:value format?

            – Urosh T.
            Nov 22 '18 at 13:08













            It is not in key:value format

            – Chillax
            Nov 22 '18 at 13:31





            It is not in key:value format

            – Chillax
            Nov 22 '18 at 13:31


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429486%2fkubernetes-how-to-define-configmap-built-using-a-file-in-a-yaml%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?