** Example:1 **
vi mysecret.yaml
apiVersion: v1
kind: Secret
metadata:
name: my-secret-pod
stringData:
user: admin
password: PaSsW0rD
kubectl create -f mysecret.yaml
kubectl get secret
kubectl get secret my-secret-pod -o yaml
Base-64 Encoding:
echo -n 'admin' | base64
echo -n 'PaSsW0rD' | base64
** Example:2 **
vi my-secret-env.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-secret-env-pod
spec:
containers:
name: my-secret-redis-container
image: redis
env:
name: secret_user
valueFrom:
secretKeyRef:
name: my-secret-pod
key: user
name: secret_password
valueFrom:
secretKeyRef:
name: my-secret-pod
key: password
kubectl create -f my-secret-env.yaml
** Example:3 **
vi my-secret-vol.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-secret-vol-pod
spec:
containers:
name: my-secret-vol-container
image: busybox
command: ['sh', '-c', "echo $(ls /etc/config/) && sleep 3600"]
volumeMounts:
name: mysecretvolume
mountPath: /etc/config
volumes:
name: mysecretvolume
secret:
secretName: my-secret-pod
kubectl create -f my-secret-vol.yaml
kubectl logs my-secret-vol-pod
kubectl exec my-secret-vol-pod -- cat /etc/config/password
kubectl exec my-secret-env-pod -- printenv