October 22, 2026
(Shallow) Dive into DevOps - Understanding and connecting Kubernetes, Terraform, Github Actions, ArgoCD
- DevOps
- Testing
- Docker
- Kubernetes
- Terraform
- Github Actions
- ArgoCD
- CI/CD
Introduction
During my first job, one of the things that absolutely bewildered me was how on every push, github ran all the tests that existed in the codebase, only allowing my CTO to merge if all tests pass. And once merged, it’s deployed automatically. Back then I was just a junior backend engineer, but this idea of automating deployments, checking if everything runs even after making changes was something I knew I had to master.
Fast forward to today, after a bit over 3 years of backend development and manually deploying web applications by SSH-ing into servers, pulling the code, restarting the systemd services and all that, I decided it was time to properly learn DevOps. So here we are.
The plan
The idea of this project is simple. Take a very basic Flask app, and add an entire semi-production grade CI/CD pipeline to it. In other words, well, over-engineer it because why not?
The app
Flask
The flask app is very simple, send in a book name and get the author. This was deliverately kept simple, no database, just lookup a dict. The idea is to learn DevOps, not flask.
src/
| Dockerfile
| main.py
| requirements.txt
|
+---tests/
| | test_book_fetch.py
The dict looks like this
{
"The Great Gatsby": "F. Scott Fitzgerald",
"To Kill a Mockingbird": "Harper Lee",
"1984": "George Orwell",
}
There are 2 endpoints.
GET /
returns "Welcome to the Book Writer App!"
This is only for health checks really. We will come to it later.
GET /<str:book_name>
returns name of the author, or "Book not found"
Testing
For testing, I used pytest since I actually used it before and quite comfortable with it.
And the test is really simple.
@pytest.mark.parametrize(
"book_input, expected_writer",
[
("The Great Gatsby", "F. Scott Fitzgerald"),
("To Kill a Mockingbird", "Harper Lee"),
("1984", "George Orwell"),
("Moby Dick", "Book not found"),
]
)
def test_fetch_writer_name(book_input, expected_writer):
assert _fetch_writer_name(book_input) == expected_writer
The test can be run using pytest ./tests and voilà.
Containerization with Docker: The fun stuff starts
Using docker, we can containerize our application so that our app can have the same dependencies no matter where it it is being run, my local PC or in a server.
I just used a simple Dockerfile. Generally I prefer using docker-compose but since this is only one service, a simple Dockerfile seemed reasonable enough.
FROM python:3.12.0-slim
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
CMD ["python", "main.py"]
Before anyone points it out, yes I could’ve used gunicorn (as one should in a production environment) but well that did not really matter here.
Also, for anyone new to Docker, notice that I have used the slim version and not the base python image. This was done to reduce the size of the container. A cheeky trick you can use.
Container Orchestration: Introducing Kubernetes
In a production environment, it might be tedious to just use docker manually. Think about it, every time theres an update, you have to SSH into the server, pull the changes, build the image, then run it. And if you wanted replicas of the same application in multiple servers, well, do that all over again. It would be nice to have something that will do this automatically. Lo and behold, Kubernetes.
Kubernetes is a container orchestration tool, simply put, it manages containers (does not have to be Docker, can be any other container system as well), replicas, load balancing and most importantly, rolling update.
Understanding rolling updates
Let’s say you have 2 pods (i.e. 2 replicas of your application). Generally you would have to stop the services, pull and rebuild it, then run it again. Which mean for a certain time, your app is not live.
What Kubernetes does, is that it will create a new pod from your new updated image, once created, it will delete one of the old pods. Then it will create another new pod, and only when it is running, deletes the last old one. Meaning, you have virtually zero downtime, even when updating. The Kubernetes load balancer automatically maps incoming traffic to the new pod, without you touching anything at all.
For our application, I have used 2 yaml files, basically configuration files to describe how the pods run, and any additional services. Kubernetes is declarative, meaning you declare the state of your deployments/services, and kubernetes engine ensures that the desired state is reached.
deployment.yaml
This is the bread and butter. In this file, I declare how many pods/replicas I want of my application, what is the docker image that the pod will run even how much system resource (cpu and memory) it can use. I have set 2 replicas, with following resource limits
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
Kubernetes also checks the health and readiness of the applcation via readinessProbe and livenessProbe. Both are set to the / endpoint for every 10s and 20s respectively.
service.yaml
I initally though that applying the deployment file was enough. I was wrong. Apparently, my application was running, but inside Kubernetes’ own internal network. I wasn’t really accessing anything. To solve this, I created a NodePort service that exposed port 5000 of my pods to external ports that I can actually use.
Minikube
So I have been talking about applying the kubernetes deployment files and service files for a while. But to do that, I will need an actual kubernetes cluster. Generally one would use something like a managed K8s cluster such as Amazon EKS or DigitalOcean’s managed Kubernetes service and so on. For my application though, I decided to not spend money and ran Minikube on my PC instead. Minikube is a software that can simulate a kubernetes cluster in your local environment, instead of having multiple servers for a cluster, you can use multiple ports on your computer. I found it really helpful for tinkering with kubernetes without breaking the bank or breaking anything at all.
However, unlike a normal person, I decided to overengineer the provisioning of minikube (just a tad bit).
Terraform: Write code, build infrastructure
Terraform is a declarative IaC (Infrastructure as Code) tool that does exactly what it sounds like. You write code, define exactly what services you need (be it VPS, Load Balancer, Object Storage, VPC), write the config and apply it. Terraform will actually build all these infrastructure in your given cloud provider so that you dont have to manually click buttons and setup everything by hand. Even better, you can even verson control your infratrsucture or spin up another replica for testing.
But as I’ve said before, I’m not really in mood to spend any money. So I provisioned the minikube service (with the docker engine) using Terraform. Is this the most realistic use case? Absolutely not. However, as for learning the basics of terraform, it got the job done. However, I admit this is probably the the part of the project I am least familiar with and I’ll need more time to get used to it with a real cloud provider.
terraform {
required_providers {
minikube = {
source = "scott-the-programmer/minikube"
version = "0.8.0"
}
}
}
provider "minikube" {
kubernetes_version = "v1.37.0"
}
resource "minikube_cluster" "minikube_docker" {
driver = "docker"
cluster_name = "devopsrun"
addons = [
"default-storageclass", "storage-provisioner"
]
}
After running terraform apply, I could run minikube start and my local cluster is ready to run.
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
And I could access my app though my overengineered kubernetes cluster. Sweet, but I still ran it by hand.
CI/CD: Automating deployments
Continuous Integration
The idea of Continuous Integration (CI) is simple. Once you push your code to Github or Gitlab, you automatically run tests to ensure the new changes won’t affect the existing code. You continuously check if the integration is properly done and nothign is broken. This would mean automatically checking linting, code formatting, making sure all tests are passing, and most importantly packaging the code for deployment.
For this project, I used Github Actions. It’s free, easy to setup, and I had actaully to some degree used it before.
The pipeline is quite basic. Once a push or pull request to main branch happens, run 2 jobs.
test:
name: Run PyTest
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r src/requirements.txt
- name: Run PyTest
run: |
pytest --maxfail=1 --disable-warnings -q
The first job, test runs all the tests via pytest. If it passes, it will go on to the next job.
build_and_push:
name: Build and Push Docker Image
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set Short SHA
run: |
echo "SHORT_SHA=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_ENV
- name: Build Docker Image
run: |
docker build -t infraredcoding/devopsrun:${{ env.SHORT_SHA }} ./src/
- name: Log in to DockerHub
run: |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Push Docker Image
run: |
docker push infraredcoding/devopsrun:${{ env.SHORT_SHA }}
- name: Configure Local Git
run: |
git config --global user.name "Imran Rahman"
git config --global user.email "imranrahman.ix@gmail.com"
- name: Update Kubernetes Deployment
run: |
sed -i "s/IMAGE_TAG/${{ env.SHORT_SHA }}/" k8s/deployment.yaml
git add k8s/deployment.yaml
git diff --cached --quiet && echo "No changes" && exit 0
git commit -m "Update deployment image to ${{ env.SHORT_SHA }} [skip ci]"
git push
This job generates a short SHA and appends it to the container tag when docker is building the image as the version. Then it logs in to dockerhub and pushed the newly built image code. There is however one new change to be made. Kubernetes has no clue what the latest hash (i.e. version tag) of my image is. So we change the placeholder IMAGE_TAG with the new hash and made a commit. I explicitely added [skip ci] to the commit message, otherwise it will recursively run another ci job for the new push.
Continuous Deployment
Now that the latest docker image of our application is in Docker Hub, we need some way to automate the deployment as well. Because manually writing kubectl apply -f deployment.yaml everytime a new push comes sort of defeats the purpose of CI/CD. To achieve this, I used ArgoCD.
Setting it up was quite simple.
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
I just used the imstall.yaml from their repo and voilà I got ArgoCD running in my k8s cluster. The next task was setting up my project. Using the UI (yes, I could have used a manifest, but the UI was simple enough), I added my github repo as the source, and added a new app pointing to the repo. As soon as that was done, ArgoCD took over, synced my current cluster with the latest chnages in github, ran rolling updates automatically from my own manifest files, and marked the end of the deployment process. Everytime there’s a change in my repo, ArgoCD picks it up, pulls and applies my new manifests and rolling updates does it’s magic.

Epilogue
This project, though very immature, basic, and did not simulate a production environment at all, was indeed a very awesome learning experience. I do not claim that I fully understand how Kubernetes works or even Terraform. There are many more optimizations that can be done, things that can be done a better way and whatnot. Nevertheless, I did learn a lot, at least at a surface level, which is better than nothing at all. The next part of my journey, I’ll probably take one technology and deep dive into it. Or even use proper DevOps in one of my production applications, see how that feels. This is a new world to me, exploration shall begin!
Github Repo: https://github.com/infraredCoding/devopsrun
Happy curiosity.