GitOps: Example of a GitOps workflow using Argo CD
Argo CD: Deploying an Application
We will use the eon01/argocd-examples GitHub repository to deploy a basic Flask application on our Kubernetes cluster using Argo CD. It includes examples of applications deployable with Argo CD, each stored in a distinct folder. You can fork it or use it directly.
To begin, let's create a namespace for our application:
kubectl create namespace flask-app
We can now deploy the application manifest using the following command:
argocd app create flask-app \
--repo https://github.com/eon01/argocd-examples/ \
--path flask-app \
--dest-server https://kubernetes.default.svc \
--dest-namespace flask-app \
--revision main \
--sync-policy automated
The above command will create an Application named flask-app using the manifest stored in the flask-app folder of the GitHub repository.
Application is the name of the CRD that Argo CD uses to represent a deployable unit. It's not to be confused with a regular application, but it's a kind of wrapper around your application (represented by an image) and the way we deploy it (represented by Kubernetes manifests, Helm charts, Kustomize, etc.).
The app will be deployed in the flask-app namespace of the Kubernetes cluster. The main branch is used. We are using the --sync-policy automated flag to enable automated synchronization.
The automated synchronization will continuously ensure that the Kubernetes cluster reflects the desired application state defined in the Git repository. If the actual state of the application differs from the desired state, the application will be automatically synchronized. The synchronization is performed every 3 minutes by default. This can be customized.
The "flask-app" folder contains a kubernetes.yaml file that defines the Deployment and Service resources required to deploy the application.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-app
spec:
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app: flask-app
template:
metadata:
labels:
app: flask-app
spec:
containers:
- image: eon01/stateless-flask:v0
name: flask-app
ports:
- containerPort:Cloud-Native Microservices With Kubernetes - 2nd Edition
A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in KubernetesEnroll now to unlock all content and receive all future updates for free.
