2018-12-06 01:48:19 +00:00
# Declarative Setup
2019-02-02 09:42:48 +00:00
Argo CD applications, projects and settings can be defined declaratively using Kubernetes manifests.
2019-02-25 23:25:57 +00:00
## Quick Reference
| Name | Kind | Description |
|------|------|-------------|
| [`argocd-cm.yaml` ](argocd-cm.yaml ) | ConfigMap | General Argo CD configuration |
| [`argocd-secret.yaml` ](argocd-secret.yaml ) | Secret | Password, Certificates, Signing Key |
| [`argocd-rbac-cm.yaml` ](argocd-rbac-cm.yaml ) | ConfigMap | RBAC Configuration |
| [`application.yaml` ](application.yaml ) | Application | Example application spec |
2019-03-12 17:38:22 +00:00
| [`project.yaml` ](project.yaml ) | AppProject | Example project spec |
2019-02-25 23:25:57 +00:00
2019-02-02 09:42:48 +00:00
## Applications
The Application CRD is the Kubernetes resource object representing a deployed application instance
in an environment. It is defined by two key pieces of information:
2019-04-05 22:12:27 +00:00
* `source` reference to the desired state in Git (repository, revision, path, environment)
2019-02-02 09:42:48 +00:00
* `destination` reference to the target cluster and namespace.
2019-02-25 23:25:57 +00:00
A minimal Application spec is as follows:
2019-02-02 09:42:48 +00:00
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
2019-06-17 17:54:49 +00:00
namespace: argocd
2019-02-02 09:42:48 +00:00
spec:
project: default
source:
repoURL: https://github.com/argoproj/argocd-example-apps.git
targetRevision: HEAD
path: guestbook
destination:
server: https://kubernetes.default.svc
namespace: guestbook
```
2019-02-25 23:25:57 +00:00
See [application.yaml ](application.yaml ) for additional fields
2019-04-12 18:52:37 +00:00
!!! warning
By default, deleting an application will not perform a cascade delete, thereby deleting its resources. You must add the finalizer if you want this behaviour - which you may well not want.
```yaml
metadata:
finalizers:
- resources-finalizer.argocd.argoproj.io
```
2019-04-29 18:35:57 +00:00
### Application of Applications
2019-04-12 18:52:37 +00:00
You can create an application that creates other applications, which in turn can create other applications.
2019-04-29 18:35:57 +00:00
This allows you to declaratively manage a group of applications that can be deployed and configured in concert.
See [cluster bootstrapping ](cluster-bootstrapping.md ).
2019-04-12 18:52:37 +00:00
2019-02-02 09:42:48 +00:00
## Projects
The AppProject CRD is the Kubernetes resource object representing a logical grouping of applications.
It is defined by the following key pieces of information:
2019-04-05 22:12:27 +00:00
2019-02-02 09:42:48 +00:00
* `sourceRepos` reference to the repositories that applications within the project can pull manifests from.
* `destinations` reference to clusters and namespaces that applications within the project can deploy into.
* `roles` list of entities with definitions of their access to resources within the project.
An example spec is as follows:
```yaml
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: my-project
2019-06-17 17:54:49 +00:00
namespace: argocd
2019-02-02 09:42:48 +00:00
spec:
description: Example Project
2019-04-05 22:12:27 +00:00
# Allow manifests to deploy from any Git repos
2019-02-02 09:42:48 +00:00
sourceRepos:
- '*'
# Only permit applications to deploy to the guestbook namespace in the same cluster
destinations:
- namespace: guestbook
server: https://kubernetes.default.svc
# Deny all cluster-scoped resources from being created, except for Namespace
clusterResourceWhitelist:
- group: ''
kind: Namespace
# Allow all namespaced-scoped resources to be created, except for ResourceQuota, LimitRange, NetworkPolicy
2019-04-01 16:17:09 +00:00
namespaceResourceBlacklist:
2019-02-02 09:42:48 +00:00
- group: ''
kind: ResourceQuota
- group: ''
kind: LimitRange
- group: ''
kind: NetworkPolicy
roles:
# A role which provides read-only access to all applications in the project
- name: read-only
description: Read-only privileges to my-project
policies:
- p, proj:my-project:read-only, applications, get, my-project/*, allow
groups:
- my-oidc-group
# A role which provides sync privileges to only the guestbook-dev application, e.g. to provide
# sync privileges to a CI system
- name: ci-role
description: Sync privileges for guestbook-dev
policies:
- p, proj:my-project:ci-role, applications, sync, my-project/guestbook-dev, allow
# NOTE: JWT tokens can only be generated by the API server and the token is not persisted
# anywhere by Argo CD. It can be prematurely revoked by removing the entry from this list.
jwtTokens:
- iat: 1535390316
```
2018-12-06 01:48:19 +00:00
## Repositories
Repository credentials are stored in secret. Use following steps to configure a repo:
1. Create secret which contains repository credentials. Consider using [bitnami-labs/sealed-secrets ](https://github.com/bitnami-labs/sealed-secrets ) to store encrypted secret
definition as a Kubernetes manifest.
2019-03-29 15:13:32 +00:00
2. Register repository in the `argocd-cm` config map. Each repository must have `url` field and, depending on whether you connect using HTTPS or SSH, `usernameSecret` and `passwordSecret` (for HTTPS) or `sshPrivateKeySecret` (for SSH).
2018-12-06 01:48:19 +00:00
2019-03-29 15:13:32 +00:00
Example for HTTPS:
2018-12-06 01:48:19 +00:00
```yaml
apiVersion: v1
2019-02-25 23:25:57 +00:00
kind: ConfigMap
metadata:
name: argocd-cm
2019-06-17 17:54:49 +00:00
namespace: argocd
2018-12-06 01:48:19 +00:00
data:
repositories: |
2019-02-25 23:25:57 +00:00
- url: https://github.com/argoproj/my-private-repository
passwordSecret:
2018-12-06 01:48:19 +00:00
name: my-secret
2019-02-25 23:25:57 +00:00
key: password
2018-12-06 01:48:19 +00:00
usernameSecret:
2019-02-25 23:25:57 +00:00
name: my-secret
2018-12-06 01:48:19 +00:00
key: username
2019-03-29 15:13:32 +00:00
```
Example for SSH:
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
2019-06-17 17:54:49 +00:00
namespace: argocd
2019-03-29 15:13:32 +00:00
data:
repositories: |
- url: git@github.com:argoproj/my-private-repository
2019-02-25 23:25:57 +00:00
sshPrivateKeySecret:
2018-12-06 01:48:19 +00:00
name: my-secret
2019-02-25 23:25:57 +00:00
key: sshPrivateKey
2018-12-06 01:48:19 +00:00
```
2019-04-25 22:22:49 +00:00
!!! tip
The Kubernetes documentation has [instructions for creating a secret containing a private key ](https://kubernetes.io/docs/concepts/configuration/secret/#use-case-pod-with-ssh-keys ).
### Repository Credentials (v1.1+)
If you want to use the same credentials for multiple repositories, you can use `repository.credentials` :
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
2019-06-17 17:54:49 +00:00
namespace: argocd
2019-04-25 22:22:49 +00:00
data:
repositories: |
- url: https://github.com/argoproj/private-repo
- url: https://github.com/argoproj/other-private-repo
repository.credentials: |
- url: https://github.com/argoproj
passwordSecret:
name: my-secret
key: password
usernameSecret:
name: my-secret
key: username
```
Argo CD will only use the credentials if you omit `usernameSecret` , `passwordSecret` , and `sshPrivateKeySecret` fields (`insecureIgnoreHostKey` is ignored).
A credential may be match if it's URL is the prefix of the repository's URL. The means that credentials may match, e.g in the above example both [https://github.com/argoproj ](https://github.com/argoproj ) and [https://github.com ](https://github.com ) would match. Argo CD selects the first one that matches.
!!! tip
Order your credentials with the most specific at the top and the least specific at the bottom.
A complete example.
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
2019-06-17 17:54:49 +00:00
namespace: argocd
2019-04-25 22:22:49 +00:00
data:
repositories: |
# this has it's own credentials
- url: https://github.com/argoproj/private-repo
passwordSecret:
name: private-repo-secret
key: password
usernameSecret:
name: private-repo-secret
key: username
sshPrivateKeySecret:
name: private-repo-secret
key: sshPrivateKey
- url: https://github.com/argoproj/other-private-repo
- url: https://github.com/otherproj/another-private-repo
repository.credentials: |
# this will be used for the second repo
- url: https://github.com/argoproj
passwordSecret:
name: other-private-repo-secret
key: password
usernameSecret:
name: other-private-repo-secret
key: username
sshPrivateKeySecret:
name: other-private-repo-secret
key: sshPrivateKey
# this will be used for the third repo
- url: https://github.com
passwordSecret:
name: another-private-repo-secret
key: password
usernameSecret:
name: another-private-repo-secret
key: username
sshPrivateKeySecret:
name: another-private-repo-secret
key: sshPrivateKey
```
2018-12-06 01:48:19 +00:00
## Clusters
Cluster credentials are stored in secrets same as repository credentials but does not require entry in `argocd-cm` config map. Each secret must have label
2019-03-30 05:09:36 +00:00
`argocd.argoproj.io/secret-type: cluster` .
2018-12-06 01:48:19 +00:00
The secret data must include following fields:
2019-04-05 22:12:27 +00:00
2018-12-06 01:48:19 +00:00
* `name` - cluster name
* `server` - cluster api server url
* `config` - JSON representation of following data structure:
```yaml
# Basic authentication settings
username: string
password: string
# Bearer authentication settings
bearerToken: string
# IAM authentication configuration
awsAuthConfig:
clusterName: string
roleARN: string
# Transport layer security configuration settings
tlsClientConfig:
# PEM-encoded bytes (typically read from a client certificate file).
caData: string
# PEM-encoded bytes (typically read from a client certificate file).
certData: string
# Server should be accessed without verifying the TLS certificate
insecure: boolean
# PEM-encoded bytes (typically read from a client certificate key file).
keyData: string
# ServerName is passed to the server for SNI and is used in the client to check server
# ceritificates against. If ServerName is empty, the hostname used to contact the
# server is used.
serverName: string
```
Cluster secret example:
```yaml
apiVersion: v1
kind: Secret
metadata:
2019-03-30 05:09:36 +00:00
name: mycluster-secret
2018-12-06 01:48:19 +00:00
labels:
argocd.argoproj.io/secret-type: cluster
type: Opaque
2019-02-02 09:42:48 +00:00
stringData:
name: mycluster.com
server: https://mycluster.com
config: |
{
"bearerToken": "< authentication token > ",
"tlsClientConfig": {
"insecure": false,
"caData": "< base64 encoded certificate > "
}
}
2018-12-06 01:48:19 +00:00
```
2019-04-05 22:12:27 +00:00
## Helm Chart Repositories
2018-12-06 01:48:19 +00:00
2019-02-02 09:42:48 +00:00
Non standard Helm Chart repositories have to be registered under the `helm.repositories` key in the
`argocd-cm` ConfigMap. Each repository must have `url` and `name` fields. For private Helm repos you
may need to configure access credentials and HTTPS settings using `usernameSecret` , `passwordSecret` ,
`caSecret` , `certSecret` and `keySecret` fields.
2018-12-06 01:48:19 +00:00
Example:
```yaml
apiVersion: v1
2019-02-02 09:42:48 +00:00
kind: ConfigMap
metadata:
name: argocd-cm
2019-06-17 17:54:49 +00:00
namespace: argocd
2018-12-06 01:48:19 +00:00
data:
helm.repositories: |
2018-12-28 05:05:59 +00:00
- url: https://storage.googleapis.com/istio-prerelease/daily-build/master-latest-daily/charts
name: istio.io
2018-12-06 01:48:19 +00:00
- url: https://argoproj.github.io/argo-helm
name: argo
2019-02-25 23:25:57 +00:00
usernameSecret:
2018-12-06 01:48:19 +00:00
name: my-secret
key: username
2019-02-25 23:25:57 +00:00
passwordSecret:
2018-12-06 01:48:19 +00:00
name: my-secret
key: password
caSecret:
name: my-secret
key: ca
certSecret:
name: my-secret
key: cert
keySecret:
name: my-secret
key: key
```
2019-02-21 16:30:13 +00:00
## Resource Exclusion
Resources can be excluded from discovery and sync so that ArgoCD is unaware of them. For example, `events.k8s.io` and `metrics.k8s.io` are always excluded. Use cases:
* You have temporal issues and you want to exclude problematic resources.
* There are many of a kind of resources that impacts ArgoCD's performance.
* Restrict ArgoCD's access to certain kinds of resources, e.g. secrets. See [security.md#cluster-rbac ](security.md#cluster-rbac ).
To configure this, edit the `argcd-cm` config map:
```
kubectl edit configmap argocd-cm -n argocdconfigmap/argocd-cm edited
```
2019-02-28 00:44:17 +00:00
Add `resource.exclusions` , e.g.:
2019-02-21 16:30:13 +00:00
```yaml
apiVersion: v1
data:
2019-02-28 00:44:17 +00:00
resource.exclusions: |
2019-02-21 16:30:13 +00:00
- apiGroups:
- "*"
kinds:
- "*"
clusters:
- https://192.168.0.20
kind: ConfigMap
```
2019-02-28 00:44:17 +00:00
The `resource.exclusions` node is a list of objects. Each object can have:
2019-02-21 16:30:13 +00:00
- `apiGroups` A list of globs to match the API group.
- `kinds` A list of kinds to match. Can be "*" to match all.
- `cluster` A list of globs to match the cluster.
If all three match, then the resource is ignored.
Notes:
* Quote globs in your YAML to avoid parsing errors.
* Invalid globs result in the whole rule being ignored.
* If you add a rule that matches existing resources, these will appear in the interface as `OutOfSync` .
2018-12-06 01:48:19 +00:00
## SSO & RBAC
* SSO configuration details: [SSO ](sso.md )
* RBAC configuration details: [RBAC ](rbac.md )
2019-04-05 22:12:27 +00:00
## Manage Argo CD Using Argo CD
2018-12-06 01:48:19 +00:00
Argo CD is able to manage itself since all settings are represented by Kubernetes manifests. The suggested way is to create [Kustomize ](https://github.com/kubernetes-sigs/kustomize )
2019-04-05 22:12:27 +00:00
based application which uses base Argo CD manifests from [https://github.com/argoproj/argo-cd] and apply required changes on top.
2018-12-06 01:48:19 +00:00
Example of `kustomization.yaml` :
```yaml
bases:
2019-06-05 16:13:31 +00:00
- github.com/argoproj/argo-cd//manifests/cluster-install?ref=v1.0.1
2018-12-06 01:48:19 +00:00
# additional resources like ingress rules, cluster and repository secrets.
resources:
- clusters-secrets.yaml
- repos-secrets.yaml
# changes to config maps
patchesStrategicMerge:
- overlays/argo-cd-cm.yaml
```
The live example of self managed Argo CD config is available at https://cd.apps.argoproj.io and with configuration
stored at [argoproj/argoproj-deployments ](https://github.com/argoproj/argoproj-deployments/tree/master/argocd ).
2019-04-05 22:12:27 +00:00
!!! note
You will need to sign-in using your github account to get access to https://cd.apps.argoproj.io