Score:0

kubernetes: how to link secret tls crt/key with files or configMap?

ec flag

Is there a way to link secret tls crt/key with files?

apiVersion: v1
kind: Secret
metadata:
  name: hello-app-tls
  namespace: dev
type: kubernetes.io/tls
data:
  tls.crt: <crt_filePath>
  tls.key: <key_filePath>

Or reference values from a ConfigMap like:

apiVersion: v1
kind: Secret
metadata:
  name: hello-app-tls
  namespace: dev
type: kubernetes.io/tls
data:
  tls.crt:
    valueFrom:
       configMapKeyRef:
         name: configmap_tls
         key: crt
  tls.key:
    valueFrom:
       configMapKeyRef:
         name: configmap_tls
         key: key

Error:

Secret in version "v1" cannot be handled as a Secret: json: cannot unmarshal object into Go struct field Secret.data of type []uint8
Fariya Rahmat avatar
ve flag
Did you have time to check my answer? It helped you to solve your issue? If not, I am happy to assist further.
Score:0
ve flag

That cryptic error about unmarshalling string to a map of string means that the module was unable to resolve the content of values parameter to the contents of the actual file. Which caused the issue.

In your secret you can't give data directly. You have to encode your data in base64 format.

As mentioned in the github link by @ MadEngineX, try running the below command at data field:

tls.crt: {{ .Files.Get "api-gateway/google/files/tls.crt" | b64enc | quote  }}

Or

tls.crt: {{ .Files.Get "api-gateway/google/files/tls.crt" | toString | b64enc | quote   }}

Example-

apiVersion: v1
kind: Secret
metadata:
  name: hello-app-tls
  namespace: dev
type: kubernetes.io/tls
data:
  tls.crt: {{ .Files.Get "api-gateway/google/files/tls.crt" | b64enc | quote  }}
eastwater avatar
ec flag
api-gateway/google/files/tls.crt: where is it located? thanks.
Fariya Rahmat avatar
ve flag
I have updated my answer. Kindly refer to the Github link mentioned above for clear understanding.
eastwater avatar
ec flag
error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Files.Get \"ssl/cert.pem\" | b64enc | quote":interface {}(nil)}
Fariya Rahmat avatar
ve flag
Refer to this Github [link](https://github.com/helm/helm/issues/2004). Let me know if this helps.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.