
Knative is an open-source project that offers a set of components to simplify the configuration of services on Kubernetes. It allows developers to deploy, run, and manage serverless cloud-native applications fast without managing the underlying infrastructure directly. This reduces the execution time for common routine tasks such as creating pods, load balancing, auto-scaling, routing traffic, among other cluster operations.
Knative Serving offers a set of components that allow you to deploy and manage serverless workloads on Kubernetes. You can deploy an application and enable automatic scaling based on the incoming user traffic load. Below are the key components of Knative Serving:
In this tutorial, deploy serverless workloads on a Vultr Kubernetes Engine (VKE) cluster with Knative Serving. You are to deploy an Express application as a serverless workload using Knative serving.
Before you begin:
5 nodesDownload the latest Knative CLI latest release for Linux systems
When using a different operating system, visit the Knative CLI release page to download the latest version
Move the downloaded binary file to the /usr/local/bin/ directory to enable it as a system-wide command
Make the kn binary file executable
Verify the Knative CLI version
Output:
To deploy and manage serverless applications in your Vultr Kubernetes Engine (VKE) cluster, install Knative Serving as described in the steps below.
1.11.0. Visit the Knative Serving Releases page to verify the latest version to install in your cluster.Install the Knative Custom Resource Definitions (CRDs) to define and control how your serverless workload behavior in the cluster
Install the Knative Serving core components
Install the Knative Kourier controller and enable its Knative integration
The above command installs the Kourier controller that works as a networking layer to expose Knative applications to an external network. Knative Serving also supports other networking layers such as Istio, and Contour.
Using Kubectl, edit the config-network ConfigMap and configure Knative Serving to use Kourier as the networking layer
Wait for at least 3 minutes to provision a load balancer, then, view the external address assigned to the Kourier Controller
Output:
Install the Knative Serving DNS configuration to use the default domain sslip.io
To replace the default sslip.io domain, point a domain record to your load balancer IP address to access the Knative Service services
Verify that the Knative Serving components are active and running
Output:
To implement Knative Serving in your cluster, deploy a serverless application and verify access using the default domain record. They're two methods you can apply to deploy a serverless application with Knative serving, using the Knative CLI or Kubernetes manifest files. In this section, deploy an Express application using any of the methods described below.
The Knative CLI interacts with Knative components installed in your cluster. The tool enables the fast deployment and management of applications in a cluster. Deploy an Express application using Knative CLI as described below.
Create a new knative-app namespace for your application
Using Knative CLI, deploy your Express application to the knative-app namespace. Replace karnadocker/express-app with your desired Docker image source
Your output should look like the one below:
List Knative services and verify that the application is successfully created
Output:
Describe the service to view information about the Express application
Output:
View the application URL
Output:
Using Curl, query the application URL and verify that it displays a result
Output:
To further test the application status, use a web browser and visit the application URL
To delete the application, run kn service with the delete option
You can deploy serverless applications to your cluster using YAML files. This method allows you to implement version control for your application workloads. Deploy an Express application to your cluster as described below.
Create a new knative-app namespace
Using a text editor such as Vim, create a new YAML resource file knative-service.yaml
Add the following configurations to the file. Replace karnadocker/express-app with your desired Docker image source
Save and close the file
Apply the resource to your cluster
Verify that the service is available in the knative-app namespace
Output:
View the application URL
Output:
Using Curl, visit the application URL
Output:
The above output verifies that the application is running correctly in your cluster
Knative can scale services automatically based on incoming traffic and the configured scaling policies. It uses the Knative Pod Autoscaler (KPA) to scale the number of pods automatically. When incoming traffic increases, KPA scales up by creating new pods based on the available configuration. When there is no incoming traffic, KPA scales down by deleting pods to save cluster resources.
The KPA offers many configuration options to control the autoscaling behavior as implemented in this section.
Knative Serving allows you to set scaling limits for your application to control the number of pods created for a revision to handle the requests. This allows you to manage the cluster resource utilization and prevent unexpected resource consumption. You can set scaling limits using scale-min and scale-max options as described below.
Set your express-service application minimum and maximum scaling limit
Output:
Verify the application scaling limit
Output:
As displayed in the above output, the max scale and min scale annotations match your scaling limits
Using concurrency limits, you can control the number of concurrent requests each pod can process. When the concurrency rate exceeds the defined limit, Knative scales up the application by creating additional pods to handle the load. If the concurrency drops below the given limit, the application scales down by deleting unused pods. In this section, set the concurrency limits as described below.
To set the express-service application concurrency limit to 10, update the service with the concurrency-limit value
Output:
To test auto scaling on your application, use a concurrent request tool such as Hey to send continuous requests to your application as described below.
Install the hey CLI tool.
View the list of running pods in the knative-app namespace
Output:
Send 300 seconds of traffic while maintaining 5000 concurrent requests to your application using the following command
Verify that the pods are scaling up
Your output should look like the one below:
Each time you create or update a service, Knative creates a new revision. Route incoming traffic to revisions as described in the steps below.
List all express-service application revisions
Output:
Verify the percentage of requests routed to specific revisions in the TRAFFIC column. In the above output, Knative has mapped all requests by 100% to only the express-service-00003 revision.
View detailed information about the express-service-00003 revision
Output:
To distribute traffic among all three service revisions, apply the --traffic option to update the service using the following command
Verify that the traffic is distributed among all revisions
Output:
Verify the traffic distribution values displayed in the TRAFFIC column
You have deployed a serverless application on a Vultr Kubernetes Engine (VKE) cluster. You implemented the different deployment methods and scaled the serverless application using concurrency and scaling limits. By using Knative Serving, you can streamline the process of building, deploying, and scaling serverless workloads in your cluster. For more information about Knative Service, visit the Knative Serving documentation.
0 Comments
Be the first to comment and share your perspective with the community.