Argo CD Autopilot

repository·main·Indexed 22 days ago

https://github.com/argoproj-labs/argocd-autopilot

An opinionated tool designed to simplify the installation and management of Argo CD using GitOps principles. It automates repository structuring, application promotion, and disaster recovery by managing Argo CD and its applications entirely through Git. Key features include bootstrapping Argo CD, managing projects to group applications, and creating Directory or Kustomize applications with automatic type inference.

Tokens
20.2K
Snippets
72
Records
87
Agent score
77%

What's inside argocd-autopilot

  1. How Argo CD Autopilot works

    main

    Argo CD Autopilot automates the lifecycle of Argo CD and your GitOps repository using an opinionated workflow:

    1. Bootstrap Phase: The bootstrap command deploys an Argo CD manifest to your target Kubernetes cluster and commits an Argo CD Application manifest to a specific directory in your GitOps repository. This creates a self-managing Argo CD installation.
    2. Post-Bootstrap Management: Once bootstrapped, the tool interacts primarily with your GitOps repository rather than the cluster directly.
    3. Application Lifecycle: Users create Projects and Applications via Autopilot. Autopilot commits the necessary manifests to Git, and Argo CD then synchronizes those changes to the cluster.

    Note on Connectivity: Autopilot communicates with the Kubernetes cluster directly only during the bootstrap phase. For all subsequent operations (like adding projects or applications), Autopilot requires access to the GitOps repository and the Argo CD server.

  2. Supported Git Providers in Argo CD Autopilot

    main

    Argo CD Autopilot can automate the installation and bootstrapping of Argo CD, including the creation and initialization of git repositories. To perform these tasks, Autopilot requires access to your git provider. The following providers are currently supported:

    • Github
    • Gitlab
    • Bitbucket Server (on-prem only)
    • Azure DevOps
    • Gitea
  3. Create a Kustomize application

    main

    A Kustomize application uses a base and overlay structure.

    • The apps/<APP_NAME>/base/kustomization.yaml file is created upon the first time the application is instantiated.
    • The apps/<APP_NAME>/overlays/<PROJECT_NAME>/ folder is created for every project the application is installed on.

    All overlays for the same application share the same base kustomization.yaml file.

    argocd-autopilot app create hello-world --app github.com/argoproj-labs/argocd-autopilot/examples/demo-app/ -p <PROJECT_NAME> --type kustomize
  4. Create a Directory application

    main

    A Directory application references a specific directory at a given repository URL, path, and revision. When created, its configuration is persisted in your GitOps Repository at apps/<APP_NAME>/<PROJECT_NAME>/config.json.

    argocd-autopilot app create dir-example --app github.com/argoproj-labs/argocd-autopilot/examples/demo-dir/ -p <PROJECT_NAME> --type dir
  5. How to modify your Argo-CD installation

    main

    Argo-CD Autopilot uses a GitOps approach for the bootstrap installation. The state of Argo-CD is managed by an argo-cd application (a Kustomize type application) deployed by the autopilot-bootstrap application.

    Crucial Rule: You cannot modify Argo-CD resources directly in the cluster. To make changes, you must use kustomize patches within your installation repository to modify the resources generated from bootstrap/argo-cd/kustomization.yaml.

  6. Understand the Application Specifier structure

    main

    An application specifier is a string used with the --app flag in the app create and repo bootstrap commands to define the entrypoint for an application.

    A standard specifier follows this format: [repository]?[ref]=[ref_value]

    It is composed of three parts:

    1. Repository: The URL of the git repository (e.g., github.com/argoproj/argo-workflows).
    2. Path: The directory path inside the repository containing the base kustomization.yaml (e.g., manifests/cluster-install).
    3. Git Ref: An optional query parameter ?ref= specifying a tag, branch, or commit SHA (e.g., ?ref=v3.0.7).

    Git Ref Resolution Logic: If a ref is not explicitly provided, argocd-autopilot resolves it using this priority:

    1. The HEAD of the main branch.
    2. A commit matching the provided SHA.
    3. A tag matching the provided name.
    4. A branch matching the provided name.
    argocd-autopilot app create workflows --app "github.com/argoproj/argo-workflows/manifests/cluster-install?ref=v3.0.7" --project prod
  7. Quickstart: Bootstrap Argo CD and Create Applications

    main

    To get started, you must provide your Git credentials and the repository URL via the GIT_TOKEN and GIT_REPO environment variables (or via the --git-token and --repo flags in each command).

    1. Bootstrap Argo CD

    Run the bootstrap command on your current Kubernetes context. This installs Argo CD and the ApplicationSet controller. If the repository specified in GIT_REPO does not exist, Autopilot will attempt to create a private repository.

    argocd-autopilot repo bootstrap

    2. Create a Project

    Create a new Argo CD project to organize your applications:

    argocd-autopilot project create my-project

    3. Create an Application

    Install an application into your project. You can point to a public Git repository and a specific path:

    argocd-autopilot app create demoapp --app github.com/argoproj-labs/argocd-autopilot/examples/demo-app/ -p my-project
    # Setup environment
    export GIT_TOKEN=<YOUR_TOKEN>
    export GIT_REPO=<REPO_URL>
    
    # Bootstrap
    argocd-autopilot repo bootstrap
    
    # Create project
    argocd-autopilot project create my-project
    
    # Create app
    argocd-autopilot app create demoapp --app github.com/argoproj-labs/argocd-autopilot/examples/demo-app/ -p my-project
  8. Apply static labels to an ArgoCD Project

    main

    When creating a new Project using argocd-autopilot, you can supply static labels via the --labels flag. These labels are added to the ApplicationSet template and will be applied exactly as provided to every Application generated by that Project.

    Use the format "key=value","key2=value2" to provide multiple labels.

    argocd-autopilot project create my-proj --labels "app.my.org/name=org-name","app.my.org/type=org-type"
  9. Create an application with argocd-autopilot

    main

    Use the argocd-autopilot app create command to install applications. You must provide an application name, an application specifier (the source repository URL), and a project name. If you do not specify the --type flag, argocd-autopilot will attempt to clone the source repository and use Argo CD's tool detection to automatically infer the application type.

    argocd-autopilot app create <APP_NAME> --app <APP_SPECIFIER> -p <PROJECT_NAME>
  10. Apply modified Argo-CD manifests from an existing repository

    main

    If you have made custom modifications to your Argo-CD manifests within your repository, you can instruct argocd-autopilot to use those specific manifests instead of generating new ones. Use the --app flag with an app specifier to point to the location of your Argo-CD manifests (e.g., the path to the kustomization.yaml).

    export GIT_REPO=https://github.com/owner/installation-repo
    export GIT_TOKEN=xxx
    
    argocd-autopilot repo bootstrap --recover --app "${GIT_REPO}.git/bootstrap/argo-cd"
  11. Run Argo CD Autopilot via Docker

    main

    When running the Argo CD Autopilot Docker image, you must mount your .kube and .gitconfig directories to ensure the container has the necessary credentials to interact with your Kubernetes cluster and Git repository.

    docker run \
      -v ~/.kube:/home/autopilot/.kube \
      -v ~/.gitconfig:/home/autopilot/.gitconfig \
      -it quay.io/argoprojlabs/argocd-autopilot <cmd> <flags>