How best to have files on volumes in Kubernetes using helm charts?





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







1















The plan is to move my dockerized application to Kubernetes.



The docker container uses couple of files - which I used to mount on the docker volumes by specifying in the docker-compose file:



volumes:
- ./license.dat:/etc/sys0/license.dat
- ./config.json:/etc/sys0/config.json


The config file would be different for different environments, and the license file would be the same across.



How do I define this in a helm template file (yaml) so that it is available for the running application?



What is generally the best practise for this? Is it also possible to define the configuration values in values.yaml and the config.json file could get it?










share|improve this question


















  • 1





    Have you read docs.helm.sh/chart_template_guide/…? I'd probably use a Secret and not a ConfigMap as in the example there, but it's outlined pretty well in the Helm docs.

    – David Maze
    Nov 16 '18 at 15:48


















1















The plan is to move my dockerized application to Kubernetes.



The docker container uses couple of files - which I used to mount on the docker volumes by specifying in the docker-compose file:



volumes:
- ./license.dat:/etc/sys0/license.dat
- ./config.json:/etc/sys0/config.json


The config file would be different for different environments, and the license file would be the same across.



How do I define this in a helm template file (yaml) so that it is available for the running application?



What is generally the best practise for this? Is it also possible to define the configuration values in values.yaml and the config.json file could get it?










share|improve this question


















  • 1





    Have you read docs.helm.sh/chart_template_guide/…? I'd probably use a Secret and not a ConfigMap as in the example there, but it's outlined pretty well in the Helm docs.

    – David Maze
    Nov 16 '18 at 15:48














1












1








1








The plan is to move my dockerized application to Kubernetes.



The docker container uses couple of files - which I used to mount on the docker volumes by specifying in the docker-compose file:



volumes:
- ./license.dat:/etc/sys0/license.dat
- ./config.json:/etc/sys0/config.json


The config file would be different for different environments, and the license file would be the same across.



How do I define this in a helm template file (yaml) so that it is available for the running application?



What is generally the best practise for this? Is it also possible to define the configuration values in values.yaml and the config.json file could get it?










share|improve this question














The plan is to move my dockerized application to Kubernetes.



The docker container uses couple of files - which I used to mount on the docker volumes by specifying in the docker-compose file:



volumes:
- ./license.dat:/etc/sys0/license.dat
- ./config.json:/etc/sys0/config.json


The config file would be different for different environments, and the license file would be the same across.



How do I define this in a helm template file (yaml) so that it is available for the running application?



What is generally the best practise for this? Is it also possible to define the configuration values in values.yaml and the config.json file could get it?







kubernetes kubernetes-helm docker-volume






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 15:41









ChillaxChillax

1,354123463




1,354123463








  • 1





    Have you read docs.helm.sh/chart_template_guide/…? I'd probably use a Secret and not a ConfigMap as in the example there, but it's outlined pretty well in the Helm docs.

    – David Maze
    Nov 16 '18 at 15:48














  • 1





    Have you read docs.helm.sh/chart_template_guide/…? I'd probably use a Secret and not a ConfigMap as in the example there, but it's outlined pretty well in the Helm docs.

    – David Maze
    Nov 16 '18 at 15:48








1




1





Have you read docs.helm.sh/chart_template_guide/…? I'd probably use a Secret and not a ConfigMap as in the example there, but it's outlined pretty well in the Helm docs.

– David Maze
Nov 16 '18 at 15:48





Have you read docs.helm.sh/chart_template_guide/…? I'd probably use a Secret and not a ConfigMap as in the example there, but it's outlined pretty well in the Helm docs.

– David Maze
Nov 16 '18 at 15:48












1 Answer
1






active

oldest

votes


















2














Since you are dealing with json a good example to follow might be the official stable/centrifugo chart. It defines a ConfigMap that contains a config.json file:



data:
config.json: |-
{{ toJson .Values.config| indent 4 }}


So it takes a config section from the values.yaml and transforms it to json using the toJson function. The config can be whatever you want define in that yaml - the chart has:



config:
web: true
namespaces:
- name: public
anonymous: true
publish: true
...


In the deployment.yaml it creates a volume from the configmap:



      volumes:
- name: {{ template "centrifugo.fullname" . }}-config
configMap:
name: {{ template "centrifugo.fullname" . }}-config


Note that {{ template "centrifugo.fullname" . }}-config matches the name of the ConfigMap.



