Course contentsShow
← Cloud and Infrastructure
Lesson 1261 of 2,98925. Kubernetes Configuration and SecretsFree lesson

Creating Secrets from Literals

Learn to create Secrets imperatively using kubectl with literal key-value pairs on the command line.

Creating Secrets from Literals

What you'll learn: How to quickly create Kubernetes Secrets directly from the command line using literal key-value pairs.

What Are Literal Secrets?

Just as you learned to create ConfigMaps imperatively with kubectl, Kubernetes lets you create Secrets the same way. A literal Secret means you provide the sensitive data (passwords, tokens, keys) directly on the command line as key-value pairs, without needing a YAML file or external file.

Think of it like handing someone a sealed envelope with a password written on a slip of paper inside—you're creating the secret container and its contents in one quick action.

Creating a Secret from Literals

Use the kubectl create secret generic command followed by a name and one or more --from-literal flags:

kubectl create secret generic db-credentials \
  --from-literal=username=admin \
  --from-literal=password=secretpass123

This creates a Secret named db-credentials with two keys: username and password. Kubernetes automatically base64-encodes these values for storage.

When to Use This Approach

Creating Secrets from literals is ideal for:

  • Quick testing during development
  • Single or few values that don't warrant a file
  • Interactive setup where you type sensitive data directly

However, avoid this for production workflows where secrets should come from secure vaults or CI/CD pipelines—typing passwords in command history is a security risk.

Verifying Your Secret

Check that your Secret was created:

kubectl get secrets
kubectl describe secret db-credentials

Note that describe won't show the actual values—they're encoded and protected.

Key Takeaway: Use kubectl create secret generic with --from-literal flags to quickly create Secrets from command-line key-value pairs, perfect for development but requiring caution with command history in production environments.