This guide demonstrates how to perform Canary rollouts using the SMI Traffic Split configuration.
Prerequisites
- Kubernetes cluster running Kubernetes v1.20.0 or greater.
- Have OSM installed.
- Have
kubectlavailable to interact with the API server. - Have
osmCLI available for managing the service mesh.
Demo
In this demo, we will deploy an HTTP application and perform a canary rollout where a new version of the application is deployed to serve a percentage of traffic directed to the service.
To split traffic to multiple service backends, the SMI Traffic Split API will be used. More about the usage of this API can be found in the traffic split guide. For client applications to transparently split traffic to multiple service backends, it is important to note that client applications must direct traffic to the FQDN of the root service referenced in a TrafficSplit resource. In this demo, the curl client will direct traffic to the httpbin root service, initially backed by version v1 of the service, and then perform a canary rollout to direct a percentage of traffic to version v2 of the service.
The following steps demonstrate the canary rollout deployment strategy.
Note: Permissive traffic policy mode is enabled to avoid the need to create explicit access control policies.
Enable permissive mode
osm_namespace=osm-system # Replace osm-system with the namespace where OSM is installedkubectl patch meshconfig osm-mesh-config -n "$osm_namespace" -p '{"spec":{"traffic":{"enablePermissiveTrafficPolicyMode":true}}}' --type=merge
Deploy the
curlclient into thecurlnamespace after enrolling its namespace to the mesh.# Create the curl namespacekubectl create namespace curl# Add the namespace to the meshosm namespace add curl# Deploy curl client in the curl namespacekubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.1/manifests/samples/curl/curl.yaml -n curl
Confirm the
curlclient pod is up and running.$ kubectl get pods -n curlNAME READY STATUS RESTARTS AGEcurl-54ccc6954c-9rlvp 2/2 Running 0 20s
Create the root
httpbinservice that clients will direct traffic to. The service has the selectorapp: httpbin.# Create the httpbin namespacekubectl create namespace httpbin# Add the namespace to the meshosm namespace add httpbin# Create the httpbin root service and service accountkubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.1/manifests/samples/canary/httpbin.yaml -n httpbin
Deploy version
v1of thehttpbinservice. The servicehttpbin-v1has the selectorapp: httpbin, version: v1, and the deploymenthttpbin-v1has the labelsapp: httpbin, version: v1matching the selector of both thehttpbinroot service andhttpbin-v1service.kubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.1/manifests/samples/canary/httpbin-v1.yaml -n httpbin
Create an SMI TrafficSplit resource that directs all traffic to the
httpbin-v1service.kubectl apply -f - <<EOFapiVersion: split.smi-spec.io/v1alpha2kind: TrafficSplitmetadata:name: http-splitnamespace: httpbinspec:service: httpbin.httpbin.svc.cluster.localbackends:- service: httpbin-v1weight: 100EOF
Confirm all traffic directed to the root service FQDN
httpbin.httpbin.svc.cluster.localis routed to thehttpbin-v1pod. This can be verified by inspecting the HTTP response headers and confirming that the request succeeds and the pod displayed corresponds tohttpbin-v1.for i in {1..10}; do kubectl exec -n curl -ti "$(kubectl get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')" -c curl -- curl -sI http://httpbin.httpbin:14001/json | egrep 'HTTP|pod'; doneHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvt
The above output indicates all 10 requests returned HTTP 200 OK, and were responded by the
httpbin-v1pod.Prepare the canary rollout by deploying version
v2of thehttpbinservice. The servicehttpbin-v2has the selectorapp: httpbin, version: v2, and the deploymenthttpbin-v2has the labelsapp: httpbin, version: v2matching the selector of both thehttpbinroot service andhttpbin-v2service.kubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.1/manifests/samples/canary/httpbin-v2.yaml -n httpbin
Perform the canary rollout by updating the SMI TrafficSplit resource to split traffic directed to the root service FQDN
httpbin.httpbin.svc.cluster.localto both thehttpbin-v1andhttpbin-v2services, fronting thev1andv2versions of thehttpbinservice respectively. We will distribute the weight equally to demonstrate traffic splitting.kubectl apply -f - <<EOFapiVersion: split.smi-spec.io/v1alpha2kind: TrafficSplitmetadata:name: http-splitnamespace: httpbinspec:service: httpbin.httpbin.svc.cluster.localbackends:- service: httpbin-v1weight: 50- service: httpbin-v2weight: 50EOF
Confirm traffic is split proportional to the weights assigned to the backend services. Since we configured a weight of
50for bothv1andv2, requests should be load balanced to both the versions as seen below.$ for i in {1..10}; do kubectl exec -n curl -ti "$(kubectl get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')" -c curl -- curl -sI http://httpbin.httpbin:14001/json | egrep 'HTTP|pod'; doneHTTP/1.1 200 OKpod: httpbin-v2-6b48697db-cdqldHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v2-6b48697db-cdqldHTTP/1.1 200 OKpod: httpbin-v2-6b48697db-cdqldHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvtHTTP/1.1 200 OKpod: httpbin-v2-6b48697db-cdqldHTTP/1.1 200 OKpod: httpbin-v2-6b48697db-cdqldHTTP/1.1 200 OKpod: httpbin-v1-77c99dccc9-q2gvt
The above output indicates all 10 requests returned an HTTP 200 OK, and both
httpbin-v1andhttpbin-v2pods responsed to 5 requests each based on the weight assigned to them in theTrafficSplitconfiguration.
