Using secrets with Kubernetes
In the Using secrets with Docker Swarm recipe, we showed how you can use secrets to store your passwords in a safe way using Docker Swarm. Kubernetes has a similar feature, so let's look at how it works.
Getting ready
You will need a Kubernetes cluster set up and configured, as described in the previous recipe.
How to do it...
Follow these steps:
- Add your secret to a file on your local machine:
$ echo -n "MyS3cRet123" > ./secret.txt
- Add your secret to Kubernetes:
$ kubectl create secret generic my-secret --from-file=./secret.txt secret/my-secret created
- View the secret to make sure it was added correctly:
$ kubectl describe secrets/my-secret

- Use your secret in a pod using a volume.
Create a file called secret_pod.yml
and put the following inside it. We will use the file to create a pod that has a volume where we will mount our secret:
apiVersion: v1 kind: Pod metadata: name: mypod spec: containers: - name: shell image: alpine command: -...