Learn Knative - 10 Code Examples & CST Typing Practice Test
Knative is a Kubernetes-based platform that extends Kubernetes to build, deploy, and manage modern serverless workloads. It simplifies running containerized applications with automatic scaling, eventing, and routing capabilities.
View all 10 Knative code examples →
Learn KNATIVE with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple Knative Service
# knative/demo/service.yaml
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"
A simple Knative service deploying a containerized HTTP application.
Knative Service with Concurrency Limit
# knative/demo/concurrency.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: concurrency-demo
namespace: default
spec:
template:
spec:
containerConcurrency: 1
containers:
- image: gcr.io/knative-samples/helloworld-go
A Knative service with max concurrency configured.
Knative Service with Resource Limits
# knative/demo/resources.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: resource-demo
namespace: default
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
resources:
limits:
memory: "128Mi"
cpu: "500m"
Set CPU and memory limits on a Knative container.
Knative Service with Environment Variables
# knative/demo/env.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: env-demo
namespace: default
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
env:
- name: GREETING
value: "Hello Knative"
Set environment variables for a Knative service container.
Knative Service with Multiple Containers
# knative/demo/multi-container.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: multi-demo
namespace: default
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
- image: gcr.io/knative-samples/sidecar
Demonstrates a Knative service with multiple containers in a pod.
Knative Service with Custom Labels
# knative/demo/labels.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: label-demo
namespace: default
labels:
team: devops
env: staging
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
Add labels to a Knative service metadata.
Knative Service with Annotations
# knative/demo/annotations.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: annotation-demo
namespace: default
annotations:
autoscaling.knative.dev/minScale: "1"
autoscaling.knative.dev/maxScale: "3"
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
Use annotations to configure autoscaling behavior in Knative.
Knative Service with Revision Naming
# knative/demo/revision.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: revision-demo
namespace: default
spec:
template:
metadata:
name: rev1
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
Configure revision name template for a Knative service.
Knative Service with Probes
# knative/demo/probes.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: probe-demo
namespace: default
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
readinessProbe:
httpGet:
path: /health
port: 8080
Configure readiness and liveness probes for Knative containers.
Knative Service with Scale to Zero
# knative/demo/scale-to-zero.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: scale-zero-demo
namespace: default
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
autoscaling.knative.dev/minScale: "0"
Configure a Knative service that scales down to zero when idle.
Frequently Asked Questions about Knative
What is Knative?
Knative is a Kubernetes-based platform that extends Kubernetes to build, deploy, and manage modern serverless workloads. It simplifies running containerized applications with automatic scaling, eventing, and routing capabilities.
What are the primary use cases for Knative?
Serverless applications on Kubernetes. Event-driven microservices. Automatic scaling workloads. Routing and traffic management for services. Integrating with cloud-native CI/CD pipelines
What are the strengths of Knative?
Automatic scaling reduces resource usage. Supports event-driven serverless architecture. Seamless Kubernetes integration. Flexible routing and traffic management. Extensible and cloud-native friendly
What are the limitations of Knative?
Requires Kubernetes knowledge. Complex setup for beginners. Dependent on cluster resources and networking. Debugging can be more challenging than traditional apps. Limited built-in tooling compared to managed serverless platforms
How can I practice Knative typing speed?
CodeSpeedTest offers 10+ real Knative code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.