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.
References: https://fastapi.tiangolo.com/deployment/docker/
Commands:
docker build -t fastapi .
docker run -d --name fastapi_helloworld -p 80:80 fastapi
I tested the API via curl tool to localhost to ensure my API was working.
curl -v http://localhost
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.
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
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
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"}}'
I navigated to the external IP and tested connectivity to argocd
I grabbed the credentials from k8s and confirmed successful setup up ArgoCD
ArgoCD GitOps CRD
I created an Argo CRD to point to my applications deployment yaml files:
I committed the Argo CRD yaml and navigated to the Argo UI to confirm:
ArgoCD GitOps CRD
I incremented the image version of the application and resynced ArgoCD via the UI