Canary Testing

Alien
2 min readOct 2, 2019

--

We have numerous testing types — unit testing, manual testing, integration testing, blackbox testing and so on. All these types of testing miss one crucial point —the tests never perfectly simulate the real world usage of the code no matter how hard we try to simulate it.

The goal of a canary test is to make sure code changes are transparent and work in a real world environment. In canary testing, a short number of users are pushed new code without the users knowledge. If the policies are set by the company, then the all metrics such as capturing customer responses, behavior and everything required the company to make a decision.

Canary Testing

How to leverage Kubernetes?

For example, following is the kubernetes yaml which deployed right now. The yaml file is for understanding the concept.

It contains service and deployment. If you notice the match labels: it contains app and track as stable. So, the yaml file create one service and two pods.

kind: Service
apiVersion: v1
metadata:
name: canary-testing-service
spec:
type: NodePort
selector:
app: canary-testing
ports:
— protocol: TCP
port: 8080
nodePort: 80
— -apiVersion: apps/v1
kind: Deployment
metadata:
name: canary-testing-deployment
labels:
app: canary-testing
spec:
replicas: 2
selector:
matchLabels:
app: canary-testing
track: stable
template:
metadata:
labels:
app: canary-testing
track: stable
spec:
containers:
— name: canary-testing
image: httpd:2.4
ports:
— containerPort: 8080
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 15
timeoutSeconds: 1
periodSeconds: 10
resources:
requests:
cpu: 200m

Now, you want to test new code, you will deploy it as following. New image, new service and track as canary.

kind: Service
apiVersion: v1
metadata:
name: canary-testing-service
spec:
type: NodePort
selector:
app: canary-testing
track: canary
ports:
— protocol: TCP
port: 8080
nodePort: 81
— -apiVersion: apps/v1
kind: Deployment
metadata:
name: canary-testing-deployment
labels:
app: canary-testing
spec:
replicas: 1
selector:
matchLabels:
app: canary-testing
track: canary
template:
metadata:
labels:
app: canary-testing
track: canary
spec:
containers:
— name: canary-testing
image: httpd:latest
ports:
— containerPort: 8080
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 15
timeoutSeconds: 1
periodSeconds: 10
resources:
requests:
cpu: 200m

So, when you hit the URL you will get redirected to either of the pods. Depending upon the load, kubernetes will show you either new code or old code. Now, you ready to perform some analysis on the new code.

--

--

No responses yet