Serverless on Kubernetes: Setting Up Knative Serving

Introduction

In modern cloud-native environments, developers seek the best of both worlds: the flexibility of Kubernetes and the simplicity of serverless computing. Knative Serving brings serverless capabilities to Kubernetes, enabling auto-scaling, scale-to-zero, and request-driven execution.

Why Knative?

  • Auto-scaling – Scale pods based on incoming traffic.
  • Scale-to-zero – When no traffic exists, Knative frees up resources.
  • Traffic Splitting – Deploy multiple versions and roll out updates safely.
  • Event-driven – Respond dynamically to requests without managing infra manually.

In this guide, we’ll install Knative Serving on Kubernetes and deploy a simple serverless application.

Prerequisites

Ensure you have:
 ✅ A running Kubernetes cluster (Minikube, K3s, or any managed Kubernetes).
 ✅ kubectl installed and configured.
 ✅ A valid domain name (or use a local DNS setup like sslip.io).

Step 1: Installing Knative Serving

Install the Required CRDs

Knative requires custom resources for managing serving components. Apply them to your cluster.

kubectl apply -f https://github.com/knative/serving/releases/latest/download/serving-crds.yaml

Install the Knative Core Components

kubectl apply -f https://github.com/knative/serving/releases/latest/download/serving-core.yaml

Install a Networking Layer

Knative requires an ingress to route traffic. We’ll use Kourier (a lightweight option).

kubectl apply -f https://github.com/knative/net-kourier/releases/latest/download/kourier.yaml
kubectl patch configmap/config-network --namespace knative-serving --type merge --patch '{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}'

Verify Installation

kubectl get pods -n knative-serving

All Knative components should be in Running state.

Step 2: Deploying a Serverless Application

We’ll deploy a simple Hello World application using Knative Serving.

Create a Knative Service

Define a KnativeService resource for our application.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-world
  namespace: default
spec:
  template:
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-go
          env:
            - name: TARGET
              value: "Knative on Kubernetes"
Click Here to Copy YAML

Apply the manifest:

kubectl apply -f hello-world.yaml

Step 3: Testing the Serverless Application

Get the External URL

Run the following command to get the app URL:

kubectl get ksvc hello-world

You should see an output like:

NAME          URL                                      LATESTCREATED   LATESTREADY
hello-world   http://hello-world.default.example.com   hello-world-00001   hello-world-00001

To test it:

curl http://hello-world.default.example.com

You should see “Hello Knative on Kubernetes!”

Step 4: Auto-Scaling & Scale-to-Zero in Action

Knative automatically scales up when there’s traffic and scales down to zero when idle.

Send multiple requests to trigger scaling:

hey -n 100 -c 10 http://hello-world.default.example.com

Watch the pods scaling:

kubectl get pods -w

Wait a few minutes and check again:

kubectl get pods

If no traffic exists, the app scales to zero, freeing up cluster resources!

Conclusion

With Knative Serving, we have transformed Kubernetes into a serverless powerhouse!

  • Deployed request-driven applications
  • Enabled automatic scaling and scale-to-zero
  • Simplified service deployment with KnativeService

Knative gives us the best of Kubernetes and serverless—scalability, flexibility, and resource efficiency. Now, you can deploy event-driven applications without worrying about infrastructure overhead.

Follow for more Kubernetes and cloud-native insights! Drop your thoughts in the comments!👇

Leave a comment