As a follow-up from my previous jenkins install, I decided to instead use gitlab to run my ci/cd pipeline due to the following reasons:
- Code and Jobs in one place feels more natural as execution automatically gets triggered in each code commit.
- No need to mess with plugins. Way easier to setup.
Now, to have a real-world experience (or alteast close to it) I needed to have a good use case to apply it. Good thing my sister has a local baking business – a good use case is to create an online presence for it. After 3 weekends, I was able to finish the webpage with full CI/CD pipeline that deploys to dev/prod environments depending on the branch commit 🙂
The output: https://reddeliciousph.com
Here are the learning and overview from the project
Learnings
- Containerizing application on Day 1 will save you a lot of time when you start deploying it in Production Environment.
- For python applications, this saves you creating virtual environments as this can be initiated inside the container.
- Always use environment variables to switch from DEV to PROD.
- Docker-compose is your friend. Kubernetes Kompose is your best friend. Converting from docker-compose to kubernetes manifest is so easy with kompose
- Use ootb Kubernetes Kustomize for easy templating
- Gitlab CICD: create jobs that gets triggered only to specific branches. This avoids always deploying to PROD for each changes you’ll be doing
- Gitlab Runner: Linux runner is really easy to use but may have security implications once you have multiple teams using it.
- In using on-prem Harbor Registry – use a trusted SSL certificate! This will save you head-ache when pushing/pulling from Kubernetes as you don’t need to mess with docker daemon.json in the nodes. For me, using letsencrypt is the easiest way to do this.
Overview of Technology Used:
- Web Framework:
- Flask (+ Bootstrap Template + FontAwesome Icons)
- Celery for offloading sending emails
- Packaging
- Docker Container since day 1 (no virtual environments! yey)
- Git Repo and CI/CD Engine
- Gitlab
- Linux Runner (originally, I was using kubernetes runner but I encountered too many issues)
- CICD Pipeline
- Commit to DEV branch -> test webpage, deploy to dev and push to harbor
- Merge from DEV to MASTER -> deploy to prod and push to harbor
- Container Registry
- Harbor
- Development Environment
- local Kubernetes installation deployed using TKG
- Production Environment
- VPS running ubuntu with docker running
That’s it. Thanks for reading.