How to properly install Knative on GKE


The default Knative Installation instructions for Google Kubernete Engine (GKE) is problematic (see bug 2266). In this post, I want to outline what the problem is, tell you what I do, and also provide you the scripts that work for me until a proper solution is implemented either in gcloud or Knative.

The problem

The default Knative Installation instructions tell you to create a GKE cluster as follows:

gcloud beta container clusters create $CLUSTER_NAME \
 --addons=HorizontalPodAutoscaling,HttpLoadBalancing,Istio \
 --machine-type=n1-standard-4 \
 --cluster-version=latest --zone=$CLUSTER_ZONE \
 --enable-stackdriver-kubernetes --enable-ip-alias \
 --enable-autoscaling --min-nodes=1 --max-nodes=10 \
 --enable-autorepair \
 --scopes cloud-platform

Notice the Istio add-on. This command creates a Kubernetes cluster with Istio already installed. This is good because Istio is a dependency of Knative but keep reading.

Afterwards, you continue with installing Knative Serving and Knative Eventing. At this point, Knative Serving will work fine. However, you’ll have issues with Knative Eventing.

As I explained in my previous post, you won’t be able to use Knative Services as event sinks in Knative Eventing. For example, you won’t be able to have a Knative Service receiving Google Cloud Pub/Sub messages through Knative Eventing (a pure Kubernetes Service works).

Why? Because you need a cluster local gateway installed to get events routed to Knative Services. Knative docs have a page explaining how to install this. However, it is outdated and relies on Helm. Maybe it’s just me but I couldn’t get it working using those instructions.

Initial non-solution

In my previous post, I provided an initial solution that kind of worked but it doesn’t work anymore. To recap, I talked about a third_party folder in Knative Serving. In this folder, there are a couple versions of Istio folders (1.3.6 and 1.4.2 as of today). In these folders, there’s an istio-knative-extras.yaml file that you could apply to get the cluster local gateway installed.

However, this doesn’t work anymore because the Istio add-on version in GKE lags considerably behind 1.3.6. Knative seems to update Istio versions faster than GKE add-on can update.

My solution

My solution is basically not to rely on GKE Istio add-on anymore. Instead, I rely on the Istio versions in third_party folder of Knative and install the Istio version I want using the yaml files in there. The same folder also have yaml files for installing cluster local gateway.

Create a GKE cluster without Istio add-on

gcloud beta container clusters create $CLUSTER\_NAME \
--addons HorizontalPodAutoscaling,HttpLoadBalancing \
--zone $CLUSTER\_ZONE \
--cluster-version $CLUSTER\_MASTER\_VERSION \
--machine-type $CLUSTER\_NODE\_MACHINE\_TYPE \
--num-nodes $CLUSTER\_START\_NODE\_SIZE \
--min-nodes 1 \
--max-nodes $CLUSTER\_MAX\_NODE\_SIZE \
--enable-ip-alias \
--enable-stackdriver-kubernetes \
--enable-autoscaling \
--enable-autorepair \
--scopes cloud-platform

Install Istio manually using yaml files from Knative Serving

ISTIO\_VERSION=1.4.2

kubectl apply -f https://raw.githubusercontent.com/knative/serving/master/third\_party/istio-${ISTIO\_VERSION}/istio-crds.yaml

kubectl apply -f https://raw.githubusercontent.com/knative/serving/master/third\_party/istio-${ISTIO\_VERSION}/istio-minimal.yaml

Install cluster local gateway

kubectl apply -f https://raw.githubusercontent.com/knative/serving/master/third\_party/istio-${ISTIO\_VERSION}/istio-knative-extras.yaml

Scripts

Since I do this often enough, I updated my Knative Tutorial with a setup folder where I have scripts to setup Knative on GKE properly. Feel free to use them and send me pull requests if you have any ideas on how to make them better.

Bug

I also opened a bug (2266) on this in Knative. Please upvote!


See also