Skip to content

Commit 4cc4253

Browse files
committed
Update secrets guide for K8s
- the openfaas-fn namespace is required but was missing from the command to create secrets and resulted in a user raising an issue Closes: openfaas/faas-netes#306 - language simplified and bespoke example replaced with a full example created with the CLI Signed-off-by: Alex Ellis (VMware) <[email protected]>
1 parent 491fe68 commit 4cc4253

File tree

1 file changed

+30
-58
lines changed

1 file changed

+30
-58
lines changed

docs/deployment/kubernetes.md

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -210,46 +210,17 @@ This section covers additional advanced topics beyond the initial deployment.
210210
If you are using a hosted private Docker registry ([Docker Hub](https://hub.docker.com/), or other),
211211
in order to check how to configure it, please visit the Kubernetes [documentation](https://kubernetes.io/docs/concepts/containers/images/#using-a-private-registry).
212212
213-
##### Deploy a function from a private Docker image
213+
If you try to deploy using `faas-cli deploy` it will fail because the Kubernetes kubelet component will not have credentials to authorize the pull request.
214214
215-
With the following commands you can deploy a function from a private Docker image, tag and push it to your docker registry account:
215+
Once you have pushed an image to a private registry using `faas-cli push` follow the instructions below to either create a pull secret that can be referenced by each function which needs it, or create a secret for the ServiceAccount in the `openfaas-fn` namespace so that any functions which need it can make use of it.
216216
217-
```bash
218-
$ docker pull functions/alpine:latest
219-
$ docker tag functions/alpine:latest $DOCKER_USERNAME/private-alpine:latest
220-
$ docker push $DOCKER_USERNAME/private-alpine:latest
221-
```
222-
223-
Log into the [Hub](https://hub.docker.com/) and make your image `private-alpine` private.
224-
225-
Then create your openfaas project:
226-
227-
```bash
228-
$ mkdir privatefuncs && cd privatefuncs
229-
$ touch stack.yaml
230-
```
231-
232-
In your favorite editor, open stack.yaml and add
233-
234-
```yml
235-
provider:
236-
name: faas
237-
gateway: http://127.0.0.1:8080
238-
239-
functions:
240-
protectedapi:
241-
lang: Dockerfile
242-
skip_build: true
243-
image: username/private-alpine:latest
244-
```
217+
If you need to troubleshoot the use of a private image then see the Kubernetes section of the [troubleshooting guide](./troubleshooting.md).
245218
246-
##### Create an image pull secret
219+
##### Option 1 - use an ad-hoc image pull secret
247220
248-
If you try to deploy using `faas-cli deploy` it will fail because Kubernetes can not pull the image. You can verify this in the Kubernetes dashboard or via the CLI using the `kubectl describe` command.
221+
To deploy your function(s) first you need to create an [Image Pull Secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) with the commands below.
249222
250-
To deploy the function, you need to create an [Image Pull Secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/)
251-
252-
You should set the following environmental variables:
223+
Setup some environmental variables:
253224
254225
```bash
255226
export DOCKER_USERNAME=<your_docker_username>
@@ -261,41 +232,37 @@ Then run this command to create the secret:
261232
262233
```bash
263234
$ kubectl create secret docker-registry dockerhub \
235+
-n openfaas-fn \
264236
--docker-username=$DOCKER_USERNAME \
265237
--docker-password=$DOCKER_PASSWORD \
266238
--docker-email=$DOCKER_EMAIL
267239
```
268240
269-
Then you need to add the secret to your `stack.yml` file:
241+
> Note if not using the Docker Hub you will also need to pass `--docker-server` and the address of your remote registry.
270242
271-
```yml
272-
secrets:
273-
- dockerhub
243+
The secret *must* be created in the `openfaas-fn` namespace or the equivalent if you have customised this.
244+
245+
Create a sample function with a `--prefix` variable:
246+
247+
```sh
248+
faas-cli new --lang go private-fn --prefix=registry:port/repo
249+
mv private-fn.yml stack.yml
274250
```
275251
276-
This is a `stack.yml` example with the secret added in it:
252+
Update the `stack.yml` file and add a reference to the new secret:
277253
278254
```yml
279-
provider:
280-
name: faas
281-
gateway: http://127.0.0.1:8080
282-
283-
functions:
284-
protectedapi:
285-
lang: Dockerfile
286-
skip_build: true
287-
image: username/private-alpine:latest
288-
secrets:
255+
secrets:
289256
- dockerhub
290257
```
291258
292-
You can deploy your function using `faas-cli deploy`. If you inspect the Kubernetes pods, you will see that it can pull the docker image.
259+
Now deploy the function using `faas-cli up`.
293260
294-
##### Link the image pull secret to a namespace service account
261+
##### Option 2 - Link an image pull secret to the namespace's ServiceAccount
295262

296-
Instead of always editing the function .yml you can link your private Docker repository secret to the Kubernetes namespace service account manifest. This will auto add the `imagePullSecret` property to any deployment/pod manifest refrencing an image in that particular private repo.
263+
Rather than specifying the pull secret for each function that needs it you can bind the secret to the namespace's ServiceAccount. With this option you do not need to update the `secrets:` section of the `stack.yml` file.
297264
298-
Create the image pull secret in the `openfaas-fn` namespace:
265+
Create the image pull secret in the `openfaas-fn` namespace (or equivalent):
299266
300267
```bash
301268
$ kubectl create secret docker-registry my-private-repo \
@@ -305,9 +272,13 @@ $ kubectl create secret docker-registry my-private-repo \
305272
--namespace openfaas-fn
306273
```
307274
308-
Open up the service account manifest for editing:
275+
If needed, pass in the `--docker-server` address.
309276
310-
`kubectl edit serviceaccount default -n openfaas-fn`
277+
Use the following command to edit the default ServiceAccount's configuration:
278+
279+
```sh
280+
$ kubectl edit serviceaccount default -n openfaas-fn
281+
```
311282

312283
At the bottom of the manifest add:
313284

@@ -316,8 +287,9 @@ imagePullSecrets:
316287
- name: my-private-repo
317288
```
318289

319-
Save your changes.
320-
OpenFaaS will now deploy functions with images in private repositories without having to specify the secret in the deployment manifests.
290+
Save the changes in the editor and this configuration will be applied.
291+
292+
The OpenFaaS controller will now deploy functions with images in private repositories without having to specify the secret in the `stack.yml` file.
321293

322294
#### Set a custom ImagePullPolicy
323295

0 commit comments

Comments
 (0)