Challenge
DifficultyMedium
Learner activity35 solved of 40 attempts

Roll Out a Canary Release With Core Kubernetes Objects

A new version of a web app is ready, but nobody wants to switch all users to it at once. Roll it out as a canary in Kubernetes and send about 20% of the real traffic to it.

Your team has a new version of the frontend web app. It runs on nginx:alpine and serves its page from the frontend-v2-config ConfigMap. Before switching all users to it, the team wants to send a small share of real traffic to the new version and watch how it behaves.

The current version runs as the frontend-stable Deployment in the canary namespace. It has 10 replicas of nginx:stable that serve the page from the frontend-v1-config ConfigMap. Users reach it through the frontend-service NodePort Service on port 30007.

Roll out the new version as a canary Deployment named frontend-canary in the same namespace. Label its pods with app: frontend and version: v2, so the team can tell the two versions apart. The namespace has room for exactly 10 frontend pods across both versions, and about 20% of the requests to frontend-service should reach the new version. The rest should keep going to the stable version. Use only built-in objects such as Deployments and Services, without an Ingress controller or a service mesh.

You can see which version answers a request with curl http://cplane-01:30007 from the dev-machine.

Hint 1: Serving the new page

A volume mount with subPath places a single file from a volume into the container. In that case, mountPath is the full path of the file. The frontend-stable Deployment already mounts its page this way.

Read more in Using subPath and Using ConfigMaps as files from a Pod.

Hint 2: Splitting the traffic

A plain Kubernetes Service has no setting for traffic weights. It spreads the connections roughly evenly across all the pods it selects, so each version gets about the same share of the requests as it has of the pods.

Read more in Canary deployments.

Hint 3: The canary gets no requests

If the canary pods run but curl never reaches them, compare the Service's selector with the labels of the canary pods. kubectl get endpointslices -n canary shows which pods the Service sends traffic to.

Read more in Defining a Service, Labels and Selectors, and EndpointSlices.

Problem
Solution
Start
Tasks