And mounts it into the deployment's pod/s:



        volumeMounts:
- name: "{{ template "centrifugo.fullname" . }}-config"
mountPath: "/centrifugo"
readOnly: true


This approach would let you populate the json config file from the values.yaml so that you can set different values for different environments by supplying custom values file per env to override the default one in the chart.



To handle the license.dat you can add an extra entry to the ConfigMap to define an additional file but with static content embedded. Since that is a license you may want to switch the ConfigMap to a Secret instead, which is a simple change of replacing the word ConfigMap for Secret in the definitions. You could try it with ConfigMap first though.






share|improve this answer


























  • Could we have this mounted to the same path as where the docker container expects it ? that is: /etc/sys0/ ? If we do not need it as part of vlaues, then we just need to use the ConfigMap without the centrifugo chart I believe?

    – Chillax
    Nov 20 '18 at 11:29











  • Yes I don't mean to suggest using the centrifugo class. I meant to suggest copying the approach that they take to incorporate your own configmap into your chart - basically by copy-pasting their code and changing the names to your chart name and changing the path to your desired mount path. If you don't need it as part of the values then you could just put the static content into the configmap (or load with Files.Get) but would still need to mount the configmap.

    – Ryan Dawson
    Nov 20 '18 at 11:41











  • happy to chat if you like chat.stackoverflow.com/rooms/183948/…

    – Ryan Dawson
    Nov 20 '18 at 11:42






  • 1





    Thanks. I did try ConfigMap and it is working as expected. I will try getting it from values later and update how it goes.

    – Chillax
    Nov 21 '18 at 16:27












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%2f53341089%2fhow-best-to-have-files-on-volumes-in-kubernetes-using-helm-charts%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Since you are dealing with json a good example to follow might be the official stable/centrifugo chart. It defines a ConfigMap that contains a config.json file:



data:
config.json: |-
{{ toJson .Values.config| indent 4 }}


So it takes a config section from the values.yaml and transforms it to json using the toJson function. The config can be whatever you want define in that yaml - the chart has:



config:
web: true
namespaces:
- name: public
anonymous: true
publish: true
...


In the deployment.yaml it creates a volume from the configmap:



      volumes:
- name: {{ template "centrifugo.fullname" . }}-config
configMap:
name: {{ template "centrifugo.fullname" . }}-config


Note that {{ template "centrifugo.fullname" . }}-config matches the name of the ConfigMap.



And mounts it into the deployment's pod/s:



        volumeMounts:
- name: "{{ template "centrifugo.fullname" . }}-config"
mountPath: "/centrifugo"
readOnly: true


This approach would let you populate the json config file from the values.yaml so that you can set different values for different environments by supplying custom values file per env to override the default one in the chart.



To handle the license.dat you can add an extra entry to the ConfigMap to define an additional file but with static content embedded. Since that is a license you may want to switch the ConfigMap to a Secret instead, which is a simple change of replacing the word ConfigMap for Secret in the definitions. You could try it with ConfigMap first though.






share|improve this answer


























  • Could we have this mounted to the same path as where the docker container expects it ? that is: /etc/sys0/ ? If we do not need it as part of vlaues, then we just need to use the ConfigMap without the centrifugo chart I believe?

    – Chillax
    Nov 20 '18 at 11:29











  • Yes I don't mean to suggest using the centrifugo class. I meant to suggest copying the approach that they take to incorporate your own configmap into your chart - basically by copy-pasting their code and changing the names to your chart name and changing the path to your desired mount path. If you don't need it as part of the values then you could just put the static content into the configmap (or load with Files.Get) but would still need to mount the configmap.

    – Ryan Dawson
    Nov 20 '18 at 11:41











  • happy to chat if you like chat.stackoverflow.com/rooms/183948/…

    – Ryan Dawson
    Nov 20 '18 at 11:42






  • 1





    Thanks. I did try ConfigMap and it is working as expected. I will try getting it from values later and update how it goes.

    – Chillax
    Nov 21 '18 at 16:27
















2














Since you are dealing with json a good example to follow might be the official stable/centrifugo chart. It defines a ConfigMap that contains a config.json file:



data:
config.json: |-
{{ toJson .Values.config| indent 4 }}


So it takes a config section from the values.yaml and transforms it to json using the toJson function. The config can be whatever you want define in that yaml - the chart has:



