In this post, I will walk you through deploying the Open Event Server on Kubernetes, hosted on Google Cloud Platform’s Compute Engine. You’ll be needing a Google account for this, so create one if you don’t have one.
First, I cd into the root of our project’s Git repository. Now I need to create a Dockerfile. I will use Docker to package our project into a nice image which can be then be “pushed” to Google Cloud Platform. A Dockerfile is essentially a text doc which simply contains the commands required to assemble an image. For more details on how to write one for your project specifically, check out Docker docs. For Open Event Server, the Dockerfile looks like the following:
These commands simply install the dependencies and set up the environment for our project. The final CMD command is for running our project, which, in our case, is a server.
After our Dockerfile is configured, I go to Google Cloud Platform’s console and create a new project:
Once I enter the product name and other details, I enable billing in order to use Google’s cloud resources. A credit card is required to set up a billing account, but Google doesn’t charge any money for that. Also, one of the perks of being a part of FOSSASIA was that I had about $3000 in Google Cloud credits! Once billing is enabled, I then enable the Container Engine API. It is required to support Kubernetes on Google Compute Engine. Next step is to install Google Cloud SDK. Once that is done, I run the following command to install Kubernetes CLI tool:
Then I configure the Google Cloud Project Zone via the following command:
Now I will create a disk (for storing our code and data) as well as a temporary instance for formatting that disk:
Once the disk is attached to our instance, I SSH into it and list the available disks:
Now, ls the available disks:
This will list multiple disks (as shown in the Terminal window below), but the one I want to format is “google-persistent-disk-1”.
Now I format that disk via the following command:
Finally, after the formatting is done, I exit the SSH session and detach the disk from the instance:
Now I create a Kubernetes cluster and get its credentials (for later use) via gcloud CLI:
I can additionally bind our deployment to a domain name! If you already have a domain name, you can use the IP reserved below as an A record of your domain’s DNS Zone. Otherwise, get a free domain at freenom.com and do the same with that domain. This static external IP address is reserved in the following manner:
It’ll be useful if I note down this IP for further reference. I now add this IP (and our domain name if I used one) in Kubernetes configuration files (for Open Event Server, these were specific files for services like nginx and PostgreSQL):
These files will look similar for your specific project as well. Finally, I run the deployment script provided for Open Event Server to deploy with defined configuration:
This is the specific deployment script for this project; for your app, this will be a bunch of simple kubectl create * commands specific to your app’s context. Once this script completes, our app is deployed! After a few minutes, I can see it live at the domain I provided above!
I can also see our project’s statistics and set many other attributes at Google Cloud Platform’s console:
And that’s it for this post! For more details on deploying Docker-based containers on Kubernetes clusters hosted by Google, visit Google Cloud Platform’s documentation.