Skip to content

Commit

Permalink
inits secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
mhausenblas committed Apr 26, 2017
1 parent 1aae1f2 commit d70bf5a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ Browse the examples:
- [health checks](/healthz/)
- [environment variables](/envs/)
- [namespaces](/ns/)
- [secrets](/secrets/)

Want to try it out yourself? Follow the instructions [here](/diy/).
47 changes: 47 additions & 0 deletions content/page/secrets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
+++
title = "Secrets"
subtitle = "Kubernetes secrets by example"
date = "2017-04-26"
url = "/secrets/"
+++

You don't want sensitive information such as a database password or an
API key keep around in clear text. Secrets provide you with a mechanism
to use such information in a safe and reliable way.

Let's create a secret `apikey` that holds a (made-up) API key:

```bash
$ echo -n "A19fh68B001j" > ./apikey.txt

$ kubectl create secret generic apikey --from-file=./apikey.txt
secret "apikey" created

$ kubectl describe secrets/apikey
Name: apikey
Namespace: default
Labels: <none>
Annotations: <none>

Type: Opaque

Data
====
apikey.txt: 12 bytes
```

Now let's and use it in a [pod](https://github.com/mhausenblas/kbe/blob/master/specs/secrets/pod.yaml):

```bash
$ kubectl create -f https://raw.githubusercontent.com/mhausenblas/kbe/master/specs/secrets/pod.yaml
```

If we now exec into the container we see the secret mounted at `/tmp/apikey`:

```
$ kubectl exec consumesec -c shell -i -t -- bash
[root@consumesec /]# mount | grep apikey
tmpfs on /tmp/apikey type tmpfs (ro,relatime)
[root@consumesec /]# cat /tmp/apikey/apikey.txt
A19fh68B001j
```
20 changes: 20 additions & 0 deletions specs/secrets/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Pod
metadata:
name: consumesec
spec:
containers:
- name: shell
image: centos:7
command:
- "bin/bash"
- "-c"
- "sleep 10000"
volumeMounts:
- name: apikeyvol
mountPath: "/tmp/apikey"
readOnly: true
volumes:
- name: apikeyvol
secret:
secretName: apikey

0 comments on commit d70bf5a

Please sign in to comment.