0
0
Kubernetesdevops~30 mins

Creating Secrets in Kubernetes - Try It Yourself

Choose your learning style9 modes available
Creating Secrets
📖 Scenario: You are managing a Kubernetes cluster for a small web application. You need to securely store sensitive information like database passwords so that your application can access them safely without exposing them in plain text.
🎯 Goal: Learn how to create a Kubernetes Secret resource using a YAML manifest. You will create a secret with a database username and password, then verify it is created correctly.
📋 What You'll Learn
Create a Kubernetes Secret manifest file named db-secret.yaml
Include exact keys username and password with base64 encoded values
Use kubectl apply -f db-secret.yaml to create the secret
Use kubectl get secret db-secret -o yaml to verify the secret
💡 Why This Matters
🌍 Real World
Kubernetes Secrets are used to store sensitive information like passwords, tokens, and keys securely so that applications can access them without exposing them in plain text.
💼 Career
Knowing how to create and manage Kubernetes Secrets is essential for DevOps engineers and cloud administrators to maintain secure application deployments.
Progress0 / 4 steps
1
Create the Secret YAML skeleton
Create a file named db-secret.yaml with the following exact content:
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
Kubernetes
Need a hint?

Start by writing the YAML keys exactly as shown. The data section will hold your encoded secrets.

2
Add base64 encoded username and password
Add two keys under data: username with value YWRtaW4= (which is base64 for 'admin') and password with value c2VjcmV0MTIz (which is base64 for 'secret123'). Indent these keys correctly under data.
Kubernetes
Need a hint?

Remember to indent the username and password keys two spaces under data.

3
Apply the Secret manifest to the cluster
Run the exact command kubectl apply -f db-secret.yaml in your terminal to create the secret in your Kubernetes cluster.
Kubernetes
Need a hint?

This command tells Kubernetes to create or update the secret from your YAML file.

4
Verify the Secret was created
Run the exact command kubectl get secret db-secret -o yaml to display the secret details and confirm the keys username and password exist with the correct base64 values.
Kubernetes
Need a hint?

This command shows the secret's stored data so you can check it matches your input.