Cluster Deployment with Google Kubernetes Engine (GKE)



Google Kubernetes Engine (GKE) provides a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. The GKE environment consists of multiple machines -specifically, Compute Engine instances- grouped together to form a cluster.

GKE clusters are powered by the Kubernetes open source cluster management system. Kubernetes provides the mechanisms through which you interact with your cluster. Using Kubernetes commands and resources allows you to deploy and manage your applications, perform administration tasks, set policies, and monitor the health of your deployed workloads.


To get started, you must first have:

Creating a Google Kubernetes Cluster Using GKE

  1. Navigate to Google Kubernetes Engine page in the cloud console.

  2. Click on Create and, based on your requirements, select the cluster mode. In this guide, we will be using GKE Standard cluster mode to configure the cluster.

  3. Configure the following options in the Cluster Basics tab:
    • Assign the Name to the cluster which is being created.

    • Based on your requirement, you can select the Location type for the cluster.

    • Select the Control Plane version based on your requirement.

  4. Configure the following options in the Node Pools tab:
    • Assign the Name, along with the Number of nodes in the Size tab.
    • Based on your requirement, you can enable Autoscaling.

  5. Based on your Data Points estimation, select the Resource allocation (CPU, Memory, and Disk specifications) for the Node Pools in the Nodes section of the default pool to meet the infrastructure requirement.
    Additional Security, Taints, and Labels can be configured for the Node Pools under the Security & Metadata section.

  6. Automation, Networking, and additional features can be configured in the Cluster section as per your requirement.

  7. After configuring all the sections, proceed to Create the cluster.

It will take a few minutes to initialize and create the Kubernetes cluster. After the creation is completed, the cluster will be available in the Kubernetes Cluster tab.

Connecting to the Google Kubernetes Cluster

  1.  After creating the Kubernetes Cluster as mentioned above, set the region/zone along with the Project ID using this Google Cloud command line to authenticate and access the cluster:
    gcloud config set project <project id>
    gcloud config set compute/<region or zone> <value of region or zone>
  2. After configuring the default project and computing the region/zone, use the command below to fetch the authentication credentials for the cluster:
    gcloud container clusters get-credentials <cluster name>
  3. Verify the connection to your cluster using this Kubectl get nodes command to return a list of the cluster nodes:

    kubectl get nodes
    Note! Remember you need to verify that the nodes are in the Ready status in the output of the command above.

Deploying Countly Application on Kubernetes Cluster

The following assumes you have already set up kubectl and helm. Serviced, Deployments, and Ingress resource configurations are available in our Github repository.

  1. Firstly, create a namespace "Countly" and set it as default to deploy the services and application pods in the Countly namespace to isolate the resources in a single cluster, as shown below:

    kubectl create ns countly 
    kubectl config set-context --current --namespace=countly
  2. After creating the namespace, create a storage class with a GCE-specific provisioner and Disk type.
    cd countly/bin/docker/k8s
    kubectl apply -f mongo/storage-class.yaml
    kubectl get storageclass
  3. Install MongoDB and set up a replica set configuration prior to installing Countly's API and Frontend pods, as plugins installation is dependent on MongoDB. Use the commands below:
    cd countly/bin/docker/k8s
    helm install mongo -f mongo/values.yaml stable/mongodb-replicaset
    To verify the installation, check the pods generated for MongoDB, as shown below:
    kubectl get pods
  4. Before deploying the Countly application containers, create a Kubernetes Secret to authenticate to and access Countly Enterprise Docker Images from our Private Google Container Registry.
    To create the Secret, refer to this Guide.

    Step available only in Countly Enterprise.

  5. Once the MongoDB pods are running, create Countly Deployments and Services for the API and the Frontend.
    Both countly-frontend.yaml and countly-api.yaml need to be edited withkey:value pair to configure pods with relevant values (Refer env config guide), in the env section:
    value: "mobile,web,desktop,some,more,plugins" #<Enterprise or Community Plugins>
    value: "gridfs"
    value: "mongodb://" #<Mongodb pod connection names>
    value: #<Domain name required as url>
    value: "4" #<value can be CPU core count>

    - name: NODE_OPTIONS
    value: "--max-old-space-size=2048"
    value: ""
    value: 25
    value: "example-user"
    value: "example-password"
    cd countly/bin/docker/k8s
    kubectl apply -f countly-frontend.yaml
    kubectl apply -f countly-api.yaml
  6. Once Countly Service and deployments are up and running, you will also need to expose the setup to the outer world so that it can be accessible publicly.
    This can be done by setting up an ingress resource configured to forward all incoming requests either to the Countly-API or to the Countly-frontend services based on the route defined.

    To do this, create the Kubernetes secret to enable SSL for the URL mapped with your service. Use the command to help you create a TLS Secret:
    kubectl create secret tls <add name to secret> --key <path-to-key> --cert <path-to-cert>
    kubectl get secret #To view the secret created
  7. Create a Static IP address that will be assigned to Ingress resource through which you will map your DNS name, as shown below:
    gcloud compute addresses create <K8s-ingress-ip-name> --global 
  8. After generating the TLS Secret, create the Ingress resource to route the traffic based on the path configured for the Countly application:
    kind: Ingress
    name: countly-ingress
    annotations: / "k8s-ingress-ip-name"
    - hosts:
    secretName: countly-tls
    - host: YOUR_HOSTNAME #
    - path: /i
    pathType: Prefix
    name: countly-api
    number: 3001
    - path: /i/*
    pathType: ImplementationSpecific
    name: countly-api
    number: 3001
    - path: /o
    pathType: Prefix
    name: countly-api
    number: 3001
    - path: /o/*
    pathType: ImplementationSpecific
    name: countly-api
    number: 3001
    - path: /
    pathType: Prefix
    name: countly-frontend
    number: 6001
    To view the Ingress created, use the command below:
    kubectl get ingress
  9. The final step would be to map the DNS A record with the IP address associated with Ingress.

Looking for help?