This project demonstrates how to implement CustomResourceDefinition (CRD) controllers using the Knative API server event source feeding Knative services.
This is a Knative variant of the sample controller project.
- A Kubernetes cluster with Knative 0.6.0
- envsubst installed locally. This is installed by the gettext package. If not installed it can be installed by a Linux package manager, or by Homebrew on OS X.
- Clone this repository somewhere not under $GOPATH
- Set $DOCKER_USER
- Build and publish the sample-controller docker image
go get ./...
CGO_ENABLED=0 GOOS=linux go build -o sample-controller cmd/reconcile/main.go
docker build -t $DOCKER_USER/sample-controller .
docker push $DOCKER_USER/sample-controller
- Deploy the sample controller in the default namespace:
envsubst < config/template/ksvc-example.yaml | kubectl apply -f -
kubectl apply -Rf config/default
Two pods are created: one watching for events (apiserver-example-foo-XXX
) and another one containing the reconciling loop (example-foo-reconcile-XXX-deployment-YYY-ZZZ
). The first pod always stays alive, whereas the second one scale down to zero when there is no events.
- In one terminal, watch for pods.
watch kubectl get pods
- In another terminal, create a
Foo
object:
kubectl apply -f sample
Observe the pod named example-foo-reconcile-XXX
being created.
- Check the controller for
Foo
is working:
kubectl get deployments example-foo
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
example-foo 1 1 1 1 4m48s
Observe the pod named example-foo-reconcile-XXX
being deleted after about 1mn30s (default Knative scale down period).
- Delete the sample
kubectl delete -f sample/
- Delete the controller:
kubectl delete -Rf config