In K8S, how to use data from existed secret when creating new secret?

11/24/2018

We got an existed secret in K8S(suppose it is "secret_1") and we want to write a yaml to create a new secret "secret_2", using some values from secret_1.

That is, in this yaml we'd like to

  1. Read values from other secret
  2. Store values to new secret

Is it possible to do this? It will be great help if a sample can be provided.

Thanks in advance.

-- Lijing Zhang
kubernetes
kubernetes-helm
templates

1 Answer

11/24/2018

You cannot do this directly in YAML. You would need to write a script of some kind to do the steps you described, though you can use kubectl get secret -o yaml (or -o json) for a lot of the heavy lifting, possibly with jq for the reformatting.

-- coderanger
Source: StackOverflow