Configure HA for Knative deployment resources with Knative Operator

This brief tutorial explains how to configure the high availability (HA) for the deployment resources in Knative Serving with Knative Operator.

As of the 0.14 release for Knative Operator, developers have a new configuration field called spec.high-availability.replicas in the custom resource to specify the minimum number of replicas. If you install Knative Serving with Knative Operator, you will get seven deployment resources: activator, autoscaler, autoscaler-hpa, controller, istio-webhook, networking-istio, and webhook. Knative Operator 0.14 can configure the deployment resources associated with HorizontalPodAutoscaler or without leader election. If a deployment is running in leader-elected mode, the workload will go to the leader of all the replicas. It does not matter how many replicas are up and running. The following deployment resources are not running in leader-elected mode:

  • controller
  • autoscaler-hpa
  • networking-istio

The activator deployment resource is associated with HorizontalPodAutoscaler.

Knative Operator does not specify the number of replicas for each deployment individually. We are only able to specify the minimum number of replicas for all eligible deployments — controller, autoscaler-hpa, networking-istio and activator — at one time with the same value.

Why the HA option is important to Knative configuration

Knative Operator only launches one replica for all the deployment resources by default. The number of replicas can scale up based on the workload, but the process of scaling up will end up with a longer response time to requests. It is convenient to set the minimum replicas of the deployment resources to a reasonable number for better handling of the requests in a timely fashion.

Prerequisites

You need to install Kubectl for managing development environments. In addition, you need to set up a Kubernetes cluster as your environment to run and test the CustomResourceDefinition. You may choose to use a Kubernetes service from any major cloud provider, such as the IBM Cloud Kubernetes Service, and set up your connection based on the guidance provided. If you choose to use a local Kubernetes cluster on your own machine, based on your operating system, you can select Minikube or Docker Desktop.

Estimated time

Based on your familiarity with Knative, it may take 5-10 minutes to successfully install Knative with Knative Operator and configure Knative Serving with HA.

Steps

The Knative release combines operator and separate operators: serving operator and eventing operator. We will use the combined operator.

1. Install Knative Operator

Run the following command to install the 0.14 release of Knative Operator:

kubectl apply -f https://github.com/knative-sandbox/operator/releases/download/v0.14.1/operator.yaml

2. Verify the installation of Knative Operator

Run the following command to verify the installation of Knative Serving Operator:

kubectl get deployment knative-serving-operator

The deployment should show a Ready status, such as this output:

NAME                               READY   UP-TO-DATE   AVAILABLE   AGE
knative-serving-operator   1/1                1                         1           19h

Run the following command to verify the installation of Knative Eventing Operator:

kubectl get deployment knative-eventing-operator

The deployment should show a Ready status, such as this:

NAME                                 READY   UP-TO-DATE   AVAILABLE   AGE
knative-eventing-operator   1/1                1                         1           19h

3. Install Knative Serving with HA

To specify three minimum replicas for the eligible deployment resources — activator, autoscaler-hpa, controller, networking-istio — set the value 3 to the field spec.high-availability.replicas in the serving custom resource. To use knative-serving as the namespace to install Knative Serving, 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
spec:
  high-availability:
    replicas: 3
EOF

4. Verify the number of replicas

Run the following command to check all the deployments of Knative Serving:

kubectl get deployment -n knative-serving

You will see that three replicas have been launched for the deployment resources: activator, autoscaler-hpa, controller, and networking-istio:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
activator               3/3     3            3           39m
autoscaler            1/1     1            1           39m
autoscaler-hpa     3/3     3            3           39m
controller              3/3     3            3           39m
istio-webhook       1/1     1            1           39m
networking-istio    3/3     3            3           39m
webhook               1/1     1            1           39m

This is a new feature introduced into Knative Operator 0.14. If you experience any errors with HA configuration, report your issues on GitHub.

Summary

A new field called spec.high-availability.replicas in the Serving Operator custom resource enables you to specify the minimum number of replicas for deployment resources. This is a convenient configuration option for leveraging the custom resource to configure Knative. Without changing the released YAML files, Knative Operator provides the ability to configure HA for your Knative software via custom resource.