GitOps with Helm and Argo CD
The Declarative Way of Managing Argo CD Applications
The commands we have explored so far are useful, but they are imperative. In a world of "everything-as-code," it's often better to use the declarative way of doing things.
# Example of an imperative command to create an application
argocd app create flask-app \
--repo https://github.com/$GITHUB_USERNAME/argocd-helm-example-bis/ \
--path flask-app \
--dest-server https://kubernetes.default.svc \
--dest-namespace flask-app \
--revision main \
--sync-policy automated \
--self-heal \
--auto-prune \
--allow-empty
If you run this command, you will create an Application resource in Argo CD. However, if you run it twice, you'll get an error because the Application already exists. This is not ideal for automation and version control. In the imperative approach, you instruct the system to perform actions step by step to arrive at the desired state. To update this state, you need to run more imperative commands and keep track of what has been done to avoid conflicts.
Using the declarative approach means that we can define the application in a representative YAML
manifest file that describes the desired state instead of imperatively instructing the system to perform actions. In the declarative approach, the system (Argo CD in this case) is responsible for ensuring that the actual state matches the desired state defined in the manifest. If there are discrepancies, Argo CD will automatically reconcile them. This is the same approach at the core of Kubernetes and Helm. The goal of this section is to translate the previous imperative command into a declarative manifest.
Let's start by deleting the existing application using the CLI:
argocd app delete $APPNAME -y
Then, let's recreate it using this YAML:
kubectl apply -f - <
---
# Use Argo CD's API version
apiVersion: argoproj.io/v1alpha1
# Use the Application CRD to define the desired state of the application
kind: Application
metadata:
name: flask-app
namespace: argocd
spec Helm in Practice
Designing, Deploying, and Operating Kubernetes Applications at ScaleEnroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
