How to Create Secrets in Kubernetes
Planted .
Similar to how to create a ConfigMap, we create secrets:
- Using a file
- Using command line
Sample file
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
username: YWRtaW4=
password: MWYyZDFlMmU2N2Rm
Note that the fields in data field need to be encoded in base64.
So as an example echo “root” | base64
Using CLI
kubectl create secret generic db-user-pass \
--from-literal=username=root \
--from-literal=password='whatever'