config:
web: true
namespaces:
- name: public
anonymous: true
publish: true
...


In the deployment.yaml it creates a volume from the configmap:



      volumes:
- name: {{ template "centrifugo.fullname" . }}-config
configMap:
name: {{ template "centrifugo.fullname" . }}-config


Note that {{ template "centrifugo.fullname" . }}-config matches the name of the ConfigMap.



And mounts it into the deployment's pod/s:



        volumeMounts:
- name: "{{ template "centrifugo.fullname" . }}-config"
mountPath: "/centrifugo"
readOnly: true


This approach would let you populate the json config file from the values.yaml so that you can set different values for different environments by supplying custom values file per env to override the default one in the chart.



To handle the license.dat you can add an extra entry to the ConfigMap to define an additional file but with static content embedded. Since that is a license you may want to switch the ConfigMap to a Secret instead, which is a simple change of replacing the word ConfigMap for Secret in the definitions. You could try it with ConfigMap first though.






share|improve this answer


























  • Could we have this mounted to the same path as where the docker container expects it ? that is: /etc/sys0/ ? If we do not need it as part of vlaues, then we just need to use the ConfigMap without the centrifugo chart I believe?

    – Chillax
    Nov 20 '18 at 11:29











  • Yes I don't mean to suggest using the centrifugo class. I meant to suggest copying the approach that they take to incorporate your own configmap into your chart - basically by copy-pasting their code and changing the names to your chart name and changing the path to your desired mount path. If you don't need it as part of the values then you could just put the static content into the configmap (or load with Files.Get) but would still need to mount the configmap.

    – Ryan Dawson
    Nov 20 '18 at 11:41











  • happy to chat if you like chat.stackoverflow.com/rooms/183948/…

    – Ryan Dawson
    Nov 20 '18 at 11:42






  • 1





    Thanks. I did try ConfigMap and it is working as expected. I will try getting it from values later and update how it goes.

    – Chillax
    Nov 21 '18 at 16:27














2












2








2







Since you are dealing with json a good example to follow might be the official stable/centrifugo chart. It defines a ConfigMap that contains a config.json file:



data:
config.json: |-
{{ toJson .Values.config| indent 4 }}


So it takes a config section from the values.yaml and transforms it to json using the toJson function. The config can be whatever you want define in that yaml - the chart has:



config:
web: true
namespaces:
- name: public
anonymous: true
publish: true
...


In the deployment.yaml it creates a volume from the configmap:



      volumes:
- name: {{ template "centrifugo.fullname" . }}-config
configMap:
name: {{ template "centrifugo.fullname" . }}-config


Note that {{ template "centrifugo.fullname" . }}-config matches the name of the ConfigMap.



And mounts it into the deployment's pod/s:



        volumeMounts:
- name: "{{ template "centrifugo.fullname" . }}-config"
mountPath: "/centrifugo"
readOnly: true


This approach would let you populate the json config file from the values.yaml so that you can set different values for different environments by supplying custom values file per env to override the default one in the chart.



To handle the license.dat you can add an extra entry to the ConfigMap to define an additional file but with static content embedded. Since that is a license you may want to switch the ConfigMap to a Secret instead, which is a simple change of replacing the word ConfigMap for Secret in the definitions. You could try it with ConfigMap first though.






share|improve this answer















Since you are dealing with json a good example to follow might be the official stable/centrifugo chart. It defines a ConfigMap that contains a config.json file:



data:
config.json: |-
{{ toJson .Values.config| indent 4 }}


So it takes a config section from the values.yaml and transforms it to json using the toJson function. The config can be whatever you want define in that yaml - the chart has:



config:
web: true
namespaces:
- name: public
anonymous: true
publish: true
...


In the deployment.yaml it creates a volume from the configmap:



      volumes:
- name: {{ template "centrifugo.fullname" . }}-config
configMap:
name: {{ template "centrifugo.fullname" . }}-config


Note that {{ template "centrifugo.fullname" . }}-config matches the name of the ConfigMap.



And mounts it into the deployment's pod/s:



        volumeMounts:
- name: "{{ template "centrifugo.fullname" . }}-config"
mountPath: "/centrifugo"
readOnly: true


This approach would let you populate the json config file from the values.yaml so that you can set different values for different environments by supplying custom values file per env to override the default one in the chart.



