2
2
3
3
This repository demonstrates a few things:
4
4
- run a Docker registry as a [ Knative] ( https://knative.dev ) Service
5
- - build an image using [ Tekton] ( https://tekton.dev ) and push it to that registry
6
- - run that image as a Knative Service
5
+ - build an application image using [ Tekton] ( https://tekton.dev ) and push it
6
+ to that registry
7
+ - run that application image as a Knative Service
7
8
8
9
Why? Couple of reasons:
9
10
- show how it's possible to run someting that is not traditionally thought of
10
11
as a "function" as a Knative service
11
12
- show how to use Tekton as a replacement for Knative's Build feature, which
12
13
is almost gone now
13
14
- show how to use a local registry for times when you just don't want to deal
14
- with noise like authentication and service accounts - mainly for demos
15
+ with noise like authentication and service accounts - see
16
+ [ Some final notes] ( #some-final-notes )
15
17
16
18
## Faking it
17
19
@@ -35,7 +37,7 @@ the instructions
35
37
36
38
As of today Tekton (the replacement for Knative Build) is not installed
37
39
by default in IKS's Knative install, it will be soon, but for now you'll
38
- need to install it youself :
40
+ need to install it yourself :
39
41
40
42
``` bash
41
43
$ kubectl apply -f https://storage.googleapis.com/tekton-releases/latest/release.yaml
@@ -62,12 +64,13 @@ to explain what's going on.
62
64
First, we need to upload the source code for our application into
63
65
Kubernetes so that our build process can use it. In this case we're going
64
66
to use a ConfigMap. This has a few nice aspects to it:
65
- - it's easily populated via the ` --from-file ` option on ` kubectl `
67
+ - it's easily populated via the ` --from-file ` option on
68
+ ` kubectl create configmap `
66
69
- it can be mounted as a volume into a pod fairly easily
67
- - if necessary I can switch it to use a Secret instead if security is an issue
70
+ - if necessary, I can switch it to use a Secret instead if security is an issue
68
71
- can use it with Knative services too at some point if I wanted to. Right now
69
- Knative doesn't allow generic Volumes to be mounted into Knative Services
70
- - sadly.
72
+ Knative doesn't allow generic Volumes to be mounted into Knative Services -
73
+ sadly
71
74
72
75
``` bash
73
76
$ kubectl create cm source --from-file=src
@@ -109,7 +112,7 @@ If you're not familiar with Knative yet I would suggest you look at the
109
112
other intro demo I have [ here] ( https://github.com/duglin/helloworld ) to
110
113
understand the basic outline of this yaml.
111
114
112
- In this particular KnService I wanted to point out a couple of key things.
115
+ In this particular Knative Service I wanted to point out a couple of key things.
113
116
First, ` minScale ` and ` maxScale ` are both set to ` 1 ` . This means that Knative
114
117
will always have exactly one instance of the ` docker.io/registry ` image
115
118
running. In a perfect world I would let this scale up and down based on the
@@ -119,17 +122,17 @@ deleted, all images stored in this registry will be lost. Likewise, because
119
122
there's no Volume, I can't share it across multiple instances of the Service
120
123
to handle a large load. Thus, I'm stuck with exactly one instance.
121
124
122
- Why? Because, as I mentioned previously, Knative doesn't allow generic Volumes
125
+ As I mentioned previously, Knative doesn't allow generic Volumes
123
126
to be mounted. Why? Because not everyone supports it yet, so therefore they
124
- decided to block it for everyone. A poor decision in to me, but that's
127
+ decided to block it for everyone. A poor decision to me, but that's
125
128
the current state of things. If you want to watch how this progresses
126
129
you can watch [ this] ( https://github.com/knative/serving/issues/4417 ) .
127
130
128
131
Finally, notice that it says ` containerPort: 5000 ` . By default the Registry
129
132
will listen on port 5000, so I need to tell Knative to route all requests to
130
133
this port number. This allows me to continue to use http and https to talk to
131
134
the Registry using the normal IKS/Knative networking that's automatically
132
- setup.
135
+ setup for you .
133
136
134
137
Now let's create the ` hub ` Knative Sevice:
135
138
@@ -170,7 +173,7 @@ I'm not going to go into
170
173
Tekton too much, for that you can go look at its [ docs] ( https://tekton.dev )
171
174
or this
172
175
[ tutorial] ( https://developer.ibm.com/tutorials/knative-build-app-development-with-tekton/ ) .
173
- For now, just know that Tekton is a build tool similar to Jeknins , that will
176
+ For now, just know that Tekton is a build tool similar to Jenkins , that will
174
177
perform a set of tasks that you tell it. The above yaml file defines one
175
178
such Task. Tasks can be comprised of one or more "steps" - each is just
176
179
the execution of a container image. In this particular case we're running
@@ -218,15 +221,15 @@ it with this command:
218
221
$ kubectl get taskrun/build-image -w
219
222
```
220
223
221
- When you see something that looks like this (SUCCEEDED is ` true ` ):
224
+ When you see something that looks like this (SUCCEEDED is ` True ` ):
222
225
223
226
``` bash
224
227
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
225
228
build-image True 55s 1s
226
229
```
227
230
228
- then it's done. If something appears to have gone wrong, look at the
229
- TaskRun to get more info with this command:
231
+ then it's done and you can stop it by pressing ctrl-c. If something appears to
232
+ have gone wrong, look at the TaskRun to get more info with this command:
230
233
231
234
``` bash
232
235
$ kubectl get taskrun/build-image -o yaml
@@ -263,7 +266,8 @@ spec:
263
266
```
264
267
265
268
Nothing too exciting here other than the ` image ` property points to our
266
- newly created image that's stored in our local Docker Registry.
269
+ newly created image that's stored in our local Docker Registry. Make sure
270
+ the image name here matches the image name from the Task used to build it.
267
271
268
272
Let's create it:
269
273
@@ -276,7 +280,7 @@ Now wait for the service to be ready. You can run this command:
276
280
277
281
``` bash
278
282
$ kubectl get ksvc/hello
279
- NAME URL LATESTCREATED LATESTREADY READY REASON
283
+ NAME URL LATESTCREATED LATESTREADY READY REASON
280
284
hello http://hello-default.kntest.us-south.containers.appdomain.cloud hello-mv9bv hello-mv9bv True
281
285
```
282
286
@@ -287,7 +291,8 @@ until the `READY` column shows `True`.
287
291
Then we can test our app using te URL shown in the output above:
288
292
289
293
``` bash
290
- curl -s http://hello-default.kntest.us-south.containers.appdomain.cloud
294
+ $ curl -s http://hello-default.kntest.us-south.containers.appdomain.cloud
295
+ 4fh4n: Hello World!
291
296
```
292
297
293
298
All done, so let's clean-up:
@@ -298,14 +303,14 @@ $ kubectl delete -f service.yaml -f hub.yaml
298
303
299
304
## Some final notes
300
305
301
- As I mentioned previsously , I picked Docker's Registry for a couple of
302
- reasons. Most noteably , it allows people to use a local Docker Registry
306
+ As I mentioned previously , I picked Docker's Registry for a couple of
307
+ reasons. Most notably , it allows people to use a local Docker Registry
303
308
without the need to complicate demos/workshops with authentication, secrets
304
309
and service accounts. Clearly, those are all needed in real-world environments
305
310
but when you're trying to teach someone about Knative, those things just
306
311
complicate matters and are a distraction.
307
312
308
- I also liked the idea of using the Docker Registry because it allow me to
313
+ I also liked the idea of using the Docker Registry because it allows me to
309
314
show-off using a non-traditional serverless workload. Granted, it would have
310
315
been nice if the Registry supported scaling while using a shared Volume
311
316
to make the point that Knative should support generic Volumes, but
@@ -321,9 +326,9 @@ rebooted.
321
326
322
327
One thing I didn't hook-in yet are
323
328
[ Registry Notifications] ( https://docs.docker.com/registry/notifications/ ) .
324
- I haven't played with this yet but it looks like we should be able to get
329
+ I haven't played with this yet, but it looks like we should be able to get
325
330
notifications about image updates that could then cause a new Knative
326
331
Service Revision to be deployed - just like the old Knative Build feature
327
- supported.
332
+ supported. Perhaps I'll work on that one next...
328
333
329
334
If you have any comments or questions, ping me.
0 commit comments