1111App\Models\Blog Object ( [table:protected] => blogs [fillable:protected] => Array ( [0] => user_id [1] => date [2] => image [3] => title [4] => slug [5] => detail [6] => post_excerpt [7] => status [8] => tags [9] => related_blog_id [10] => category_id [11] => meta_detail [12] => meta_keyword ) [casts:protected] => Array ( [tags] => array ) [connection:protected] => mysql [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [preventsLazyLoading] => [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [escapeWhenCastingToString:protected] => [attributes:protected] => Array ( [id] => 67 [user_id] => 4 [category_id] => 9 [title] => Configure and Run Serverless Functions on Kubernetes [slug] => configure-and-run-serverless-functions-on-kubernetes [image] => 1712230575Configure and Run Serverless Functions on Kubernetes.webp [date] => 2022-03-28 [detail] =>
Serverless functions are standard code parts responsible for dealing with many different events. They offer a cost-efficient approach to implementing microservices. The technical team can use serverless functions to increase their focus on code and make them respond to certain events with a pay-as-you-go computing model. On the contrary, Kubernetes offers significant primitives to run the mission-critical application with the help of containers. This process provides autoscaling and automatic responses to application failovers, application deployment strategies, and APIs, enabling resource management and workload provisioning processes. Running Kubernetes and serverless functions in the same box with extensive infrastructure and its management may sound difficult but can be done with ease using open-source tools, like Knative and OpenFaaS. In this article, we are going to talk about Knative and how it can be used to run serverless functions on Kubernetes.
Here, Knative refers to a suite of Kubernetes components, providing serverless capabilities and an event-driven platform helping to run applications and services, which can further be scaled on-demand, powered with extensive monitoring, auto-renewal of SSL/TSL certificates, etc.
https://docs.docker.com/get-docker
- refer to this link for downloading and installing Docker for your OS.brew install kubectl
and to know its version type, use the command: kubectl version - -client
curl–LO https://dl.k8s.io/release/v1.21.0/bin/windows/amd64/kubectl.exe
kubectl version - -client
Note: Ensure to install Kubernetes version 1.20.x, 1.21.x, or its above versions.
brew install know
Here, we are going to use Docker Desktop to create the Kubernetes cluster.
In order to create a Kubernetes cluster, you can also use KIND – a tool that runs local Kubernetes clusters with the help of Docker container nodes. Use the following command to create Kind Cluster and configure the kubectl context:
curl -sL \
https://raw.githubusercontent.com/csantanapr\
/knative-kind/master/01-kind.sh | sh
It helps to manage service deployments, amendments, networking, and scaling of elements. The Knative Serving components share services by generating their URLs and providing safe default configurations. For KIND users:
curl –sL https://raw.githubusercontent.com/csantanapr/knative-kind/master/02-serving.sh | sh
Curl –sL https://raw.githubusercontent.com/csantanapr/knative-kind/master/02-kourier.sh | sh
For Docker Desktop Users:
curl -sL https://raw.githubusercontent.com/csantanapr/knative-docker-desktop/main/demo.sh | sh
To enable the development and deployment of the platform-specific function as a part of Knative services deployed on Kubernetes, use kn CLI extension func. It has many function templates and runtimes, which uses Cloud Native Buildpacks to create and post OCI-formatted function images. Install kn CLI on Kubernetes using Homebrew, use command:
brew tap knative-sandbox/kn-plugins && brew install func
A serverless function can be written in Java, JavaScript, Go, Rust, and Python, but here we’re going to write it in JavaScript.
kn func create sample-func --runtime node
This will create a new directory, specified as sample-func
along with the initialization of a Node.js function
project. Note: You may find out runtimes in Go, Python, Spring Boot, Rust, Quarkus, and TypeScript The Func.yaml
file encompasses its configuration details, which will be used at the time of building and deploying the function.
func.yaml
file and amend its envs
field with the following value:- name: TARGET
value: Web
Another file named index.js encompasses function logics specific to the project, which can be used to install other dependencies and is necessary for the project exporting a single default function. Now, let’s have a look at index.js file contents:
invoke (context)
function, in which context
is a parameter and an HTTP object storing HTTP request data.Open index.js file and update the handleGet
function with its necessary definition:
function handleGet(context) {
return {
target: process.env.TARGET,
query: context.query,
time: new Date().toJSON(),
};
}
kn func deploy
If you’re running it for the first time, it will ask to specify registry, then enter your registration details:
docker.io/<username>
Once it is mentioned, press Enter key to proceed.
Note: you can also run it locally using the command: kn func run
So, now your serverless function on Kubernetes is created, which would bring the benefits of a serverless entity into the Kubernetes environment. Have queries for us related to cloud computing services? If yes, send us your requirements at marketing@cloudstakes.com or book a cloud computing consultation slot with our cloud computing consultants!
[post_excerpt] => Running Kubernetes and serverless functions in the same box with extensive infrastructure and its management may sound difficult but can be done with ease using open-source tools. [tags] => ["109","498"] [related_blog_id] => 67 [status] => 1 [featured] => 0 [meta_detail] => Running Kubernetes and serverless functions in the same box with extensive infrastructure and its management may sound difficult but can be done with ease using open-source tools. [meta_keyword] => [created_at] => 2023-01-10 03:44:50 [updated_at] => 2024-04-04 17:06:15 ) [original:protected] => Array ( [id] => 67 [user_id] => 4 [category_id] => 9 [title] => Configure and Run Serverless Functions on Kubernetes [slug] => configure-and-run-serverless-functions-on-kubernetes [image] => 1712230575Configure and Run Serverless Functions on Kubernetes.webp [date] => 2022-03-28 [detail] =>Serverless functions are standard code parts responsible for dealing with many different events. They offer a cost-efficient approach to implementing microservices. The technical team can use serverless functions to increase their focus on code and make them respond to certain events with a pay-as-you-go computing model. On the contrary, Kubernetes offers significant primitives to run the mission-critical application with the help of containers. This process provides autoscaling and automatic responses to application failovers, application deployment strategies, and APIs, enabling resource management and workload provisioning processes. Running Kubernetes and serverless functions in the same box with extensive infrastructure and its management may sound difficult but can be done with ease using open-source tools, like Knative and OpenFaaS. In this article, we are going to talk about Knative and how it can be used to run serverless functions on Kubernetes.
Here, Knative refers to a suite of Kubernetes components, providing serverless capabilities and an event-driven platform helping to run applications and services, which can further be scaled on-demand, powered with extensive monitoring, auto-renewal of SSL/TSL certificates, etc.
https://docs.docker.com/get-docker
- refer to this link for downloading and installing Docker for your OS.brew install kubectl
and to know its version type, use the command: kubectl version - -client
curl–LO https://dl.k8s.io/release/v1.21.0/bin/windows/amd64/kubectl.exe
kubectl version - -client
Note: Ensure to install Kubernetes version 1.20.x, 1.21.x, or its above versions.
brew install know
Here, we are going to use Docker Desktop to create the Kubernetes cluster.
In order to create a Kubernetes cluster, you can also use KIND – a tool that runs local Kubernetes clusters with the help of Docker container nodes. Use the following command to create Kind Cluster and configure the kubectl context:
curl -sL \
https://raw.githubusercontent.com/csantanapr\
/knative-kind/master/01-kind.sh | sh
It helps to manage service deployments, amendments, networking, and scaling of elements. The Knative Serving components share services by generating their URLs and providing safe default configurations. For KIND users:
curl –sL https://raw.githubusercontent.com/csantanapr/knative-kind/master/02-serving.sh | sh
Curl –sL https://raw.githubusercontent.com/csantanapr/knative-kind/master/02-kourier.sh | sh
For Docker Desktop Users:
curl -sL https://raw.githubusercontent.com/csantanapr/knative-docker-desktop/main/demo.sh | sh
To enable the development and deployment of the platform-specific function as a part of Knative services deployed on Kubernetes, use kn CLI extension func. It has many function templates and runtimes, which uses Cloud Native Buildpacks to create and post OCI-formatted function images. Install kn CLI on Kubernetes using Homebrew, use command:
brew tap knative-sandbox/kn-plugins && brew install func
A serverless function can be written in Java, JavaScript, Go, Rust, and Python, but here we’re going to write it in JavaScript.
kn func create sample-func --runtime node
This will create a new directory, specified as sample-func
along with the initialization of a Node.js function
project. Note: You may find out runtimes in Go, Python, Spring Boot, Rust, Quarkus, and TypeScript The Func.yaml
file encompasses its configuration details, which will be used at the time of building and deploying the function.
func.yaml
file and amend its envs
field with the following value:- name: TARGET
value: Web
Another file named index.js encompasses function logics specific to the project, which can be used to install other dependencies and is necessary for the project exporting a single default function. Now, let’s have a look at index.js file contents:
invoke (context)
function, in which context
is a parameter and an HTTP object storing HTTP request data.Open index.js file and update the handleGet
function with its necessary definition:
function handleGet(context) {
return {
target: process.env.TARGET,
query: context.query,
time: new Date().toJSON(),
};
}
kn func deploy
If you’re running it for the first time, it will ask to specify registry, then enter your registration details:
docker.io/<username>
Once it is mentioned, press Enter key to proceed.
Note: you can also run it locally using the command: kn func run
So, now your serverless function on Kubernetes is created, which would bring the benefits of a serverless entity into the Kubernetes environment. Have queries for us related to cloud computing services? If yes, send us your requirements at marketing@cloudstakes.com or book a cloud computing consultation slot with our cloud computing consultants!
[post_excerpt] => Running Kubernetes and serverless functions in the same box with extensive infrastructure and its management may sound difficult but can be done with ease using open-source tools. [tags] => ["109","498"] [related_blog_id] => 67 [status] => 1 [featured] => 0 [meta_detail] => Running Kubernetes and serverless functions in the same box with extensive infrastructure and its management may sound difficult but can be done with ease using open-source tools. [meta_keyword] => [created_at] => 2023-01-10 03:44:50 [updated_at] => 2024-04-04 17:06:15 ) [changes:protected] => Array ( ) [classCastCache:protected] => Array ( ) [attributeCastCache:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) )