DEV Community

Alex Spinov
Alex Spinov

Posted on

Knative Has a Free API — Serverless Workloads on Kubernetes

Knative: Serverless Without Cloud Lock-in

Knative brings serverless capabilities to any Kubernetes cluster. Scale to zero, auto-scale on demand, event-driven workloads — all without AWS Lambda or Google Cloud Functions lock-in.

Two Components

  • Knative Serving — request-driven auto-scaling, scale-to-zero
  • Knative Eventing — event-driven architecture, CloudEvents

The Free API (CRDs)

Serving

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: my-api
spec:
  template:
    spec:
      containers:
      - image: my-api:v1
        ports:
        - containerPort: 8080
        resources:
          limits:
            memory: 256Mi
    metadata:
      annotations:
        autoscaling.knative.dev/minScale: "0"
        autoscaling.knative.dev/maxScale: "100"
        autoscaling.knative.dev/target: "50"
Enter fullscreen mode Exit fullscreen mode
# Deploy
kn service create my-api --image my-api:v1 --port 8080

# Update with traffic split
kn service update my-api --image my-api:v2 --traffic @latest=10 --traffic my-api-v1=90

# List revisions
kn revision list

# Get URL
kn service describe my-api -o url
Enter fullscreen mode Exit fullscreen mode

Eventing

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: pod-events
spec:
  serviceAccountName: events-sa
  mode: Resource
  resources:
  - apiVersion: v1
    kind: Pod
  sink:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: event-handler
Enter fullscreen mode Exit fullscreen mode

Real-World Use Case

A data processing company ran ML inference on Kubernetes. During off-hours, GPUs sat idle costing $2,000/month. Knative scale-to-zero cut costs to $400/month — pods spin up in seconds when requests arrive.

Quick Start

kubectl apply -f https://github.com/knative/serving/releases/latest/download/serving-crds.yaml
kubectl apply -f https://github.com/knative/serving/releases/latest/download/serving-core.yaml
Enter fullscreen mode Exit fullscreen mode

Resources


Need automated data pipelines? Check out my tools on Apify or email spinov001@gmail.com for custom serverless solutions.

Top comments (0)