Knative journey EP5: install and uninstall Knative with Operators

Vincent Hou
7 min readFeb 27, 2020

As of v0.10.0, Knative started to release Knative operators as powerful software to install, configure and manage Knative. If you have read some of my previous episodes, e.g. EP1, you probably have tried Knative installation on your Kubernetes cluster. In this tutorial, I will explain Knative operators as an alternative way to install and uninstall Knative.

There are two major components in Knative: Serving and Eventing, and there are two operators: Knative Serving Operator and Knative Eventing Operator, respectively dedicated to each of them. Please make sure you have set up a Kubernetes cluster accessible to your local workstation.

Limitations of Knative Operators:

The Operators released by Knative community only focus on Knative for the generic Kubernetes service, which means Docker-Desktop Kubernetes on Mac and Minikube do not need any additional configuration out of the scope of the operator custom resource, but vendor-specific Kubernetes services, like Google Kubernetes Engine, IBM Kubernetes Service, OpenShift, etc, may need some additional configurations to work after the Knative is installed by the operator.

The same to any other Kubernetes operator, Knative operators take custom resources as the sources of truth to configure your Knative. The current custom resources still have limited capabilities, which can not cover all the scenarios of how we can configure Knative to meet our needs, but Knative operators are making progress in extending their capabilities. One of the major missing points is that operators still lack of APIs for us to specify the parameters for high availability. If you rely on the HA capability, Knative operators are currently not helping with that. We will explain what we can configure with the current operators.

The opens source versions of Knative operators have not been tested on any existing production environment. Please use them for development or test purpose. However, we encourage you to experiment Knative operators on top of your cluster for your production, helping us find out what we can potentially improve in Knative operators by reporting your issues.

Prerequisites:

Knative Serving needs an ingress or gateway to route inbound network traffic to the services. There are multiple options that can be used as the ingress candidates: Istio, Ambassador, Contour, Gloo, Kourier, etc. However, to install Knative with operators, we only support Istio as the ingress for now. Knative Operators are currently working on enabling the support for more ingress options. Since we talk about the installation on generic Kubernetes service, Istio can be installed with the following steps:

  1. Download and install Istio. Go through all the 4 sub-steps.
  2. Update your Istio to use cluster local gateway.

Install Knative Serving with Operator:

All the releases for Knative Serving Operator can be found on this page. The latest release is v0.12.2 by the time I wrote this tutorial.

From releases:

Replace <version> with the latest version or the version you would like to install, and run the following command to install Knative Serving Operator:

kubectl apply -f https://github.com/knative/serving-operator/releases/download/<version>/serving-operator.yaml

From source code:

The source code is available on this page. You need to install the building tool ko first. After downloading the source code, you can install the operator in the root directory of the source code with the following command:

ko apply -f config/

Verify the installation of Knative Serving Operator with the command:

kubectl get deployment knative-serving-operator

You should see the deployment is ready, if the operator is installed:

Use the following command to track the log of the operator:

kubectl logs -f $(kubectl get pods -l name=knative-serving-operator -o name)

If everything goes fine, it is time to install Knative Serving by installing the custom resource of Knative Serving operator. Operator supports to install Knative Serving under any namespace, which needs to be created as well. Then, we can create a custom resource with empty spec section. Technically, you can use any namespace, but we recommend you to use knative-serving. In the rest of this tutorial, we keep on using knative-servingas the namespace to create the Serving operator CR and all the other namspaced Serving resources. To create the CR, you can run the following command:

cat <<-EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: knative-serving
---
apiVersion: operator.knative.dev/v1alpha1
kind: KnativeServing
metadata:
name: knative-serving
namespace: knative-serving
EOF

Wait some time for Knative Serving is to become ready. Check the Knative Serving deployment with the following command:

kubectl get deployment -n knative-serving

You will receive the status of Knative serving deployments:

If Knative Serving has been successfully deployed, check the operator log again, and you will see similar content as below:

Install Knative Eventing with Operator:

All the releases for Knative Eventing Operator can be found on this page. The latest release is v0.12.1 by the time I wrote this tutorial.

From releases:

Replace <version> with the latest version or the version you would like to install, and run the following command to install Knative Eventing Operator:

kubectl apply -f https://github.com/knative/serving-operator/releases/download/<version>/eventing-operator.yaml

From source code:

The source code is available on this page. You need to install the building tool ko first. After downloading the source code, you can install the operator in the root directory of the source code with the following command:

ko apply -f config/

Verify the installation of Knative Eventing Operator with the command:

kubectl get deployment knative-eventing-operator

You should see the deployment is ready, if the operator is installed:

Use the following command to track the log of the operator:

kubectl logs -f $(kubectl get pods -l name=knative-eventing-operator -o name)

If everything goes fine, it is time to install Knative Evenintg by installing the custom resource of Knative Eventing operator. The same to Knative Serving operator, you can use any namespace, but we recommend you to use knative-eventingfor Knative eventing. In the rest of this tutorial, we keep on using knative-eventingas the namespace to create the Eventing operator CR and all the other namspaced Eventing resources. Run the following command:

cat <<-EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: knative-eventing
---
apiVersion: operator.knative.dev/v1alpha1
kind: KnativeEventing
metadata:
name: knative-eventing
namespace: knative-eventing
EOF

Wait some time for Knative Eventing t become ready. Check the Knative Eventing deployments with the following command:

kubectl get deployment -n knative-eventing

We should see a list of Knative Eventing deployments up and running:

If Knative Eventing has been successfully deployed, check the operator log again, and you will see similar content as below:

Uninstall Knative Serving with Operator:

All the resources of Knative Serving are owned by the Knative Serving operator custom resource. To uninstall your Knative Serving, you only need to remove the operator CR with the command:

kubectl delete KnativeServing knative-serving -n knative-serving

Knative Serving operator prevents unsafe removal of Knative serving resources. Even if the operator CR is successfully removed, all the CRDs in Knative Serving are still kept in the cluster. All your resources relying on Knative CRDs can still work.

To remove Knative Serving Operator:

If you install from releases, run the following command:

kubectl delete -f https://github.com/knative/serving-operator/releases/download/<version>/serving-operator.yaml

Replace <version> with the version number of Knative Serving, you have installed.

If you install from source code, run the following command in the root directory of your source code:

ko delete -f config/

Uninstall Knative Eventing with Operator:

All the resources of Knative Eventing are owned by the Knative Eventing operator custom resource. You can uninstall your Knative Eventing, by removing the operator CR with the command:

kubectl delete KnativeEventing knative-eventing -n knative-eventing

Knative Eventing operator also prevents unsafe removal of Knative Eventing resources by keeping the Knative Eventing CRDs.

To remove Knative Eventing Operator:

If you install from releases, run the following command:

kubectl delete -f https://github.com/knative/eventing-operator/releases/download/<version>/serving-operator.yaml

Replace <version> with the version number of Knative Eventing, you have installed.

If you install from source code, run the following command in the root directory of your source code:

ko delete -f config/

Congratulations on the accomplishment of Knative installation and uninstallation with operators! I will explain how to configure your Knative with custom resources in my next tutorial.

Follow Vincent, (and)you won’t derail!

--

--

Vincent Hou

A Chinese software engineer, used to study in Belgium and currently working in US, as Knative & Tekton Operator Lead and Istio Operator Contributor.