Install Knative with Istio on IBM Cloud: the hard way
Tags: cloud, kubernetes, istio, knative
Published: 2019-03-14 13:57:47

---
title: Install Knative with Istio on IBM Cloud: the hard way
published: true
tags: cloud,kubernetes,istio,knative
canonical_url: https://medium.com/vmacwrites/install-knative-with-istio-on-iks-cluster-and-deploy-an-app-on-ibm-cloud-7b7d368b9833
---

In this tutorial, learn how easy it is to install Knative with Istio on IBM Cloud Kubernetes Service(IKS), build and push an image to IBM Cloud Container Registry and deploy a nodejs app.

Before jumping into the instructions, let’s quickly understand what Knative is and what are its key components.

Knative extends Kubernetes to provide the missing building blocks that developers need to create modern, source-centric, container-based, cloud-native applications.

![](https://cdn-images-1.medium.com/max/280/1*pzF__5c3GXD8phF0pCBcfQ.png)

Each of the components under the Knative project attempt to identify common patterns and codify the best practices shared by successful real-world Kubernetes-based frameworks and applications, such as:

- orchestrating source-to-container workflows
- routing and managing traffic during deployment
- scaling and sizing resources based on demand
- binding running services to eventing ecosystems

Knative focuses on the “boring but difficult” parts that everyone needs, but no one benefits from doing over again on their own. This, in turn, frees developers to spend more time writing application code, not worrying about how they are going to build, deploy, monitor, and debug it.

### What are the Knative components?

Currently, Knative consists of the following top-level repositories:

- [build](https://github.com/knative/build) and [build-templates](https://github.com/knative/build-templates) — automatic, repeatable server-side container builds
- [serving](https://github.com/knative/serving) — scale to zero, request-driven compute
- [eventing](https://github.com/knative/eventing) — management and delivery of events

We expect this list to grow as more areas are identified.

### Prerequisites

- [Node and npm](https://www.npmjs.com/get-npm)
- [Download and install the ibmcloud command line tool](https://console.bluemix.net/docs/cli/index.html#overview)

### Setup CLI

> _If you already have ibmcloud CLI installed with the ibmcloud plugins, you can skip these steps._

- Install the cs (container-service) and cr (container-registry) plugins

```
$ ibmcloud plugin install container-service -r Bluemix

$ ibmcloud plugin install container-registry -r Bluemix
```

- Authorize ibmcloud:

```
$ ibmcloud login
```

### Create a Kubernetes cluster and setup Istio

In this section, you will provision a Kubernetes cluster on IBM Cloud Kubernetes service(IKS) and install Istio + Knative components.

- [Setup environment variables](https://github.com/knative/docs/blob/master/install/Knative-with-IKS.md#setting-environment-variables)
- Follow the steps to [Create a Kubernetes Cluster](https://github.com/knative/docs/blob/master/install/Knative-with-IKS.md#creating-a-kubernetes-cluster) (always choose the **stable**  version)
- As Knative depends on Istio, let’s install the latest version of Istio

```
$ kubectl apply --filename https://raw.githubusercontent.com/knative/serving/master/third_party/istio-1.0.2/istio.yaml
```

![](https://cdn-images-1.medium.com/max/1024/1*ogetR49JlqDlMJeA9Sj87Q.png)<figcaption>Install Istio</figcaption>

- Label the default namespace with istio-injection=enabled: kubectl label namespace default istio-injection=enabled
- Monitor the Istio components until all of the components show a STATUS of Running or Completed: kubectl get pods --namespace istio-system
- Follow the instructions for [Installing Knative components](https://github.com/knative/docs/blob/master/install/Knative-with-IKS.md#installing-knative-components) on IKS cluster
- To check Knative installation, run the below command

```
kubectl api-resources | grep knative
```

> Requires kubectl client version 1.11 or above

![](https://cdn-images-1.medium.com/max/1024/1*vSO4ZX1LYIs-UlDatTPfYg.png)<figcaption>To verify Knative installation</figcaption>

### Build and Deploy the app

This section uses a rehash of [helloworld-nodejs](https://github.com/knative/docs/tree/master/serving/samples/helloworld-nodejs) app. For code samples in other programming languages(Go, Python, C#, Java etc.,), refer [Knative serving sample applications](https://github.com/knative/docs/tree/master/serving/samples)

- Clone the [repo](https://github.com/VidyasagarMSC/knative-deploy) and cd into the folder

```
$ git clone https://github.com/VidyasagarMSC/knative-deploy.git

$ cd knative-deploy
```

- Install dependencies

```
$ npm install
```

- Build and Push the Docker image to IBM Cloud Container Registry by replacing <region> and <namespace> values

```
$ ibmcloud cr build -t registry.<region>.bluemix.net/<namespace>/knative-node-app .
```

> **Note:** To check your region, run ibmcloud cr regionand to setup a new namespace, refer [this link](https://console.bluemix.net/docs/services/Registry/index.html#registry_namespace_add)

- In service.yaml, replace image value and run the below command

{% gist https://gist.github.com/VidyasagarMSC/b6e8ae82e014047bbe3dbc296f317e38 %}

```
$ kubectl apply --filename service.yaml
```

- To find the IP address for your service, use kubectl get svc knative-ingressgateway -n istio-system to get the ingress IP for your cluster. If your cluster is new, it may take sometime for the service to get assigned an external IP address.

```
$ export IP_ADDRESS=$(kubectl get svc knative-ingressgateway --namespace istio-system --output 'jsonpath={.status.loadBalancer.ingress[0].ip}')
```

- To find the URL for your service, use kubectl get services.serving.knative.dev knative-node-app --output jsonpath='{.status.domain}'

```
$ export HOST_URL=$(kubectl get services.serving.knative.dev knative-node-app --output jsonpath='{.status.domain}')
```

- Now you can make a request to your app to see the result.

```
$ curl -H "Host: ${HOST_URL}" http://${IP_ADDRESS}

**Response:** Knative Node App running on IBM Cloud
```

> To Build a source into a container image from a Dockerfile inside a kubernetes cluster and push the image to IBM Cloud Container registry; all of this using Google’s Kaniko tool, follow the steps [in the post](https://medium.com/@VidyasagarMSC/build-a-container-image-inside-a-k8s-cluster-and-push-it-to-ibm-cloud-container-registry-abac9b1e5246)

### Cleanup

- Run the below command to remove the sample app from your cluster

```
$ kubectl delete --filename service.yaml
```

- To delete the cluster (removes everything), enter the following command:

```
$ ibmcloud cs cluster-rm $CLUSTER_NAME
```

**_Questions or concerns? Reach out on Twitter — _** [**_VidyasagarMSC_**](https://twitter.com/VidyasagarMSC)

### Further reading

- **Using Kaniko**  — [Build a container image inside a K8s cluster and push it to IBM Cloud Container Registry](https://medium.com/@VidyasagarMSC/build-a-container-image-inside-a-k8s-cluster-and-push-it-to-ibm-cloud-container-registry-abac9b1e5246)
- **Knative** [Logging with LogDNA](https://medium.com/vmacwrites/knative-log-analysis-with-logdna-on-ibm-cloud-568c4f5edfa0)
- **Knative** [Monitoring with Sysdig](https://medium.com/vmacwrites/knative-monitoring-with-sysdig-on-ibm-cloud-dc206c3f413d)
- **Knative** [Monitoring](https://medium.com/@VidyasagarMSC/knative-monitoring-with-grafana-zipkin-weavescope-other-plugins-30a2d8d20344)
- [IBM, Google Give Birth to Knative Serverless Cloud Project](http://www.eweek.com/development/ibm-google-give-birth-to-knative-serverless-cloud-project)
- [Knative Docs](https://github.com/knative/docs)

* * *