0

What could be the kubectl command to see k8s secret values

I tried

kubectl get secrets/<secrets-name> -n <namespace>

It returns

NAME            TYPE     DATA   AGE
secrets1        Opaque   1      18h

but I want to know what value stored inside the secret

Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61

2 Answers2

2

Say you had a secret like the one below with a password key then something like this should work to obtain the value:

kubectl get secret/my-secret -n dev -o go-template='{{.data.password|base64decode}}'

apiVersion: v1
kind: Secret
metadata: 
  name: my-secret
  namespace: dev
type: Opaque
data: 
  password: TXEyRCMoOGdmMDk=
  username: cm9vdA==

Alan
  • 491
  • 4
  • 13
1

So the answer was so simple I just have to add -o jsonpath='{.data}' at the end of the command

kubectl get secrets/<secrets-name> -n <namespace>  -o jsonpath='{.data}'
Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61