{"id":1868,"date":"2020-04-07T22:18:06","date_gmt":"2020-04-07T19:18:06","guid":{"rendered":"https:\/\/artem.services\/?p=1858"},"modified":"2020-04-07T22:30:58","modified_gmt":"2020-04-07T19:30:58","slug":"1868","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1868&lang=en","title":{"rendered":"Helm &#8212; Creating Secret from Variable"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1859\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/helm-logo.png\" alt=\"\" width=\"304\" height=\"351\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/helm-logo.png 304w, https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/helm-logo-260x300.png 260w\" sizes=\"(max-width: 304px) 100vw, 304px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>In order to save the value of the variable as <strong>Secret<\/strong>, the variable must be encoded in <strong>base64<\/strong>, for this we use &quot;<strong>_helpers.tpl<\/strong>&quot;<\/p>\n<p>For example, we need to save the value of the variable &quot;<strong>applicationSecret<\/strong>&quot;<\/p>\n<h3>values.yaml:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Default values for artem-services.\r\n# This is a YAML-formatted file.\r\n# Declare variables to be passed into your templates.\r\n\r\nreplicaCount: 1\r\nnamespace: default\r\n\r\nimage:\r\n  repository: XXXXXXXXXXXX.dkr.ecr.eu-east-1.amazonaws.com\/artem-services\r\n  tag: 1.0.1\r\n  pullPolicy: IfNotPresent\r\n\r\nnameOverride: &quot;&quot;\r\nfullnameOverride: &quot;artem-services&quot;\r\n\r\napplicationSecret: |\r\n  var1=value1\r\n  var2=value2\r\n  var3=value3\r\n  var4=value4\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Add the following to &quot;<strong>_helpers.tpl<\/strong>&quot;:<\/p>\n<h3>_helpers.tpl:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n{{- define &quot;applicationSecret&quot; }}\r\n{{- printf .Values.applicationSecret | b64enc }}\r\n{{- end }}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Now in the &quot;<strong>templates<\/strong>&quot; directory, create the file &quot;<strong>secret.yaml<\/strong>&quot;<\/p>\n<h3>secret.yaml:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\napiVersion: v1\r\nkind: Secret\r\ntype: Opaque\r\nmetadata:\r\n  name: &quot;{{ .Chart.Name }}-application&quot;\r\ndata:\r\n  application.conf: {{ template &quot;applicationSecret&quot; . }}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; In order to save the value of the variable as Secret, the variable must be encoded in base64, for this we use &quot;_helpers.tpl&quot; For example, we need to save the value of the variable &quot;applicationSecret&quot; values.yaml: &nbsp; Add the following to &quot;_helpers.tpl&quot;: _helpers.tpl: &nbsp; Now in the &quot;templates&quot; directory, create the file &quot;secret.yaml&quot; secret.yaml:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1513],"tags":[1533,1535,1027,1537],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1868"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1868"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1868\/revisions"}],"predecessor-version":[{"id":1870,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1868\/revisions\/1870"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}