Skip to content

Commit 8f9661f

Browse files
committed
Clarify secret usage with multiple keys or values
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 5a6559b commit 8f9661f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/reference/secrets.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,54 @@ For Kubernetes, secrets are stored [within the built-in secrets store](https://k
2727

2828
For faasd, secrets are created as plaintext files under `/var/lib/faasd-provider/secrets`. When you deploy a function, these secrets are bind-mounted into your container.
2929

30+
## Secrets with multiple keys or files
31+
32+
Let's explore an example where you have a function which needs to connect to two different databases. You will have two different connection strings, one for MongoDB and one for Postgresql as separate files under `/var/openfaas/secrets`:
33+
34+
* `/var/openfaas/secrets/mongo-connection.txt`
35+
* `/var/openfaas/secrets/postgres-connection.txt`
36+
37+
When using `faas-cli` to create and manage secrets, you can only have one file or literal within each Kubernetes secret, so you'll create two secrets with different names:
38+
39+
```bash
40+
faas-cli secret create mongo-connection \
41+
--from-file=mongo-connection.txt=./mongo-connection.txt
42+
43+
faas-cli secret create postgres-connection \
44+
--from-file=postgres-connection.txt=./postgres-connection.txt
45+
```
46+
47+
> Note that `openfaas-fn` is a default value for the `--namespace` flag, you don't need to specify it with `faas-cli`.
48+
49+
Then in stack.yml, you'll need to add both `mongo-connection` and `postgres-connection` to the `secrets` section.
50+
51+
```yaml
52+
functions:
53+
my-function:
54+
...
55+
secrets:
56+
- mongo-connection
57+
- postgres-connection
58+
```
59+
60+
With `kubectl`, you can have multiple files or literals within a single secret.
61+
62+
```bash
63+
kubectl create secret generic -n openfaas-fn database-connections \
64+
--from-file=mongo-connection.txt=./mongo-connection.txt \
65+
--from-file=postgres-connection.txt=./postgres-connection.txt
66+
```
67+
68+
You'll only need to add one secret to the `secrets` section in stack.yml.
69+
70+
```yaml
71+
functions:
72+
my-function:
73+
...
74+
secrets:
75+
- database-connections
76+
```
77+
3078
## Example of using a secret
3179

3280
Create a new function with the `python3-http` template:

0 commit comments

Comments
 (0)