Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.
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.
Visit https://cloud.google.com/free/ and follow on-screen instructions to create an account and get the free trial.
Create a new project with desired name and ID.
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.
In the top-right panel, click the shell button.
We'll be greeted by an online console.
$ git clone https://github.com/loklak/loklak_server.git $ cd loklak_server/
$ 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.
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.
||Number of nodes in the cluster.||A natural number|
||Type of each machine in the cluster.||
||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.
$ 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
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 188.8.131.52 80:30287/TCP 1m
On a browser, visit the deployment using the external IP (http://184.108.40.206/ in this case).
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.
Let us install StackDriver for the Kubernetes instance we just created. From the left panel in Google Cloud Console, select
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.
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.