View Kubernetes Secrets easily

Suraj Narwade
Suraj in Cloud
Published in
2 min readDec 13, 2022
Photo by Stefan Steinbauer on Unsplash

Often we find it difficult to visualize the Kubernetes secrets as they are base64 encoded. you will need to manually copy the encoded data and then decode it or write small custom shell scripts for the same.

Fortunately, there’s kubectl plugin to simplify this process. view-secret the plugin allows users to view the contents of a secret without having to decode it manually.

Check out the project on GitHub:

If you find the tool useful, make sure you ⭐️ the repo and show your love for the project :)

To use the kubectl view-secret plugin, you first need to install it on your system. You can do this by running the following command:

$ kubectl krew install view-secret

Note: above command will only work if you have Krew installed.

Once the plugin is installed, you can use it by running the following command:

$ kubectl view-secret [SECRET_NAME]

This will display the contents of the secret in plain text. For example, if you have a secret named mysecret,

$ kubectl get secret mysecret -o yaml
apiVersion: v1
data:
foo: YmFy
kind: Secret
metadata:
name: my-secret
namespace: default
type: Opaque

Ideally, you would have to decode the value manually and view the secret, for example,

$ echo "YmFy" | base64 -d
bar

with view-secret plugin you can view its contents by running the following command:

$ kubectl view-secret mysecret
Choosing key: foo
bar

This will print the contents of the secret in plain text, allowing you to easily view and manage the secret without having to decode it manually.

another interesting use case can be, if secret has more than one key-value in it,

$ kubectl get secret mysecret -o yaml
apiVersion: v1
data:
bar: Zm9v
foo: YmFy
kind: Secret
metadata:
name: mysecret
namespace: default
type: Opaque

you can now explore secret using the plugin as follow,

$kubectl view-secret mysecret
Multiple sub keys found. Specify another argument, one of:
-> bar
-> foo
$ kubectl view-secret mysecret foo
bar
$ kubectl view-secret mysecret bar
foo

In conclusion, the kubectl view-secret a plugin is a useful tool for viewing secrets in Kubernetes clusters. It allows users to view the contents of a secret in plain text.

If you enjoyed this post, please consider following me for more content like this.

Check out the video format of this blog.

--

--

Suraj Narwade
Suraj in Cloud

All things Cloud, Containers & Developer Experience