Is it possible to create a string array secret in k8s?

4/16/2020

I'm trying to store a string array as a secret; I have this secrets.yml file that I'm using in my local environment and works perfectly (values are for explanation purposes only):

secrets.yml

passwordz:
  - pass_001
  - pass_002
  - pass_003

The idea is to be able to store multiple passwords, and I want to use them as part of a k8s secret but had no luck so far; something like this:

k8s-secrets.yml

apiVersion: v1
kind: Secret
metadata:
  name: master-passwordz
type: Opaque
data:
  secrets.yml: |-
    passwordz: CiAgLSBwYXNzXzAwMQogIC0gcGFzc18wMDIKICAtIHBhc3NfMDAz

At the time to try to apply this secret:

kubectl apply -f ./k8s-secrets.yml

I'm getting the following error:

Error from server (BadRequest): error when creating "k8s-secrets.yml": Secret in version "v1" cannot be handled as a Secret: v1.Secret.ObjectMeta: v1.ObjectMeta.TypeMeta: Kind: Data: decode base64: illegal base64 data at input byte 3

Any idea if it's possible to accomplish this?

-- Cas1337
kubernetes
kubernetes-secrets

2 Answers

4/16/2020

No, the values must be a []byte, i.e. a string of some kind. You would have to store your array with some kind of encoding (usually JSON) so it's a simple string.

-- coderanger
Source: StackOverflow

4/16/2020

Could you try using "stringData" instead of "data". AFAIK this key should be used when you don't provide complete base64 encoded data in Secrets.

-- Alex
Source: StackOverflow