Learn KNATIVE with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
1
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.
2
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.
3
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.
4
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.
5
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.
6
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.
7
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.
8
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.
9
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.
10
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.