How-tos

Install Knative and Deploy an App on IBM Cloud

Share this post:

Install Knative with Istio on IBM Cloud Kubernetes Service

In this post, I’m going to show you how easy it is to install Knative with Istio on IBM Cloud Kubernetes Service, build and push an image to IBM Cloud Container Registry, and deploy an app.

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

Knative

Knative 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. These best practices include the following:

  • 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. To learn more about the basics of Knative, please see our lightboarding video, “What is Knative?

What are the Knative components?

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

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


Install Knative with Istio on IBM Cloud Kubernetes Service

Prerequisites

Set up 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 set up Istio

In this section, you will provision a Kubernetes cluster on the IBM Cloud Kubernetes Service and install Istio and Knative components.

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
  • Follow the instructions for installing Knative components on an IBM Cloud Kubernetes Service cluster
  • To check Knative installation, run the following command (this requires kubectl client version 1.11 or above):
kubectl api-resources | grep knative

Build and deploy the app

This section uses a nodejs app. For code samples in other programming languages (Go, Python, C#, Java, etc.,), please refer to Knative serving sample applications.

  • Clone the repo and cd into the folder:
git clone https://github.com/IBM-Cloud/knative-node-deploy
cd knative-node-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 region, and to set up a new namespace, please refer to this link.

  • In service.yaml, replace image value and run the below command:
    apiVersion: serving.knative.dev/v1alpha1 # Current version of Knative
    kind: Service
    metadata:
      name: knative-node-app # The name of the app
      namespace: default # The namespace the app will use
    spec:
      runLatest:
        configuration:
          revisionTemplate:
            spec:
              container:
                image: registry.{REGION}.bluemix.net/{NAMESPACE}/knative-node-app # The URL to the image of the app on IBMCLOUD Registry
                env:
                - name: TARGET # The environment variable printed out by the sample app
                  value: "Knative Node App running on IBM Cloud"
    
    
    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 some time 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

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? Please don’t hesitate to reach out to me on Twitter: VidyasagarMSC

Further learning

Technical Offering Manager & Polyglot Programmer | IBM Cloud

More How-tos stories
May 3, 2019

Kubernetes Tutorials: 5 Ways to Get You Building Fast

Ready to start working with Kubernetes? Want to build your Kubernetes skills? The five tutorials in this post will teach you everything you need to know about how to manage your containerized apps with Kubernetes.

Continue reading

May 3, 2019

Using Portworx to Deploy and Manage an HA MySQL Cluster on IBM Cloud Kubernetes Service

This tutorial is a walkthrough of the steps involved in deploying and managing a highly available MySQL cluster on IBM Cloud Kubernetes Service.

Continue reading

May 2, 2019

Kubernetes v1.14.1 Now Available in IBM Cloud Kubernetes Service

We are excited to announce the availability of Kubernetes v1.14.1 for your clusters that are running in IBM Cloud Kubernetes Service. IBM Cloud Kubernetes Service continues to be the first public managed Kubernetes service to support the latest upstream versions from the community.

Continue reading