To handle the license.dat you can add an extra entry to the ConfigMap to define an additional file but with static content embedded. Since that is a license you may want to switch the ConfigMap to a Secret instead, which is a simple change of replacing the word ConfigMap for Secret in the definitions. You could try it with ConfigMap first though.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 9:39

























answered Nov 16 '18 at 17:11









Ryan DawsonRyan Dawson

4,9023428




4,9023428













  • Could we have this mounted to the same path as where the docker container expects it ? that is: /etc/sys0/ ? If we do not need it as part of vlaues, then we just need to use the ConfigMap without the centrifugo chart I believe?

    – Chillax
    Nov 20 '18 at 11:29











  • Yes I don't mean to suggest using the centrifugo class. I meant to suggest copying the approach that they take to incorporate your own configmap into your chart - basically by copy-pasting their code and changing the names to your chart name and changing the path to your desired mount path. If you don't need it as part of the values then you could just put the static content into the configmap (or load with Files.Get) but would still need to mount the configmap.

    – Ryan Dawson
    Nov 20 '18 at 11:41











  • happy to chat if you like chat.stackoverflow.com/rooms/183948/…

    – Ryan Dawson
    Nov 20 '18 at 11:42






  • 1





    Thanks. I did try ConfigMap and it is working as expected. I will try getting it from values later and update how it goes.

    – Chillax
    Nov 21 '18 at 16:27



















  • Could we have this mounted to the same path as where the docker container expects it ? that is: /etc/sys0/ ? If we do not need it as part of vlaues, then we just need to use the ConfigMap without the centrifugo chart I believe?

    – Chillax
    Nov 20 '18 at 11:29











  • Yes I don't mean to suggest using the centrifugo class. I meant to suggest copying the approach that they take to incorporate your own configmap into your chart - basically by copy-pasting their code and changing the names to your chart name and changing the path to your desired mount path. If you don't need it as part of the values then you could just put the static content into the configmap (or load with Files.Get) but would still need to mount the configmap.

    – Ryan Dawson
    Nov 20 '18 at 11:41











  • happy to chat if you like chat.stackoverflow.com/rooms/183948/…

    – Ryan Dawson
    Nov 20 '18 at 11:42






  • 1





    Thanks. I did try ConfigMap and it is working as expected. I will try getting it from values later and update how it goes.

    – Chillax
    Nov 21 '18 at 16:27

















Could we have this mounted to the same path as where the docker container expects it ? that is: /etc/sys0/ ? If we do not need it as part of vlaues, then we just need to use the ConfigMap without the centrifugo chart I believe?

– Chillax
Nov 20 '18 at 11:29





Could we have this mounted to the same path as where the docker container expects it ? that is: /etc/sys0/ ? If we do not need it as part of vlaues, then we just need to use the ConfigMap without the centrifugo chart I believe?

– Chillax
Nov 20 '18 at 11:29













Yes I don't mean to suggest using the centrifugo class. I meant to suggest copying the approach that they take to incorporate your own configmap into your chart - basically by copy-pasting their code and changing the names to your chart name and changing the path to your desired mount path. If you don't need it as part of the values then you could just put the static content into the configmap (or load with Files.Get) but would still need to mount the configmap.

– Ryan Dawson
Nov 20 '18 at 11:41





Yes I don't mean to suggest using the centrifugo class. I meant to suggest copying the approach that they take to incorporate your own configmap into your chart - basically by copy-pasting their code and changing the names to your chart name and changing the path to your desired mount path. If you don't need it as part of the values then you could just put the static content into the configmap (or load with Files.Get) but would still need to mount the configmap.

– Ryan Dawson
Nov 20 '18 at 11:41













happy to chat if you like chat.stackoverflow.com/rooms/183948/…

– Ryan Dawson
Nov 20 '18 at 11:42





happy to chat if you like chat.stackoverflow.com/rooms/183948/…

– Ryan Dawson
Nov 20 '18 at 11:42




1




1





Thanks. I did try ConfigMap and it is working as expected. I will try getting it from values later and update how it goes.

– Chillax
Nov 21 '18 at 16:27





Thanks. I did try ConfigMap and it is working as expected. I will try getting it from values later and update how it goes.

– Chillax
Nov 21 '18 at 16:27




















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%2f53341089%2fhow-best-to-have-files-on-volumes-in-kubernetes-using-helm-charts%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

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly