Install Knative with Istio on IKS cluster and deploy an app on IBM Cloud
Install Knative with Istio on IKS cluster and deploy an app on IBM Cloud
This post provides you step-by-step instructions to install Knative with Istio on IBM Cloud Kubernetes Service(IKS), build and push your image to IBM Cloud Container Registry and deploy the app.
Before jumping into the instructions, let’s quickly understand what Knative is and what are its key components.
Knative (pronounced /ˈnā-tiv/) extends Kubernetes to provide the missing building blocks that developers need to create modern, source-centric, container-based, cloud-native applications.
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 and build-templates — automatic, repeatable server-side container builds
- serving — scale to zero, request-driven compute
- eventing — management and delivery of events
We expect this list to grow as more areas are identified.
Prerequisites
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.
kubectl apply --filename kubectl apply --filename https://raw.githubusercontent.com/knative/serving/master/third_party/istio-1.0.2/istio.yaml
- 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
Build and Deploy the app
This section uses a rehash of helloworld-nodejs app. For code samples in other programming languages(Go, Python, C#, Java etc.,), refer Knative serving sample applications
- Clone the repo and
cd
into the folder
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 .
- In
service.yaml
, replaceimage
value and run the below command
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}
Knative Node App running on IBM Cloud
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