Search code examples
kuberneteskubernetes-secrets

cannot decode kubernetes secrets with base64


I'm trying to get secrets with kubectl with:

kubectl get secrets/postgresql -n my-namespace -o=go-template=='{{index .data "postgresql-password" }}'

it returns the correct value ( I get the same result with lens )

But when I do:

kubectl get secrets/postgresql -n my-namespace -o=go-template=='{{index .data "postgresql-password" }}' | base64 -d

I get:

base64: invalid input

But Lens can decode it easily. What am I doing wrong ?


Solution

  • First check command :

    kubectl get secrets/postgresql -n my-namespace -o=go-template=='{{index .data "postgresql-password" }}'
    

    if you see base64 string it is good. But also you can see "=" in the start and the end of this string.

    Just try to run the following :

    kubectl get secrets/postgresql -n my-namespace -o=go-template='{{index .data "postgresql-password" }}' | base64 -d