Personal Development Category (English)728x90

Kubeless tutorial – Kubernetes native serverless framework

Disclosure: This page uses affiliate links.When you click an affliate link,we get a small compensation at no cost to you.Thanks for your support!Learn more

kubeless is a Kubernetes-native serverless framework that lets you deploy small bits of code without having to worry about the underlying infrastructure plumbing. It leverages Kubernetes resources to provide auto-scaling, API routing, monitoring, troubleshooting, and more.

Kubeless Kubernetes-native serverless framework

Image – Kubeless – Kubernetes-native serverless framework

Before we move on to the tutorial, Little bit of intro on Serverless, it allows developers to build and run applications and services without thinking about the servers actually running the code. Serverless services, or FaaS (Functions-as-a-Service) providers, instrument this concept by allowing developers to upload the code while taking care of deploying running and scaling it. AWS Lambda was the first one in the market to offer this kind.

Popular cloud providers that support Function As A Service (FaaS) as follows:

Kubeless aims to be an open-source FaaS solution to clone the functionalities of AWS Lambda/Google Cloud Functions.

For more details on Serverless & comparison of the platforms, look up here.

Quick Snapshot

Subscribe to Emails

More than 100,000 subscribers across the world trust & read Upnxtblog articles. Subscribe to emails updates!
* indicates required

How it works

Serverless services or FaaS lets you run code without provisioning or managing servers (but still servers are needed). You pay only for the compute time you consume there is no charge when your code is not running. You can run code for virtually any type of application or backend service all with zero administration. Just upload your code and FaaS provider would take care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger other services or call it directly from any web or mobile app.

AWS Lambda / How it works

Image – AWS Lambda / How it works

Image- Another Sample

Devops Engineer Masters Program will make you proficient in DevOps principles like CI/CD, Continuous Monitoring and Continuous Delivery, using tools like Puppet, Nagios, Chef, Docker, Git & Jenkins. It includes training on Linux, Python, Docker, AWS DevOps Certification Training and Splunk. The curriculum has been determined by extensive research on 5000+ job descriptions across the globe.
New customer offer! Top courses from $13.99 when you first visit Udemy

With Kubeless you can deploy functions without the need to build containers. These functions can be called via regular HTTP(S) calls or triggered by events submitted to message brokers like Kafka.

Currently, Kubeless Functions have three possible types:

  1. HTTP triggered (function will expose an HTTP endpoint)
  2. Pubsub triggered (function will consume event on a specific topic; a running Kafka cluster on your k8s is required)
  3. Schedule triggered (function will be called on a cron schedule)

#1.Kubeless Installation

Recover over 700 unique file formats. Fully recover documents, emails, photos, videos, audio files and more. Supports 8 different data lost scenarios: deleted files recovery, recycle bin recovery, formatted drive recovery, lost partition recovery, externa

Step #1: Create a kubeless namespace where you will install the controller.

Create Kubeless namespace

Image – Create Kubeless namespace

Step #2: Install the latest stable version with a kubectl create command

curl -sL | kubectl create -f -
Install Kubeless

Image – Install Kubeless

You can see that few pods are being started in the kubeless namespace. The controller will watch for function objects to be created and also two Pods to enabled PubSub function (Kafka & Zoo pods).

Step #3: Check the status of the pods using get pods command

Check deployment status using get pods command

Image – check deployment status using get pods command

Once the controller is in ‘Running’ state, we can start deploying functions.

Career Category (English)640x480

#2.Deploy Function

To deploy a function, we are going to use the kubeless CLI. For the function that we are going to deploy, we have to specify a run time which language the function is in.

Also, we need to specify the file that contains the function, how the function will get triggered (here we are using an HTTP trigger), and finally specify the function name as a handler.

kubeless function deploy toy --runtime python2.7 --handler toy.handler --from-file --trigger-http
Deploy kubeless function

Image – Deploy kubeless function

Congrats! Now we have created a new function.

We can check the list of functions with the kubeless CLI:

Google IT Support Professional Certificate by Grow with Google (300x600) - 2
kubeless function ls

kubeless function ls command

Image – kubeless function ls command

Kubeless would have automatically created a Kubernetes deployment and service. You can check that a Pod containing your function is running:

kubectl get pods command

Image – kubectl get pods command

#3.Call Function via HTTP

To test the function, call the function using the kubeless CLI command:

Call kubeless function from CLI

Image – Call kubeless function from CLI

If the proxy is configured, we can call it using curl command

curl --data '{"hello":"world"}' localhost:8080/api/v1/proxy/namespaces/default/services/toy:8080/ --header "Content-Type:application/json"

Call function using curl command

Image – Call function using curl command

For viewing the logs of the function, use logs command

kubeless function logs toy

View Function logs

Image – View Function logs

To get the description of the function, use describe command like below

Start your future with a Data Analysis Certificate.
kubeless function describe toy

Describe command to get details of function

Image – Describe command to get details of function

To update a function use the kubeless function updatecommand. For example, to replace the toy function which we have created with the method from the script, do:

kubeless function update toy --from-file

As clean up activity, we can also remove the functions and the deployments we have created.

kubeless function delete toy

Delete command

Image – Delete command

The deployment and Kubernetes services will be removed automatically. You can use get deployments, services to check the same.

Online business courses to jumpstart your future.

Congrats! Today we have learned how to create, update, and call the function via HTTP.

Like this post? Don’t forget to share it!

Additional Resources :

Kubeless tutorial - Kubernetes native serverless framework
Article Name
Kubeless tutorial - Kubernetes native serverless framework
kubeless is a Kubernetes-native serverless framework that lets you deploy small bits of code without having to worry about the underlying infrastructure plumbing.
Publisher Name
Publisher Logo

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: