# Argo CD

[Argo CD](https://argoproj.github.io/cd/) is a declarative, GitOps continuous delivery tool for Kubernetes. Argo CD aligns with the GitOps principles, ensuring that the deployment of groundcover is always in sync with the predefined configurations in your Git repository. This means that any changes made to the deployment configurations are automatically applied to the cluster, streamlining updates and ensuring that all instances of groundcover are consistent across different environments.

Argo CD’s multi-environment support ensures that groundcover can be deployed consistently across various Kubernetes clusters, whether they are designated for development, testing, or production.

To deploy groundcover through Argo CD, use the following steps.

{% hint style="info" %}
The steps below require a user with admin permissions
{% endhint %}

## Create the groundcover namespace

groundcover requires setting up secrets in the installation namespace prior to creating the ArgoCD application. For that reason we will start by creating the groundcover namespace:

```sh
kubectl create namespace groundcover
```

## Create the Ingestion Key Secret

#### Step 1 - Fetch the Ingestion key

{% hint style="info" %}
Read more about ingestion keys here:[ingestion-keys](https://docs.groundcover.com/use-groundcover/remote-access-and-apis/ingestion-keys "mention")
{% endhint %}

1. Open the [Ingestion Keys](https://app.groundcover.com/settings?selectedTab=ingestion-keys) page
2. Create an `Ingestion Key` of type `Sensor`
3. Copy the value of the key created

#### Step 2 - Create the spec file

Create the spec file for the secret in the `groundcover` namespace using the following snippet:

{% hint style="info" %}
Make sure to replace the `<ingestion-key>` value below with the value fetched in the previous step
{% endhint %}

```sh
cat << EOF > groundcover_ingestionkey_secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: groundcover-ingestion-key
  namespace: groundcover
stringData:
  INGESTION_KEY: <ingestion-key>
type: Opaque
EOF
```

#### Step 3 - Create the secret

Apply the spec file from above:

```sh
kubectl apply -f groundcover_ingestionkey_secret.yaml
```

## Create the Argo CD Application Manifest

{% hint style="info" %}
Make sure to set the following values in the manifest:

* \<project-name> - to match your environment
* \<targetRevision> - set the deployment version. EIther a specific groundcover chart version, or use `">= 1.0.0"` for auto upgrades.\
  You can use the following commands to fetch the latest chart version:
  * `helm repo update`
  * `helm search repo groundcover/groundcover`
    {% endhint %}

{% hint style="info" %}
The `<cluster-name>` value in the `values` part in the manifest can be any name you wish to assign to the cluster where the platform is installed. In multi-cluster installations, make sure to change it according to the cluster being installed.
{% endhint %}

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: groundcover
  namespace: argocd
spec:
  project: <project-name>
  source:
    chart: groundcover
    repoURL: https://helm.groundcover.com
    targetRevision: <groundcover-version>
    helm:
      releaseName: groundcover
      values: |
        clusterId: <cluster-name>
        ingress:
          site: <endpoint>
        global:
          backend:
            enabled: false
          groundcoverPredefinedTokenSecret:
            secretKey: INGESTION_KEY
            secretName: groundcover-ingestion-key
  destination:
    server: "https://kubernetes.default.svc"
    namespace: groundcover
  # avoid OutOfSync state on generated secrets with random data,
  # but keep api-key and groundcover-config managed by Argo CD.
  # https://argo-cd.readthedocs.io/en/stable/user-guide/helm/#random-data
  syncPolicy:
    syncOptions:
    - CreateNamespace=true
    - RespectIgnoreDifferences=true
  ignoreDifferences:
  - kind: Secret
    namespace: groundcover
    jqPathExpressions:
    - 'select(.metadata.name != "api-key" and .metadata.name != "groundcover-config") | .data'
    - 'select(.metadata.name != "api-key" and .metadata.name != "groundcover-config") | .stringData'
  - group: apps
    kind: '*'
    jsonPointers:
    - /spec/template/metadata/annotations/checksum~1secret
  - group: admissionregistration.k8s.io
    kind: ValidatingWebhookConfiguration
    jqPathExpressions:
    - '.webhooks[]?.clientConfig.caBundle'
```

The `ignoreDifferences` section above ignores drift on generated secret data while keeping the `api-key` and `groundcover-config` secrets fully managed by Argo CD.

## Inspect the groundcover namespace

After creating the manifest above the groundcover deployments will start spinning up in the namespace. When all pods are running you will start seeing data in the platform.

{% hint style="success" %}
If you encounter any issues in the installation [let us know over Slack.](https://www.groundcover.com/join-slack)
{% endhint %}
