This guide will help you set up and run a Python app locally, and explain how continuous delivery for staging or production is achieved with the help of ArgoCD.
Before you start, make sure the following tools are installed on your MacOS:
- Docker Desktop with Kubernetes: Download and install from Docker Official Website.
- Kind: Install using Homebrew with
brew install kind
. - Kustomize: Install using Homebrew with
brew install kustomize
.
Follow these steps to run the app locally:
- Create a new cluster using kind with
kind create cluster --name local-app
. - Switch to the newly created cluster with
kubectl config use-context kind-local-app
. - Create a new namespace for the app using
kubectl create namespace python-app-develop
. - Clone the Kustomize repository using
git clone https://github.com/Agotfrid/kustomize-example
. - Navigate to the base of
kustomize-example
and apply the manifests to the new namespace usingkubectl apply -k overlays/develop -n python-app-develop
. This command will set up all the required Kubernetes resources including the app, a small MySQL server, required services, secret, ConfigMap, and PVC and PV for database usage. - Forward the port of the app service using
kubectl port-forward -n python-app-develop svc/python-app-service 5000:80
so that you can use the API onlocalhost:5000
. - The API should now be usable!
This section explains how continuous delivery is set up for this project:
- Once a GitHub Actions task successfully completes the build, tag, and push the Docker image to
agotfrid/python-app
(or any other artifact registry etc.), the next task updates thekustomization.yaml
file in theoverlays
directory of the Kustomize repo with the new image version for the Python app. The tag used can be eitherlatest
or the commit hash of that particular release. - In a staging or production environment, we would have ArgoCD installed in the
argocd
namespace. This namespace includes an argo project and application that monitors the Kustomize repository for any changes. Onc a change is detected (such as an updated image tag), ArgoCD syncs these changes with the cluster, deploying the updated application.