Skip to main content

Canarytrace in Kubernetes

What you’ll learn#

  • You will know how to run Canarytrace on cloud
  • You will know how to setup Elasticsearch cloud
  • You will know how to start Kubernetes on DigitalOcean
  • You will be know how to prepare the cronjob for deploy and rotate Canarytrace Smoke
  • Basic of working with the Lens application

Canarytrace on cloud#

This tutorial introduces you to the essentials of Canarytrace community edition by walking you through run first smoke in Kubernetes on cloud.

Step-by-step#

We will go step by step to build your Canarytrace infrastructure based on Kubernetes and Elasticsearch in cloud.

Create deployment on Elastic cloud#


  • save your Elasticsearch endpoint e.g. https://9e0f4b1db5234c48b0933bd421b543f0.us-central1.gcp.cloud.es.io:9243
  • save your Kibana endpoint e.g. https://2036be9b05634936879e34555dbaa17b.us-central1.gcp.cloud.es.io:9243

Elastic and Kibana endpoints

  • save your credentials e.g. username: elastic and password: GnkOwVswOkGqHRKuXzCBbwUE

Create Kubernetes cluster on DigitalOcean#


  • Download config Action > Download Config into download directory canarytrace-kubeconfig.yaml

Setup Elasticsearch and Kibana#


version: "3.8"
services:
installer:
image: quay.io/canarytrace/installer:1.0
environment:
ELASTIC_ENDPOINT: 'https://9e0f4b1db5234c48b0933bd421b543f0.us-central1.gcp.cloud.es.io'
ELASTIC_PORT: 9243
ELASTIC_INDEX_PREFIX: 'c.'
ELASTIC_USER: 'elastic'
ELASTIC_PASS: 'GnkOwVswOkGqHRKuXzCBbwUE'
KIBANA_ENDPOINT: 'https://2036be9b05634936879e34555dbaa17b.us-central1.gcp.cloud.es.io'
KIBANA_PORT: 9243
KIBANA_USER: 'elastic'
KIBANA_PASS: 'GnkOwVswOkGqHRKuXzCBbwUE'
  • save the code to a file docker-compose.yaml and run docker-compose up
Installer result
installer_1 | ┌─────────────────────────┬────────────────────┬────────────────────┐
installer_1 | │ │ executed │ failed │
installer_1 | ├─────────────────────────┼────────────────────┼────────────────────┤
installer_1 | │ iterations │ 10
installer_1 | ├─────────────────────────┼────────────────────┼────────────────────┤
installer_1 | │ requests │ 90
installer_1 | ├─────────────────────────┼────────────────────┼────────────────────┤
installer_1 | │ test-scripts │ 180
installer_1 | ├─────────────────────────┼────────────────────┼────────────────────┤
installer_1 | │ prerequest-scripts │ 90
installer_1 | ├─────────────────────────┼────────────────────┼────────────────────┤
installer_1 | │ assertions │ 180
installer_1 | ├─────────────────────────┴────────────────────┴────────────────────┤
installer_1 | │ total run duration: 8.6s │
installer_1 | ├───────────────────────────────────────────────────────────────────┤
installer_1 | │ total data received: 2.64KB (approx)
installer_1 | ├───────────────────────────────────────────────────────────────────┤
installer_1 | │ average response time: 901ms [min: 154ms, max: 2.5s, s.d.: 794ms]
installer_1 | └───────────────────────────────────────────────────────────────────┘

Prepare deployment script / CronJob#


Open Cronjob in your editor and edit labels in env:

  • BASE_URL add your landing pages separated by semicolon
  • ELASTIC_CLUSTER add your Elasticsearch endpoint
  • ELASTIC_HTTP_AUTH add your Elasticsearch credentials in a format username:password
CronJob with Canarytrace smoke
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: smoke-desktop
namespace: canarytrace
spec:
concurrencyPolicy: Replace
failedJobsHistoryLimit: 2
schedule: "*/3 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: canarytrace
image: quay.io/canarytrace/canarytrace-pub:<your-Canarytrace-Docker-image>
env:
- name: BASE_URL
value: "https://webperf.canarytrace.com/;https://battle.canarytrace.com/"
- name: PT_AUDIT
value: "allow"
- name: PT_AUDIT_THROTTLING
value: "desktopDense4G"
- name: LABELS
value: "desktop, smoke"
- name: LICENSE
value: "XXXXX-YYYYY-Z4WG5-5363C-CF0CB-A8647"
- name: ELASTIC_CLUSTER
value: "https://9e0f4b1db5234c48b0933bd421b543f0.us-central1.gcp.cloud.es.io:9243"
- name: ELASTIC_HTTP_AUTH
value: "elastic:GnkOwVswOkGqHRKuXzCBbwUE"
resources:
requests:
memory: "300Mi"
cpu: "200m"
limits:
memory: "1600Mi"
cpu: "800m"
volumeMounts:
- name: assets
mountPath: /opt/canary/assets
imagePullPolicy: "IfNotPresent"
- name: selenium
image: selenium/standalone-chrome:4.1.1-20211217
ports:
- containerPort: 4444
resources:
requests:
memory: "2000Mi"
cpu: "2000m"
limits:
memory: "4000Mi"
cpu: "4000m"
imagePullPolicy: "IfNotPresent"
volumeMounts:
- mountPath: "/dev/shm"
name: "dshm"
livenessProbe:
httpGet:
path: /status
port: 4444
initialDelaySeconds: 10
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /status
port: 4444
initialDelaySeconds: 10
timeoutSeconds: 5
restartPolicy: "Never"
terminationGracePeriodSeconds: 5
volumes:
- name: "dshm"
emptyDir:
medium: "Memory"

Lens | The Kubernetes IDE#


Lens is open-source and multi-platform IDE for controll Kubernetes cluster.

Last steps for run Canarytrace Smoke in Kubernetes

  • Download and install Lens. Please select correct platform (Linux, MacOS or Windows)
  • Drag and drop your canarytrace-kubeconfig.yaml file to Lens and use it to add your Kubernetes cluster. See below on screencast.
  • Copy your CronJob with Canarytrace for create resource and deploy to Kubernetes. See below on screencast.

View the result in Kibana#


That's all 🎉 Now wait a few minutes and you can explore dashboard and visualizations in Kibana. Open your Kibana endpoint https://2036be9b05634936879e34555dbaa17b.us-central1.gcp.cloud.es.io:9243 in your browser and navigate to Dashboard / Canarytrace Smoke Overview

Kibana Cloud