First run of Canarytrace in Kubernetes

What you’ll learn#

  • You will know how to run Canarytrace Smoke 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:7.3
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-web
spec:
concurrencyPolicy: Replace
failedJobsHistoryLimit: 2
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: selenium
image: selenium/standalone-chrome:3.141.59-20200730
ports:
- containerPort: 4444
resources:
requests:
memory: "4000Mi"
cpu: "2000m"
limits:
memory: "6000Mi"
cpu: "4000m"
imagePullPolicy: "IfNotPresent"
volumeMounts:
- mountPath: "/dev/shm"
name: "dshm"
livenessProbe:
httpGet:
path: /wd/hub
port: 4444
initialDelaySeconds: 10
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /wd/hub
port: 4444
initialDelaySeconds: 10
timeoutSeconds: 5
- name: canary
image: quay.io/canarytrace/smoke:3.0.5
env:
- name: BASE_URL
value: "http://canarytrace.com/;https://www.teststack.cz/"
- name: SMOKE
value: allow
- name: ELASTIC_CLUSTER
value: "https://9e0f4b1db5234c48b0933bd421b543f0.us-central1.gcp.cloud.es.io:9243"
- name: ELASTIC_HTTP_AUTH
value: "elastic:GnkOwVswOkGqHRKuXzCBbwUE"
- name: AT_DRIVER_HOST_NAME
value: "localhost"
resources:
requests:
memory: "300Mi"
cpu: "200m"
limits:
memory: "400Mi"
cpu: "300m"
imagePullPolicy: "IfNotPresent"
restartPolicy: "Never"
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