I’ve been looking into how to learn terraform. I have also discovered for my project I need to use
Kubernetes.
It turns out that it is really easy to create a kubernetes cluster on the local desktop to have
a play with. Here goes:
I got started using the following tutorial
I used Kubernetes in Docker (kind) to test. This turned out to be really easy to install.
I already had Docker installed, so I didn’t need to worry about that. I downloaded kind from it’s website - there is a compiled executable which is easiest.
The instructions say on Linux:
Once I had finished the tutorial, I wanted to be able to start working on some containers I had made in our local docker repo.
This requires me to use a secret. To do this, I needed to add the secret to kubernetes:
For some reason while you specify generic when the password is created,
kubernetes says the type is opaque when you read it back. The inconsistent
terminology can be a little confusing.
$ kubectl get pods
$ kubectl exec --stdin --tty mycontainer-8588bb5c4f-xr9lm --/bin/bash
# cd /mnt
# ls
mypass1 mypass2
# cat mypass1
p@assw0rd
# cat mypass2
s0pers3kr3t
A note about config maps
Kubernets has config maps. These work in the
same way, as secrets, but aren’t secret. So instead of passing a
dozen environment variables, we can pass a config
map that contains them all.
To share it as an environment variable, we do exactly the same as with the secrets, but replace secret_ref
with config_map_ref. Similarly to mount a config map we replace the secret configuration:
volume {
name = "passwords" config_map {
name = "dbpass" }
}
Obviously we wouldn’t be storing passwords in the config map, so the names would change as well, but this demonstrates how similar
config maps and secrets are. The volume once defined is mounted in exactly the same way as with the secrets.
Conclusion
So now I have learned how to use Secrets in kubernetes. I can mount them as a filesystem, or I can
pass them as environment variables. The same applies to config maps. This is nice as we can have a
config map and secret pair for each of for development, staging and production.