Skip to content

Commit 001bf97

Browse files
ivanayovalexellis
authored andcommitted
Add docs for how to use a private registry with Kubernetes
This adds the following documentation: how to configure a private registry (link to Kubernetes documentation), how to create an image pull secret and add the secret to an yaml file, how to pull a function from a private Docker image and push it to a Docker registry. Signed-off-by: Ivana Yovcheva (VMware) <[email protected]>
1 parent 7354ce2 commit 001bf97

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

docs/deployment/kubernetes.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,91 @@ $ echo -n "" | faas-cli invoke --gateway http://kubernetes-ip:31112 nodeinfo
185185
$ echo -n "verbose" | faas-cli invoke --gateway http://kubernetes-ip:31112 nodeinfo
186186
```
187187
188+
### 4.0 Use a private registry with Kubernetes
189+
190+
If you are using a hosted private Docker registry ([Docker Hub](https://hub.docker.com/), or other),
191+
in order to check how to configure it, please visit the Kubernetes [documentation](https://kubernetes.io/docs/concepts/containers/images/#using-a-private-registry).
192+
193+
#### Deploy a function from a private Docker image
194+
195+
With the following commands you can deploy a function from a private Docker image, tag and push it to your docker registry account:
196+
197+
```bash
198+
$ docker pull functions/alpine:latest
199+
$ docker tag functions/alpine:latest $DOCKER_USERNAME/private-alpine:latest
200+
$ docker push $DOCKER_USERNAME/private-alpine:latest
201+
```
202+
203+
Log into the [Hub](https://hub.docker.com/) and make your image `private-alpine` private.
204+
205+
Then create your openfaas project:
206+
207+
```bash
208+
$ mkdir privatefuncs && cd privatefuncs
209+
$ touch stack.yaml
210+
```
211+
212+
In your favorite editor, open stack.yaml and add
213+
214+
```yml
215+
provider:
216+
name: faas
217+
gateway: http://localhost:8080
218+
219+
functions:
220+
protectedapi:
221+
lang: Dockerfile
222+
skip_build: true
223+
image: username/private-alpine:latest
224+
```
225+
226+
#### Create an image pull secret
227+
228+
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.
229+
230+
To deploy the function, you need to create an [Image Pull Secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/)
231+
232+
You should set the following environmental variables:
233+
234+
```bash
235+
export DOCKER_USERNAME=<your_docker_username>
236+
export DOCKER_PASSWORD=<your_docker_password>
237+
export DOCKER_EMAIL=<your_docker_email>
238+
```
239+
240+
Then run this command to create the secret:
241+
242+
```bash
243+
$ kubectl create secret docker-registry dockerhub \
244+
--docker-username=$DOCKER_USERNAME \
245+
--docker-password=$DOCKER_PASSWORD \
246+
--docker-email=$DOCKER_EMAIL
247+
```
248+
249+
Then you need to add the secret to your `stack.yml` file:
250+
251+
```yml
252+
secrets:
253+
- dockerhub
254+
```
255+
256+
This is a `stack.yml` example with the secret added in it:
257+
258+
```yml
259+
provider:
260+
name: faas
261+
gateway: http://localhost:8080
262+
263+
functions:
264+
protectedapi:
265+
lang: Dockerfile
266+
skip_build: true
267+
image: username/private-alpine:latest
268+
secrets:
269+
- dockerhub
270+
```
271+
272+
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.
188273
189274
## 3.1 Start the hands-on labs
190275

0 commit comments

Comments
 (0)