Using Gitlab Actions and ArgoCD to Perform a GitOps Style Continuous Release Process

FastAPI Microservice to Digital Ocean Kubernetes

FastAPI and Docker

I created a FastAPI API Project. I created the Dockerfile and deployed it on localhost.

image image

References: https://fastapi.tiangolo.com/deployment/docker/

Commands:

docker build -t fastapi .

docker run -d --name fastapi_helloworld -p 80:80 fastapi

image image

I tested the API via curl tool to localhost to ensure my API was working.

curl -v http://localhost

image

Dockerhub Container Registry and Gitlab Action Pipeline

I went to DockerHub to create an authentication token. I added the token to the secrets section and wrote a Gitlab Action YAML file to automate the build and push of this image on every push to master branch. Under Gitlab Actions, I verified my Gitlab Action Pipeline was succeeding and that the images were pushed to Docker Container Registry.

image

image

image

Digital Ocean and K8s Setup

I installed the DO command line tool and created a K8s cluster via the UI. I added the credentials to the K8s cluster to my local machine.

I created a deployment as well as a Load Balancer Service to expose my API endpoint to the Ingress.

Typically I would use Traefik but this is out of scope.

brew install doctl

doctl version

image

image

kubectl apply -f ./k8s/fastapi-deployment.yaml

kubectl apply -f ./k8s/fastapi-svc.yaml

I replaced my test from localhost to the External IP created by DO Load Balancer Service.

curl -v http://165.227.250.126

image

image

ArgoCD GitOps Foundation and Install

I installed ArgoCD into DO K8s.

References: https://argo-cd.readthedocs.io/en/stable/getting_started/

kubectl create namespace argocd

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

kubectl apply -f ./k8s/argocd/argocd-svc.yaml -n argocd

I patched the argocd-server service to type Load Balancer to expose ArgoCD.

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

image

I navigated to the external IP and tested connectivity to argocd

image

I grabbed the credentials from k8s and confirmed successful setup up ArgoCD

image

ArgoCD GitOps CRD

I created an Argo CRD to point to my applications deployment yaml files:

image

I committed the Argo CRD yaml and navigated to the Argo UI to confirm:

image

ArgoCD GitOps CRD

I incremented the image version of the application and resynced ArgoCD via the UI

image

image

App:

http://165.227.250.126/docs