Introduction

A Kubernetes Secret is used to store sensitive data (like passwords, tokens, or keys) securely. Creating a Secret from a file is useful when you already have the secret value saved in a file (example: db_password.txt) and you want Kubernetes to manage it and provide it to Pods when needed.

Prerequisites

Before running the commands, ensure you have:

  • A running Kubernetes cluster (Minikube / Kind / EKS / AKS / GKE)
  • kubectl installed and connected to the cluster
  • The file db_password.txt available in your current directory
  • Access/permission to create Secrets in the target namespace

Steps (Create Secret from a File)

  1. Verify the file exists
ls -l db_password.txt
  1. Create the secret from the file
kubectl create secret generic db-secret --from-file=db_password.txt
  1. Confirm the secret is created
kubectl get secret db-secret
  1. View secret details (value is not shown)
kubectl describe secret db-secret

Conclusion

By creating a Secret from a file, you keep sensitive information out of your application code and configuration files. Kubernetes stores the file content securely and you can mount it into Pods when required, making deployments safer and easier to manage.

Leave a Reply