Nicolas's workshop

Argo CD

August 14, 2022

The following few steps can be taken as a quick start to Argo CD that can be done with a local cluster, say minikube.

Starting argocd non HA with cluster privilege

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

Displaying argocd initial admin secret

ENCODED=$(kubectl -n argocd get secret argocd-initial-admin-secret -o yaml | yq .data.password)
echo $ENCODED
echo $ENCODED | base64 --decode

Exposing argocd server with a port forward argocd server pod

kubectl port-forward svc/argocd-server -n argocd 8080:443

Open browser at https://localhost:8080

Using ArgoCD CLI

CLI allows to manage everything: applications, repos, clusters, tasks, projects...

argocd login localhost:8080
argocd cluster list

Applications

Given the following yaml content in a file called application.yml:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: guestbook
  namespace: argocd
spec: 
  destination:
    namespace: guestbook
    server: "https://kubernetes.default.svc"
  project: default
  source:
    path: guestbook
    repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
    targetRevision: master
  syncPolicy:
    syncOptions:
      - CreateNamespace=true

run the following commands:

kubectl apply -f application.yml

And then verify the application was created with:

kubectl get application -n argocd

Other app based on helm can be started the same way:

kubectl apply -f application_helm_options.yml

where application_helm_options.yml has a content like:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: helm-app
  namespace: argocd
spec: 
  destination:
    namespace: helm-app
    server: "https://kubernetes.default.svc"
  project: default
  source:
    path: helm-guestbook
    repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
    targetRevision: master
    helm:
      releaseName: my-release
  syncPolicy:
    syncOptions:
      - CreateNamespace=true

Finally, an application loaded recursively from a local directory can be started with:

kubectl apply -f application_subdirectories_options.yml

with a file application_subdirectories_options.yml with a content:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: directory-app
  namespace: argocd
spec: 
  destination:
    namespace: directory-app
    server: "https://kubernetes.default.svc"
  project: default
  source:
    path: guestbook-with-sub-directories
    repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
    targetRevision: master
    directory:
      recurse: true
  syncPolicy:
    syncOptions:
      - CreateNamespace=true

Here are ArgoCD options which can be adjusted with kustomize:

  • Name prefix: appended to resources
  • Name suffix: appended to resources
  • Images: to override images
  • Common labels: set labels on all resources
  • Common annotations: set annotations on all resources
  • Version: explicitly set kustomize version

The manifest below called for instance application_kustomize.yaml is an example of an kustomize argocd application. Two options are adjusted with kustomize: namePrefix and a commonLabel with a key of app and a value of demo.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: kustomize-app
  namespace: argocd
spec: 
  destination:
    namespace: kustomize-app
    server: "https://kubernetes.default.svc"
  project: default
  source:
    path: kustomize-guestbook
    repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
    targetRevision: master
    kustomize:
      namePrefix: staging-
      commonLabels:
        app: demo
  syncPolicy:
    syncOptions:
      - CreateNamespace=true

Application can be started with:

kubectl apply -f application_kustomize.yml

Note that Argo CD automatically detects that it is a Kustomize application.

Projects

Display info on by default project:

kubectl get appproject -n argocd -o yaml

Now a project can be created by running

kubectl apply -f ./project.yaml

with a file called project.yaml:

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: demo-project
  namespace: argocd
spec:
  description: Demo Project
  sourceRepos:
  - '*'

  destinations:
  - namespace: '*'
    server: '*'

  clusterResourceWhitelist:
  - group: '*'
    kind: '*'

  namespaceResourceWhitelist:
  - group: '*'
    kind: '*'

Display info on projects again with:

kubectl get appproject -n argocd -o yaml

An application can be defined to start in the project thus created with:

kubectl apply -f './application.yml'

with the following content for application.yml:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: guestbook-demo-project
  namespace: argocd
spec: 
  destination:
    namespace: guestbook-demo-project
    server: "https://kubernetes.default.svc"
  project: demo-project
  source:
    path: guestbook
    repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
    targetRevision: master
  syncPolicy:
    syncOptions:
      - CreateNamespace=true

Sync

Automated syncing can be enabled by declaring a syncPolicy in the manifest of the application. Or by adding a sync-policy automated flag to a cli argocd app create command. There is also a SYNC POLICY setting which can be set to Automatic in the Web UI.

Example of an application manifest:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: auto-sync-app
  namespace: argocd
spec: 
  destination:
    namespace: auto-sync-app
    server: "https://kubernetes.default.svc"
  project: default
  source:
    path: guestbook-with-sub-directories
    repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
    targetRevision: master
    directory:
      recurse: true
  syncPolicy:
    automated: {}
    syncOptions:
      - CreateNamespace=true
  • Additional features:

    • automated pruning
    • self healing
  • Sync Options with at the resource level with annotations or at the application level with syncOptions (in syncPolicy):

    • Prune = false
    • Validate = false
  • Selective syncing at the application level only with syncOptions: ApplyOutOfSyncOnly=true

  • Argo waves with PruneLast=true at application or resource level.

  • Replacing resources: by default Argo CD uses kubectl apply to deploy resources changes In some cases, you need to replace/recreate the resources. ArgoCD can do this by using replace=true. It can be done at application level with a Replace of true in syncOptions. It can be also done at resource level with an annotation like argocd.argoproj.io/sync-options: Replace=true

  • sync can be configured to fail if resource is found in other applications by using FailOnSharedResource=true

Previous: Git

Next: Maven