|
| 1 | +# Knative the easy way (on Google Kubernetes Engine) |
| 2 | + |
| 3 | +This guide walks you through the installation of the latest version of |
| 4 | +[Knative serving](https://github.com/knative/serving) using pre-built images on |
| 5 | +a Google Kubernetes Engine cluster. |
| 6 | + |
| 7 | +You can find [guides for other platforms here](README.md). |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +### Install gcloud SDK |
| 12 | + |
| 13 | +> If you already have `gcloud` installed, you can skip this section. |
| 14 | +
|
| 15 | +1. [Install the Google Cloud SDK](https://cloud.google.com/sdk/). |
| 16 | +1. Authorize `gcloud` to use your Google account: |
| 17 | + |
| 18 | +```shell |
| 19 | +gcloud auth login |
| 20 | +``` |
| 21 | + |
| 22 | +### Define environment variables |
| 23 | + |
| 24 | +To simply the command lines for this walkthrough, we need to define a few |
| 25 | +environment variables. |
| 26 | + |
| 27 | +If you already have a default project set in `gcloud`, enter: |
| 28 | + |
| 29 | +```shell |
| 30 | +export PROJECT_ID=$(gcloud config get-value project) |
| 31 | +``` |
| 32 | + |
| 33 | +Or, if you don't have an existing GCP project you'd like to use, |
| 34 | +replace `my-knative-project` with your desired project ID. This variable will |
| 35 | +be used later to create your new GCP project. The project ID must be globally |
| 36 | +unique across all GCP projects. |
| 37 | + |
| 38 | +```shell |
| 39 | +export PROJECT_ID=my-knative-project |
| 40 | +``` |
| 41 | + |
| 42 | +Set the following two variables as desired: |
| 43 | + |
| 44 | +```shell |
| 45 | +export CLUSTER_NAME=knative |
| 46 | +export CLUSTER_ZONE=us-west1-c |
| 47 | +``` |
| 48 | + |
| 49 | +### Register a Google Cloud Platform Project |
| 50 | + |
| 51 | +If you already have a GCP project configured, make sure your project is set |
| 52 | +as your `gcloud` default: |
| 53 | + |
| 54 | +```shell |
| 55 | +gcloud config set project $PROJECT_ID |
| 56 | +``` |
| 57 | + |
| 58 | +If you don't already have a GCP project configured, create a new project: |
| 59 | + |
| 60 | +```shell |
| 61 | +gcloud projects create $PROJECT_ID --set-as-default |
| 62 | +``` |
| 63 | + |
| 64 | +Enable the necessary APIs in this project: |
| 65 | + |
| 66 | +```shell |
| 67 | +gcloud services enable \ |
| 68 | + cloudapis.googleapis.com \ |
| 69 | + container.googleapis.com \ |
| 70 | + containerregistry.googleapis.com |
| 71 | +``` |
| 72 | + |
| 73 | +## Step 1: Create a Kubernetes Cluster |
| 74 | + |
| 75 | +Create a Kubernetes cluster on GKE (large enough to host all the Knative |
| 76 | +components). The recommended configuration for a cluster is: |
| 77 | + |
| 78 | +* Kubernetes version 1.10 or later |
| 79 | +* 4 vCPU nodes (`n1-standard-4`) |
| 80 | +* Node autoscaling, up to 10 nodes |
| 81 | +* API scopes for `cloud-platform`, `logging-write`, `monitoring-write`, and |
| 82 | + `pubsub` (if those features will be used) |
| 83 | + |
| 84 | +To create a cluster matching these requriements: |
| 85 | + |
| 86 | +```shell |
| 87 | +gcloud container clusters create $CLUSTER_NAME \ |
| 88 | + --zone=$CLUSTER_ZONE \ |
| 89 | + --cluster-version latest \ |
| 90 | + --machine-type n1-standard-4 \ |
| 91 | + --enable-autoscaling --min-nodes=1 --max-nodes=10 \ |
| 92 | + --scopes=cloud-platform,logging-write,monitoring-write,pubsub \ |
| 93 | + --num-nodes 3 |
| 94 | +``` |
| 95 | + |
| 96 | +After the cluster is created, grant `cluster-admin` permissions to the current |
| 97 | +user. These permissions are required to create the necessary |
| 98 | +[RBAC rules for Istio](https://istio.io/docs/concepts/security/rbac/). |
| 99 | + |
| 100 | +```shell |
| 101 | +kubectl create clusterrolebinding cluster-admin-binding \ |
| 102 | + --clusterrole=cluster-admin \ |
| 103 | + --user=$(gcloud config get-value core/account) |
| 104 | +``` |
| 105 | + |
| 106 | +## Step 2: Install Istio |
| 107 | + |
| 108 | +Knative depends on Istio, which must be installed first: |
| 109 | + |
| 110 | +```shell |
| 111 | +# Install from pre-compiled images |
| 112 | +kubectl apply -f https://storage.googleapis.com/knative-releases/latest/istio.yaml |
| 113 | + |
| 114 | +# Label the default namespace with istio-injection=enabled. |
| 115 | +kubectl label namespace default istio-injection=enabled |
| 116 | +``` |
| 117 | + |
| 118 | +Monitor the Istio components, until all of the components report `Running` or |
| 119 | +`Completed`: |
| 120 | + |
| 121 | +```shell |
| 122 | +kubectl get pods -n istio-system --watch |
| 123 | +``` |
| 124 | + |
| 125 | +CTRL+C when it's done. |
| 126 | + |
| 127 | +## Step 3: Install Knative Serving |
| 128 | + |
| 129 | +Next, we will install [Knative Serving](https://github.com/knative/serving) and |
| 130 | +its dependencies: |
| 131 | + |
| 132 | +```shell |
| 133 | +kubectl apply -f https://storage.googleapis.com/knative-releases/latest/release.yaml |
| 134 | +``` |
| 135 | + |
| 136 | +Monitor the Knative components, until all of the components report `Running`: |
| 137 | + |
| 138 | +```shell |
| 139 | +kubectl get pods -n knative-serving --watch |
| 140 | +``` |
| 141 | + |
| 142 | +CTRL+C when it's done. |
| 143 | + |
| 144 | +You are now ready to deploy apps Now you can deploy your app or function to your |
| 145 | +newly created Knative cluster. |
| 146 | + |
| 147 | +## Step 4: Run Hello World |
| 148 | + |
| 149 | +Now that your cluster is running the Knative components, follow the insturctions |
| 150 | +for one of the [sample apps](../serving/samples/README.MD) to deploy your first |
| 151 | +app. |
| 152 | + |
| 153 | +## Cleanup (optional) |
| 154 | + |
| 155 | +Running a cluster in Kubernetes Engine will cost you money, so if you aren't |
| 156 | +using it you may wish to delete the cluster when you're done. Deleting the |
| 157 | +cluster will also remove Knative, Istio, and any apps you've deployed. |
| 158 | + |
| 159 | +```shell |
| 160 | +gcloud container clusters delete $CLUSTER_NAME --zone $CLUSTER_ZONE |
| 161 | +``` |
0 commit comments