Understanding Knative: Serving, Configuration, Traffic Splitting, and Service Integration
This article introduces Knative as a Kubernetes‑based serverless platform, explains its three core components, walks through deploying a Hello World service with YAML and kubectl commands, shows how configuration changes create revisions, demonstrates traffic splitting, and illustrates integration with external services such as Twilio.
Knative is an open‑source set of building blocks that brings serverless containers to Kubernetes, bridging the gap between container orchestration and on‑demand code execution.
It consists of three main components: Knative Serving for rapid deployment and automatic scaling of serverless containers, Knative Eventing for loosely‑coupled, event‑driven services, and Knative Build for painless code‑to‑container workflows.
Deploying a Hello World service involves packaging the code into a container image, pushing it to a public registry, and creating a Service YAML file that tells Knative where to find the image and how to configure it. An example service-v1.yaml looks like:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: helloworld-csharp
namespace: default
spec:
runLatest:
configuration:
revisionTemplate:
spec:
container:
# replace {username} with your DockerHub
image: docker.io/{username}/helloworld-csharp:v1
env:
- name: TARGET
value: "C# Sample v1"Applying the service with kubectl apply -f service-v1.yaml creates a Knative Service, its underlying pod, a Configuration object, a Revision snapshot, and a Route that directs traffic to the new revision. You can inspect the resources using kubectl get pod,ksvc,configuration,revision,route .
Configuration changes (e.g., updating environment variables or the container image) automatically generate a new Revision and a new Route, allowing seamless rollouts.
Traffic splitting enables gradual rollouts by routing a percentage of traffic to a candidate revision. Switching the Service spec from runLatest to release and providing a revisions list with a rolloutPercent achieves this. An example YAML for a 20% rollout is:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: helloworld-csharp
namespace: default
spec:
release:
revisions: ["helloworld-csharp-00001", "helloworld-csharp-00004"]
rolloutPercent: 20
configuration:
revisionTemplate:
spec:
container:
# Replace {username} with your actual DockerHub
image: docker.io/{username}/twilio-csharp:v1Integrating with external services such as Twilio is straightforward. By exposing a Knative Service as a webhook, incoming SMS messages can be processed. The C# controller code for handling Twilio messages is:
[Route("[controller]")]
public class SmsController : TwilioController
{
[HttpGet]
public TwiMLResult Index(SmsRequest incomingMessage)
{
var messagingResponse = new MessagingResponse();
messagingResponse.Message("The Knative copy cat says: " + incomingMessage.Body);
return TwiML(messagingResponse);
}
}The corresponding Knative Service definition for the Twilio webhook mirrors the Hello World example, specifying the container image that runs the controller.
Overall, the article provides a practical guide to using Knative for serverless workloads on Kubernetes, covering deployment, configuration management, traffic control, and real‑world service integration.
Architects Research Society
A daily treasure trove for architects, expanding your view and depth. We share enterprise, business, application, data, technology, and security architecture, discuss frameworks, planning, governance, standards, and implementation, and explore emerging styles such as microservices, event‑driven, micro‑frontend, big data, data warehousing, IoT, and AI architecture.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.