#4 Deploying and Monitoring loklak on Google Cloud with Kubernetes and StackDriver

431 views - Pratyush Singh
Tag(s) : docker google-cloud kubernetes gsoc loklak May 15, 2017, 8:22 a.m.
Kubernetes is a very popular container engine with large community support and high scalability. Let us see how can we set up loklak on such an engine on Google Cloud Platform and monitor it using Google StackDriver console


Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Source: https://kubernetes.io/

Deploying loklak on Google Cloud with Kubernetes

Follow these 10 steps to get an instance of loklak running on Google Cloud platform using Kubernetes.

Note: The document uses predefined names for various properties like project ID and docker image name to avoid confusion. It will be necessary to change them when needed in different setups.

1. Create Google Cloud Platform Account

Visit https://cloud.google.com/free/ and follow on-screen instructions to create an account and get the free trial.

2. Create a Project

Create a new project with desired name and ID.


kub1

3. Create a Container Engine for the Project

Go to https://console.cloud.google.com/kubernetes/list and wait for the container engine to get ready. We may require to select the project from the project section in the top-left corner.

4. Open the Google Cloud Shell

In the top-right panel, click the shell button.


screenshot from 2017-05-14 20-11-27

We'll be greeted by an online console.


screenshot from 2017-05-14 20-19-07

5. Clone the loklak project

$ git clone https://github.com/loklak/loklak_server.git
$ cd loklak_server/

6. Build the Docker Image and Push to Google Container Registry

$ docker build -t gcr.io/singhpratyush-loklak/loklak:v1 .
$ gcloud docker -- push gcr.io/singhpratyush-loklak/loklak:v1

This makes our cloud registry ready. Let us create a Kubernetes cluster where we can deploy this.

7. Creating a Container Cluster

gcloud provides easy to use interface for creating clusters. Let us take a look at the properties that we can configure while creating a cluster.

Argument Function Allowable Values
--num-nodes Number of nodes in the cluster. A natural number
--machine-type Type of each machine in the cluster.
  • f1-micro
  • g1-small
  • n1-standard-{1,2,4,8}
  • n1-highmem-{2,4,8}
  • n1-highcpu-{2,4,8}
  • --zone Zone where nodes would be located. See Compute Engine Docs

    For this example, let us create a cluster with following command -

    $ gcloud container clusters create loklak-cluster --num-nodes 3 --machine-type n1-standard-1 --zone us-central1-c
    

    This will take a few minutes to complete. After done, we can see a new cluster active on our console.


    screenshot from 2017-05-14 21-01-12

    8. Create a Deployment for the Container Registry

    $ kubectl run loklak --image=gcr.io/singhpratyush-loklak/loklak:v1 --port=80
    deployment "loklak" created
    

    We can see a list of deployments by running the following commands -

    $ kubectl get deployments
    NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
    loklak    1         1         1            1           2m
    

    9. Expose the Deployment

    With the server now deployed internally on Google Cloud Platform, we need to expose it to the Internet. For this, we use the following command -

    $ kubectl expose deployment loklak --type=LoadBalancer
    service "loklak" exposed
    

    Now, the platform will assign an external IP to the application. This may take some time. Run the following command to see the assigned external IP -

    $ kubectl get services
    NAME         CLUSTER-IP    EXTERNAL-IP     PORT(S)        AGE
    kubernetes   10.79.240.1   <none>          443/TCP        10m
    loklak       10.79.248.1   104.154.24.48   80:30287/TCP   1m
    

    10. Visit the Webpage

    On a browser, visit the deployment using the external IP (http://104.154.24.48/ in this case).

    Using Google StackDriver to Monitor Kubernetes

    Google Stackdriver provides powerful monitoring, logging, and diagnostics. It equips you with insight into the health, performance, and availability of cloud-powered applications, enabling you to find and fix issues faster. It is natively integrated with Google Cloud Platform, Amazon Web Services, and popular open source packages. Stackdriver provides a wide variety of metrics, dashboards, alerting, log management, reporting, and tracing capabilities.
    Source: https://cloud.google.com/stackdriver/

    Let us install StackDriver for the Kubernetes instance we just created. From the left panel in Google Cloud Console, select STACKDRIVER -> MONITORING.

    Next, we follow the easy steps to get our Google Cloud account linked to StackDriver. We would be required to choose a project while registering.

    After registering, we need to set up it on our cluster. In the Container Engine, connect to the existing cluster by using following command in the cloud shell -

    $ gcloud container clusters get-credentials loklak-cluster --zone us-central1-c --project singhpratyush-loklak
    

    Once connected, run the following commands to install StackDriver -

    $ curl -sSO https://repo.stackdriver.com/stack-install.sh
    $ sudo bash stack-install.sh --write-gcm
    

    Next, let us install the logging agent too -

    $ curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
    $ sudo bash install-logging-agent.sh
    

    After this, we can see the results instantly on the StackDriver console. Let StackDriver collect data about our Cluster Engine for some time. After that, we can see fruitful insights of our cluster in graphs, which we can modify according to our needs.

    Conclusion

    This tutorial provides a step by step guide about setting up loklak on Google Cloud with Kubernetes, which is a production ready, battle-tested, highly scalable cloud solution. It has being the most active open source project recently and has a huge community support. This blog post gives a step by step guide to deploying loklak using Kubernetes on Google Cloud.

    It also explains how to set up Google StackDriver for monitoring and diagnostic of the Google Cluster Engine.

    Share: