Kubernetes: Putting JSON value in YAML file
10,671
Solution 1
You can fix this by changing {{ .Values.dbCred | b64enc }}
to {{ toJson .Values.dbCred | b64enc }}
Solution 2
Alternatively, you can keep your credentials.json file inside chart directory, and access file inside your template
data:
credentials.json: {{ .Files.Get "credentials.json" | b64enc }}
Related videos on Youtube
Author by
Kamil Kamili
Updated on June 04, 2022Comments
-
Kamil Kamili almost 2 years
I am trying to create a secret from a JSON value but I keep getting this error executing
"secrets.yaml" at <b64enc>: wrong type for value; expected string; got map[string]interface {}
when I dohelm install
.secrets.yaml
apiVersion: v1 kind: Secret metadata: name: cloudsql-instance-credentials namespace: wp-{{ .Values.name }} labels: app: wp-{{ .Values.name }} type: Opaque data: credentials.json: {{ .Values.dbCred | b64enc }}
values.yaml
dbCred: { 'type': '', 'project_id': '', 'private_key_id': '', 'private_key': '-----BEGIN PRIVATE KEY-----\n\n-----END PRIVATE KEY-----\n', 'client_email': '', 'client_id': '', 'auth_uri': '', 'token_uri': '', 'auth_provider_x509_cert_url': '', 'client_x509_cert_url': '' }
-
Ryan Dawson over 5 yearsTry
toJson .Values.dbCred | b64enc
. Or you could even try putting the values in json structure in the values.yaml as yaml and letting helm convert to json for you - stackoverflow.com/a/53342487/9705485
-
-
Ryan Dawson over 5 yearsI tried putting that secrets.yaml and values entry into an example chart generated with
helm create
and was able to recreate the error. I then made this change and found I then don't get the error -
gmaghera over 4 yearsSo slick! Exactly what I was looking for.
-
Ryan Dawson over 3 years@O’Dane Brissett Bit confused by the question. This example discussed is a secrets.yaml
-
O'Dane Brissett over 3 yearsI'm using octopus deploy to set the variable then substitute the values in my helm. However using the example above i get the error
did not find expected key
-
Ryan Dawson over 3 years@O’Dane Brissett I'd suggest trying it outside of octopus, If that works then you know it's a problem at the octopus level. If it doesn't work then I'd suggest a new question on SO or an issue on the helm repo.