Skip to main content

ApplicationSet tutorial

This topic walks you through creating a GitOps ApplicationSet in Harness.

Prerequisites

To set up an ApplicationSet, you'll need the following:

Step 1: Updating manifests in Git

The following example uses a Git generator and is in Argo project’s public repository.

  1. Clone the repo and update git-generator-files.yaml with the following YAML keys/values and then save the changes.

    apiVersion: argoproj.io/v1alpha1  
    kind: ApplicationSet
    metadata:
    name: guestbook
    spec:
    generators:
    - git:
    repoURL: https://github.com/<YOUR_ACCOUNT_NAME>/applicationset.git
    revision: HEAD
    files:
    - path: "examples/git-generator-files-discovery/cluster-config/**/config.json"
    template:
    metadata:
    name: '{{cluster.name}}-guestbook'
    labels:
    harness.io/envRef: '{{envTag}}'
    harness.io/serviceRef: '{{serviceTag}}'
    harness.io/buildRef: '{{releaseTag}}'
    spec:
    project: <PROJECT_ID_IN_AGENT_PAGE>
    source:
    repoURL: https://github.com/<your account name>/applicationset.git
    targetRevision: HEAD
    path: "examples/git-generator-files-discovery/apps/guestbook"
    destination:
    server: '{{cluster.address}}'
    namespace: default
    syncPolicy:
    automated: {}

    To get the project Id, go to GitOps Agents and find the Argo Project Id you want to use to create the ApplicationSet.

  2. Navigate to applicationset/examples/git-generator-files-discovery/cluster-config/engineering/dev/config.json.

  3. Replace "address": "https://1.2.3.4" with the Endpoint IP address for the dev target cluster. Ensure that you use the https:// scheme. Note that this cluster must be created beforehand.

  4. Repeat step 2 for the prod target cluster by modifying the file applicationset/examples/git-generator-files-discovery/cluster-config/engineering/prod/config.json

Here is an example:

note

Both JSON and YAML formats are supported for ApplicationSets.

Step 2: Creating the ApplicationSet app

  1. Similar to how you create a regular application in Harness GitOps, select Applications, and then select New Application.

  2. Enter a name, choose the agent, leave the default Sync Policy settings, and select Continue.

  3. In Source, enter the following settings and then select Continue.

    1. Repository URL: select the GitOps repository you added earlier.
    2. Target Revision: select master.
    3. Path: enter examples/git-generator-files-discovery.

  4. In Destination, select the cluster and namespace in which the GitOps agent is installed.

Step 3: Sync the ApplicationSet app

You can sync from 2 places: Application view or PR pipeline. For syncing via the PR pipeline, please refer to Sync GitOps applications.

From the Application view, you can sync the Harness ApplicationSet application or the individual Applications independently.

If you configure automatic syncing in the ApplicationSet template, then the applications are synced automatically. See syncPolicy.automated in the following example.

  template:  
metadata:
name: '{{cluster.name}}-guestbook'
spec:
project: 191b68fc
source:
repoURL: https://github.com/johndoe/applicationset.git
targetRevision: HEAD
path: "examples/git-generator-files-discovery/apps/guestbook"
destination:
server: '{{cluster.address}}'
namespace: default
syncPolicy:
automated: {}