Coinprice

ai generated cover photo

Project Overview

This project is intended to serve as a demo of using Terraform, Docker, Kubernetes, and Google Cloud Platform to build a basic DevOps environment for a Flask API.

All the code for this project is available here on my GitHub:
https://github.com/labusaid/devops-example-coinprice

The App

Since this project is intended to demonstrate DevOps skills and techniques more than any particular app or framework, the app is very straightforward. In the real world, basically any containerized app could be dropped in place of this ranging from a nodejs microservice to a full machine learning image processing pipeline. I have many other examples of apps covering this range in my portfolio, so in this case all the "coinprice" app does is serve as a proxy to the coingecko api build using Flask. The app code is available at src/httpServer.py and the Dockerfile in the root of the repo.

coinprice fetching $ETH price

CI/CD Pipeline

Any push to the github repo main branch triggers a build to start in Google Cloud Build, which runs the steps provided by cloudbuild.yaml in the root of the repo. This builds the Docker container and pushes it to Artifact Registry, then sets the Kubernetes deployment to use the version tag of the new artifact.

cloudbuild Successful build and deploy

Kubernetes

A big aspect of this project is standing up a Kubernetes cluster and configuring the manifest for this application. For running a single application Kubernetes is generally overkill, but for companies with multiple applications and thousands of users it's an extremely powerful tool that helps with almost every aspect of operations. There's lots of great information on Kubernetes out there and it's not something that could easily be covered in a one page writeup, so if you're interested in my specific configuration you can check that out under kubernetes/k8smanifests.yaml in the repo.

kubernetes GKE Cluster

Terraform for Everything

Infrastructure as Code (IaC) has been the direction that most serious tech companies are moving. My preference for this is to use some kind of declarative tooling. Declarative models offer some advantages in allowing easy integrations with third party tooling for security and auditing. Traditionally this is done with Terraform, but other competitors have popped up including AWS's own Cloud Development Kit (CDK) have come up in recent years and can offer some advantages. I chose to use Terraform for this project since it has the most widespread adoption across the industry and is designed to work with multi cloud enviornments, even down to supporting roll-your-own cloud tools like localstack.

A somewhat useful diagram A somewhat useful architechture diagram generated from Terraform with Rover

Terrform is used to define everything that would be needed to stand up this enviornment from a brand new Google Cloud project. This includes defining secrets and service accounts, setting up CI/CD, configuring networks, deploying GKE, setting alerts, and everything else to support that.
The terraform for this project can be found at terraform/main.tf.

Try it yourself!

The GitHub repo has detailed installation instructions if you're interested in testing it out for yourself, I can't garuntee everything will work perfectly the first time, but if you're familiar with cloud enviornments it shouldn't be too difficult to get running.