The Countly reference Kubernetes setup is based on the Google Kubernetes Engine; however, with a few modifications (SSD disks for MongoDB and a static IP address for Ingress), it becomes applicable to any Kubernetes cluster.
Overview
The basic Kubernetes setup for Countly includes the following components: * the MongoDB replica set installed from the mongodb-replicaset Helm chart, backed by SSD disks. * countly-api service wrapping a countly-api-deployment with 2 countly/api pods; * countly-frontend service wrapping a countly-frontend-deployment with 1 countly/frontend pod; * countly-ingress Ingress in front of the services above.
Setting up a Kubernetes Cluster
The following assumes you have already set up kubectl & helm. The full script, including basic kubectl & helm configurations, is available in our Github repository.
First, create a countly namespace:
kubectl create ns countly kubectl config set-context --current --namespace=countly
The installation and configuration of a MongoDB cluster are out of the scope of this document, so we'll just leave some starting points here for consistency (note, the storage-class.yaml below contains a GCE-specific provisioner and an SSD disk type):
cd countly/bin/docker/k8s kubectl apply -f mongo/storage-class.yaml helm install --name mongo -f mongo/values.yaml stable/mongodb-replicaset
Then we will need to create Countly deployments and services:
kubectl apply -f countly-frontend.yaml kubectl apply -f countly-api.yaml
Note that the countly-api.yaml and countly-frontend.yaml deployments contain the configuration environment options we have covered above, including the MongoDB connection URL and the COUNTLY_PLUGINS environment variable.
Once Countly deployments are up and running, we'll also need to expose the setup to the outer world. This is done with the help of a static IP address and an Ingress configured to forward incoming requests either to the countly-apior countly-frontendservices. Our countly-ingress.yaml contains the TLS secret definition; please replace placeholders with your certificate, key, and hostname before the creation of Ingress:
gcloud compute addresses create countly-static-ip --global kubectl apply -f gce/countly-ingress.yaml
Please note that the full Countly stack deployment and corresponding health checks can easily take 10-20 minutes, so give it some time.
The only thing left is the creation of a DNS A-record with an IP-address, which you can get by running:
kubectl get ing