Objects of type secret are intended to hold sensitive information, such as passwords, OAuth tokens, and ssh keys.
Putting this information in a secret is safer and more flexible than putting it verbatim in a pod definition or in a Docker image.
-
Create a file with secrets in Cloud Shell
echo -n 'Ood7ooch8a' > ./password.txt
-
Create a secret in k8s from file
kubectl create secret generic password --from-file=./password.txt
-
Get information about created secrets in k8s
kubectl get secrets
-
Describe previously created secret
kubectl describe secrets/password
-
Save the following file as
secretpod.yaml
apiVersion: v1 kind: Pod metadata: name: secretpod spec: containers: - name: secretpod image: redis volumeMounts: - name: pass mountPath: "/tmp/pass" readOnly: true volumes: - name: pass secret: secretName: password
-
Create the pod with attached secret password file
kubectl create -f secretpod.yaml
-
Login to created Pod
kubectl exec -it secretpod -- /bin/bash
-
Get password
cat /tmp/pass/password.txt
-
Delete the pod and secret
kubectl delete pod secretpod kubectl delete secret password
- Deploy
secretpod
but expose secret using an environment variables instead of usingvolumeMount
. Use official documentation for reference. - Exec into the container and ensure that you can access the secret from an environment variable.
- Convert the secret from the previous exercise to ConfigMap. Use official documentation for reference.