Auto Deployment of SUSI Server using Kubernetes on Google Cloud Platform

Recently, we auto deployed SUSI Server on Google Cloud Platform using Kubernetes and Docker Images after each commit in the GitHub repo with the help of Travis Continuous Integration. So, basically, whenever a new commit is added to the repo, during the Travis build, we build the docker image of the server and then use it to deploy the server on Google Cloud Platform. We use Kubernetes for deployment since it is very easy to scale up the Project when traffic on the server is increased and Docker because using it we can easily build docker images which then can be used to update the deployment. This schematic will make things more clear what exactly is the procedure. Prerequisites You must be signed in to your Google Cloud Console and have enabled billing and must have credits left in your account. You must have a docker account and a repo in it. If you don’t have one, make it now. You should have enabled Travis on your repo and have a Travis.yml file in your repo. You must already have a project in Google Cloud Console. Make a new one if you don’t have. Pre Deployment Steps You will be needed to do some work on Google Cloud Platform before actually starting the auto deployment process. Those are: Creating a new Cluster. Adding and Formatting Persistence Disk Adding a Persistent Volume CLaim (PVC) Labeling a node as primary. Check out this documentation on how to do that. It may help. Implementation Img src: https://cloud.google.com/solutions/continuous-delivery-with-travis-ci 1. The first step is simply to add this line in Travis.yml file and create an empty deploy.sh, file mentioned below. after_success: - bash kubernetes/travis/deploy.sh Now we’ll be moving line by line and adding commands in the empty deploy.sh file that we created in the previous step. 2. Next step is to remove obsolete Google Cloud files and install Google Cloud SDK and kubectl command. Use following lines to do that. echo ">>> Removing obsolete gcoud files" sudo rm -f /usr/bin/git-credential-gcloud.sh sudo rm -f /usr/bin/bq sudo rm -f /usr/bin/gsutil sudo rm -f /usr/bin/gcloud echo ">>> Installing new files" curl https://sdk.cloud.google.com | bash; source ~/.bashrc gcloud components install kubectl 3. In this step you will be needed to download a JSON file which contains your Google Cloud Credentials, then copy that file to your repo and encrypt it using Travis encryption keys. Follow https://youtu.be/7U4jjRw_AJk this video to see how to do that. 4. So, now you have added your encrypted credentials.json files in your repo and now you need to use those credentials to login into your google cloud account. So, use below lines to do that. echo ">>> Decrypting credentials and authenticating gcloud account" # Decrypt the credentials we added to the repo using the key we added with the Travis command line tool openssl aes-256-cbc -K $encrypted_YOUR_key -iv $encrypted_YOUR_iv -in ./kubernetes/travis/Credentials.json.enc -out Credentials.json -d gcloud auth activate-service-account --key-file Credentials.json export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/Credentials.json #add gcoud project id gcloud config set project YOUR_PROJECT_ID gcloud container clusters get-credentials YOUR_CONTAINER…

Continue ReadingAuto Deployment of SUSI Server using Kubernetes on Google Cloud Platform