View Kubernetes Secrets easily

View Kubernetes Secrets easily

Play this article

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 a 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 the 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 a 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.



I hope you learned something new from this blog post. Click here to learn about me and how you can support my work, Thank you.

Check out the video format of this blog.

Did you find this article valuable?

Support Suraj Narwade by becoming a sponsor. Any amount is appreciated!