← All posts

Secrets on a Kubernetes Cluster

In this tutorial I show you how to add secrets to a Kubernetes cluster. Secrets are a way to store sensitive information such as passwords, tokens, and keys. Kubernetes secrets are stored in base64 encoded format and can be mounted as files or environment variables in a pod. This is a great way to keep sensitive information out of your code and configuration files.

Step by Step Guide

1. Create an opaque secret

kubectl create secret generic my-secret

2. Base64 encode the secret value

echo "MySecretPassword" | base64

3. Edit the secret and populate with the base64 encoded string

kubectl edit secret my-secret

Create a data key with the base64 encoded string: The data key would be the variable you wish to store the secret in.

data:
  password: <base64 encode string from above>

Save and exit the editor

Press ESC and type :wq to save and exit the editor.

If you need to decode the secret, you can use the following command:

echo "<base64 encode string from above>" | base64 -D