github.com/argoproj/argo-cd/v3@v3.2.1/docs/operator-manual/high_availability.md (about) 1 # High Availability 2 3 Argo CD is largely stateless. All data is persisted as Kubernetes objects, which in turn is stored in Kubernetes' etcd. Redis is only used as a throw-away cache and can be lost. When lost, it will be rebuilt without loss of service. 4 5 A set of [HA manifests](https://github.com/argoproj/argo-cd/tree/stable/manifests/ha) are provided for users who wish to run Argo CD in a highly available manner. This runs more containers, and runs Redis in HA mode. 6 7 !!! note 8 9 The HA installation will require at least three different nodes due to pod anti-affinity roles in the 10 specs. Additionally, IPv6 only clusters are not supported. 11 12 ## Scaling Up 13 14 ### argocd-repo-server 15 16 **settings:** 17 18 The `argocd-repo-server` is responsible for cloning Git repository, keeping it up to date and generating manifests using the appropriate tool. 19 20 * `argocd-repo-server` fork/exec config management tool to generate manifests. The fork can fail due to lack of memory or limit on the number of OS threads. 21 The `--parallelismlimit` flag controls how many manifests generations are running concurrently and helps avoid OOM kills. 22 23 * the `argocd-repo-server` ensures that repository is in the clean state during the manifest generation using config management tools such as Kustomize, Helm 24 or custom plugin. As a result Git repositories with multiple applications might affect repository server performance. 25 Read [Monorepo Scaling Considerations](#monorepo-scaling-considerations) for more information. 26 27 * `argocd-repo-server` clones the repository into `/tmp` (or the path specified in the `TMPDIR` env variable). The Pod might run out of disk space if it has too many repositories 28 or if the repositories have a lot of files. To avoid this problem mount a persistent volume. 29 30 * `argocd-repo-server` uses `git ls-remote` to resolve ambiguous revisions such as `HEAD`, a branch or a tag name. This operation happens frequently 31 and might fail. To avoid failed syncs use the `ARGOCD_GIT_ATTEMPTS_COUNT` environment variable to retry failed requests. 32 33 * `argocd-repo-server` Every 3m (by default) Argo CD checks for changes to the app manifests. Argo CD assumes by default that manifests only change when the repo changes, so it caches the generated manifests (for 24h by default). With Kustomize remote bases, or in case a Helm chart gets changed without bumping its version number, the expected manifests can change even though the repo has not changed. By reducing the cache time, you can get the changes without waiting for 24h. Use `--repo-cache-expiration duration`, and we'd suggest in low volume environments you try `1h`. Bear in mind that this will negate the benefits of caching if set too low. 34 35 * `argocd-repo-server` executes config management tools such as `helm` or `kustomize` and enforces a 90 second timeout. This timeout can be changed by using the `ARGOCD_EXEC_TIMEOUT` env variable. The value should be in the Go time duration string format, for example, `2m30s`. 36 37 * `argocd-repo-server` will issue a `SIGTERM` signal to a command that has elapsed the `ARGOCD_EXEC_TIMEOUT`. In most cases, well-behaved commands will exit immediately when receiving the signal. However, if this does not happen, `argocd-repo-server` will wait an additional timeout of `ARGOCD_EXEC_FATAL_TIMEOUT` and then forcefully exit the command with a `SIGKILL` to prevent stalling. Note that a failure to exit with `SIGTERM` is usually a bug in either the offending command or in the way `argocd-repo-server` calls it and should be reported to the issue tracker for further investigation. 38 39 **metrics:** 40 41 * `argocd_git_request_total` - Number of git requests. This metric provides two tags: 42 - `repo` - Git repo URL 43 - `request_type` - `ls-remote` or `fetch`. 44 45 * `ARGOCD_ENABLE_GRPC_TIME_HISTOGRAM` - Is an environment variable that enables collecting RPC performance metrics. Enable it if you need to troubleshoot performance issues. Note: This metric is expensive to both query and store! 46 47 ### argocd-application-controller 48 49 **settings:** 50 51 The `argocd-application-controller` uses `argocd-repo-server` to get generated manifests and Kubernetes API server to get the actual cluster state. 52 53 * each controller replica uses two separate queues to process application reconciliation (milliseconds) and app syncing (seconds). The number of queue processors for each queue is controlled by 54 `--status-processors` (20 by default) and `--operation-processors` (10 by default) flags. Increase the number of processors if your Argo CD instance manages too many applications. 55 For 1000 application we use 50 for `--status-processors` and 25 for `--operation-processors` 56 57 * The manifest generation typically takes the most time during reconciliation. The duration of manifest generation is limited to make sure the controller refresh queue does not overflow. 58 The app reconciliation fails with `Context deadline exceeded` error if the manifest generation is taking too much time. As a workaround increase the value of `--repo-server-timeout-seconds` and 59 consider scaling up the `argocd-repo-server` deployment. 60 61 * The controller uses Kubernetes watch APIs to maintain a lightweight Kubernetes cluster cache. This allows avoiding querying Kubernetes during app reconciliation and significantly improves 62 performance. For performance reasons the controller monitors and caches only the preferred versions of a resource. During reconciliation, the controller might have to convert cached resources from the 63 preferred version into a version of the resource stored in Git. If `kubectl convert` fails because the conversion is not supported then the controller falls back to Kubernetes API query which slows down 64 reconciliation. In this case, we advise to use the preferred resource version in Git. 65 66 * The controller polls Git every 3m by default. You can change this duration using the `timeout.reconciliation` and `timeout.reconciliation.jitter` setting in the `argocd-cm` ConfigMap. The value of the fields is a [duration string](https://pkg.go.dev/time#ParseDuration) e.g `60s`, `1m` or `1h`. 67 68 * If the controller is managing too many clusters and uses too much memory then you can shard clusters across multiple 69 controller replicas. To enable sharding, increase the number of replicas in `argocd-application-controller` `StatefulSet` 70 and repeat the number of replicas in the `ARGOCD_CONTROLLER_REPLICAS` environment variable. The strategic merge patch below demonstrates changes required to configure two controller replicas. 71 72 * By default, the controller will update the cluster information every 10 seconds. If there is a problem with your cluster network environment that is causing the update time to take a long time, you can try modifying the environment variable `ARGO_CD_UPDATE_CLUSTER_INFO_TIMEOUT` to increase the timeout (the unit is seconds). 73 74 ```yaml 75 apiVersion: apps/v1 76 kind: StatefulSet 77 metadata: 78 name: argocd-application-controller 79 spec: 80 replicas: 2 81 template: 82 spec: 83 containers: 84 - name: argocd-application-controller 85 env: 86 - name: ARGOCD_CONTROLLER_REPLICAS 87 value: "2" 88 ``` 89 90 * In order to manually set the cluster's shard number, specify the optional `shard` property when creating a cluster. If not specified, it will be calculated on the fly by the application controller. 91 * The shard distribution algorithm of the `argocd-application-controller` can be set by using the `--sharding-method` parameter. Supported sharding methods are: 92 - `legacy` mode uses an `uid` based distribution (non-uniform). 93 - `round-robin` uses an equal distribution across all shards. 94 - `consistent-hashing` uses the consistent hashing with bounded loads algorithm which tends to equal distribution and also reduces cluster or application reshuffling in case of additions or removals of shards or clusters. 95 96 The `--sharding-method` parameter can also be overridden by setting the key `controller.sharding.algorithm` in the `argocd-cmd-params-cm` `configMap` (preferably) or by setting the `ARGOCD_CONTROLLER_SHARDING_ALGORITHM` environment variable and by specifying the same possible values. 97 98 !!! warning "Alpha Features" 99 The `round-robin` shard distribution algorithm is an experimental feature. Reshuffling is known to occur in certain scenarios with cluster removal. If the cluster at rank-0 is removed, reshuffling all clusters across shards will occur and may temporarily have negative performance impacts. 100 The `consistent-hashing` shard distribution algorithm is an experimental feature. Extensive benchmark have been documented on the [CNOE blog](https://cnoe.io/blog/argo-cd-application-scalability) with encouraging results. Community feedback is highly appreciated before moving this feature to a production ready state. 101 102 * A cluster can be manually assigned and forced to a `shard` by patching the `shard` field in the cluster secret to contain the shard number, e.g. 103 ```yaml 104 apiVersion: v1 105 kind: Secret 106 metadata: 107 name: mycluster-secret 108 labels: 109 argocd.argoproj.io/secret-type: cluster 110 type: Opaque 111 stringData: 112 shard: 1 113 name: mycluster.example.com 114 server: https://mycluster.example.com 115 config: | 116 { 117 "bearerToken": "<authentication token>", 118 "tlsClientConfig": { 119 "insecure": false, 120 "caData": "<base64 encoded certificate>" 121 } 122 } 123 ``` 124 125 * `ARGOCD_ENABLE_GRPC_TIME_HISTOGRAM` - environment variable that enables collecting RPC performance metrics. Enable it if you need to troubleshoot performance issues. Note: This metric is expensive to both query and store! 126 127 * `ARGOCD_CLUSTER_CACHE_LIST_PAGE_BUFFER_SIZE` - environment variable controlling the number of pages the controller 128 buffers in memory when performing a list operation against the K8s api server while syncing the cluster cache. This 129 is useful when the cluster contains a large number of resources and cluster sync times exceed the default etcd 130 compaction interval timeout. In this scenario, when attempting to sync the cluster cache, the application controller 131 may throw an error that the `continue parameter is too old to display a consistent list result`. Setting a higher 132 value for this environment variable configures the controller with a larger buffer in which to store pre-fetched 133 pages which are processed asynchronously, increasing the likelihood that all pages have been pulled before the etcd 134 compaction interval timeout expires. In the most extreme case, operators can set this value such that 135 `ARGOCD_CLUSTER_CACHE_LIST_PAGE_SIZE * ARGOCD_CLUSTER_CACHE_LIST_PAGE_BUFFER_SIZE` exceeds the largest resource 136 count (grouped by k8s api version, the granule of parallelism for list operations). In this case, all resources will 137 be buffered in memory -- no api server request will be blocked by processing. 138 139 * `ARGOCD_CLUSTER_CACHE_BATCH_EVENTS_PROCESSING` - environment variable that enables the controller to collect events 140 for Kubernetes resources and process them in a batch. This is useful when the cluster contains a large number of resources, 141 and the controller is overwhelmed by the number of events. The default value is `true`. `false` would mean that the controller 142 would process events one by one. 143 144 * `ARGOCD_CLUSTER_CACHE_EVENTS_PROCESSING_INTERVAL` - environment variable controlling the interval for processing events in a batch. 145 The valid value is in the format of Go time duration string, e.g. `1ms`, `1s`, `1m`, `1h`. The default value is `100ms`. 146 The variable is used only when `ARGOCD_CLUSTER_CACHE_BATCH_EVENTS_PROCESSING` is set to `true`. 147 148 * `ARGOCD_APPLICATION_TREE_SHARD_SIZE` - environment variable controlling the max number of resources stored in one Redis 149 key. Splitting application tree into multiple keys helps to reduce the amount of traffic between the controller and Redis. 150 The default value is 0, which means that the application tree is stored in a single Redis key. The reasonable value is 100. 151 152 **metrics** 153 154 * `argocd_app_reconcile` - reports application reconciliation duration in seconds. Can be used to build reconciliation duration heat map to get a high-level reconciliation performance picture. 155 * `argocd_app_k8s_request_total` - number of k8s requests per application. The number of fallback Kubernetes API queries - useful to identify which application has a resource with 156 non-preferred version and causes performance issues. 157 158 ### argocd-server 159 160 The `argocd-server` is stateless and probably the least likely to cause issues. To ensure there is no downtime during upgrades, consider increasing the number of replicas to `3` or more and repeat the number in the `ARGOCD_API_SERVER_REPLICAS` environment variable. The strategic merge patch below 161 demonstrates this. 162 163 ```yaml 164 apiVersion: apps/v1 165 kind: Deployment 166 metadata: 167 name: argocd-server 168 spec: 169 replicas: 3 170 template: 171 spec: 172 containers: 173 - name: argocd-server 174 env: 175 - name: ARGOCD_API_SERVER_REPLICAS 176 value: "3" 177 ``` 178 179 **settings:** 180 181 * The `ARGOCD_API_SERVER_REPLICAS` environment variable is used to divide [the limit of concurrent login requests (`ARGOCD_MAX_CONCURRENT_LOGIN_REQUESTS_COUNT`)](./user-management/index.md#failed-logins-rate-limiting) between each replica. 182 * The `ARGOCD_GRPC_MAX_SIZE_MB` environment variable allows specifying the max size of the server response message in megabytes. 183 The default value is 200. You might need to increase this for an Argo CD instance that manages 3000+ applications. 184 185 ### argocd-dex-server, argocd-redis 186 187 The `argocd-dex-server` uses an in-memory database, and two or more instances would have inconsistent data. `argocd-redis` is pre-configured with the understanding of only three total redis servers/sentinels. 188 189 ## Monorepo Scaling Considerations 190 191 Argo CD repo server maintains one repository clone locally and uses it for application manifest generation. If the manifest generation requires to change a file in the local repository clone then only one concurrent manifest generation per server instance is allowed. This limitation might significantly slowdown Argo CD if you have a mono repository with multiple applications (50+). 192 193 ### Enable Concurrent Processing 194 195 Argo CD determines if manifest generation might change local files in the local repository clone based on the config management tool and application settings. 196 If the manifest generation has no side effects then requests are processed in parallel without a performance penalty. The following are known cases that might cause slowness and their workarounds: 197 198 * **Multiple Helm based applications pointing to the same directory in one Git repository:** for historical reasons Argo CD used to generate Helm manifests sequentially. Starting v3.0, Argo CD performs a parallel generation of Helm manifests by default. 199 200 * **Multiple Custom plugin based applications:** avoid creating temporal files during manifest generation and create `.argocd-allow-concurrency` file in the app directory, or use the sidecar plugin option, which processes each application using a temporary copy of the repository. 201 202 * **Multiple Kustomize applications in same repository with [parameter overrides](../user-guide/parameters.md):** sorry, no workaround for now. 203 204 205 ### Manifest Paths Annotation 206 207 Argo CD aggressively caches generated manifests and uses the repository commit SHA as a cache key. A new commit to the Git repository invalidates the cache for all applications configured in the repository. 208 This can negatively affect repositories with multiple applications. You can use the `argocd.argoproj.io/manifest-generate-paths` Application CRD annotation to solve this problem and improve performance. 209 210 Note: The `argocd.argoproj.io/manifest-generate-paths` annotation is available for use with webhooks. Since Argo CD v2.11, this annotation can also be used **without configuring any webhooks**. Webhooks are not a pre-condition for this feature. You can rely on the annotation alone to optimize manifest generation for all applications. 211 212 The `argocd.argoproj.io/manifest-generate-paths` annotation contains a semicolon-separated list of paths within the Git repository that are used during manifest generation. It will use the paths specified in the annotation to compare the last cached revision to the latest commit. If no modified files match the paths specified in `argocd.argoproj.io/manifest-generate-paths`, then it will not trigger application reconciliation and the existing cache will be considered valid for the new commit. 213 214 Installations that use a different repository for each application are **not** subject to this behavior and will likely get no benefit from using these annotations. 215 216 Similarly, applications referencing an external Helm values file will not get the benefits of this feature when an unrelated change happens in the external source. 217 218 For webhooks, the comparison is done using the files specified in the webhook event payload instead. 219 220 !!! note 221 Application manifest paths annotation support for webhooks depends on the git provider used for the Application. It is currently only supported for GitHub, GitLab, and Gogs based repos. 222 223 * **Relative path** The annotation might contain a relative path. In this case the path is considered relative to the path specified in the application source: 224 225 ```yaml 226 apiVersion: argoproj.io/v1alpha1 227 kind: Application 228 metadata: 229 name: guestbook 230 namespace: argocd 231 annotations: 232 # resolves to the 'guestbook' directory 233 argocd.argoproj.io/manifest-generate-paths: . 234 spec: 235 source: 236 repoURL: https://github.com/argoproj/argocd-example-apps.git 237 targetRevision: HEAD 238 path: guestbook 239 # ... 240 ``` 241 242 * **Absolute path** The annotation value might be an absolute path starting with '/'. In this case path is considered as an absolute path within the Git repository: 243 244 ```yaml 245 apiVersion: argoproj.io/v1alpha1 246 kind: Application 247 metadata: 248 name: guestbook 249 annotations: 250 argocd.argoproj.io/manifest-generate-paths: /guestbook 251 spec: 252 source: 253 repoURL: https://github.com/argoproj/argocd-example-apps.git 254 targetRevision: HEAD 255 path: guestbook 256 # ... 257 ``` 258 259 * **Multiple paths** It is possible to put multiple paths into the annotation. Paths must be separated with a semicolon (`;`): 260 261 ```yaml 262 apiVersion: argoproj.io/v1alpha1 263 kind: Application 264 metadata: 265 name: guestbook 266 annotations: 267 # resolves to 'my-application' and 'shared' 268 argocd.argoproj.io/manifest-generate-paths: .;../shared 269 spec: 270 source: 271 repoURL: https://github.com/argoproj/argocd-example-apps.git 272 targetRevision: HEAD 273 path: my-application 274 # ... 275 ``` 276 277 * **Glob paths** The annotation might contain a glob pattern path, which can be any pattern supported by the [Go filepath Match function](https://pkg.go.dev/path/filepath#Match): 278 279 ```yaml 280 apiVersion: argoproj.io/v1alpha1 281 kind: Application 282 metadata: 283 name: guestbook 284 namespace: argocd 285 annotations: 286 # resolves to any file matching the pattern of *-secret.yaml in the top level shared folder 287 argocd.argoproj.io/manifest-generate-paths: "/shared/*-secret.yaml" 288 spec: 289 source: 290 repoURL: https://github.com/argoproj/argocd-example-apps.git 291 targetRevision: HEAD 292 path: guestbook 293 # ... 294 ``` 295 296 !!! note 297 If application manifest generation using the `argocd.argoproj.io/manifest-generate-paths` annotation feature is enabled, only the resources specified by this annotation will be sent to the CMP server for manifest generation, rather than the entire repository. To determine the appropriate resources, a common root path is calculated based on the paths provided in the annotation. The application path serves as the deepest path that can be selected as the root. 298 299 ### Application Sync Timeout & Jitter 300 301 Argo CD has a timeout for application syncs. It will trigger a refresh for each application periodically when the timeout expires. 302 With a large number of applications, this will cause a spike in the refresh queue and can cause a spike to the repo-server component. To avoid this, you can set a jitter to the sync timeout which will spread out the refreshes and give time to the repo-server to catch up. 303 304 The jitter is the maximum duration that can be added to the sync timeout, so if the sync timeout is 5 minutes and the jitter is 1 minute, then the actual timeout will be between 5 and 6 minutes. 305 306 To configure the jitter you can set the following environment variables: 307 308 * `ARGOCD_RECONCILIATION_JITTER` - The jitter to apply to the sync timeout. Disabled when value is 0. Defaults to 60. 309 310 ## Rate Limiting Application Reconciliations 311 312 To prevent high controller resource usage or sync loops caused either due to misbehaving apps or other environment specific factors, 313 we can configure rate limits on the workqueues used by the application controller. There are two types of rate limits that can be configured: 314 315 * Global rate limits 316 * Per item rate limits 317 318 The final rate limiter uses a combination of both and calculates the final backoff as `max(globalBackoff, perItemBackoff)`. 319 320 ### Global rate limits 321 322 This is disabled by default, it is a simple bucket based rate limiter that limits the number of items that can be queued per second. 323 This is useful to prevent a large number of apps from being queued at the same time. 324 325 To configure the bucket limiter you can set the following environment variables: 326 327 * `WORKQUEUE_BUCKET_SIZE` - The number of items that can be queued in a single burst. Defaults to 500. 328 * `WORKQUEUE_BUCKET_QPS` - The number of items that can be queued per second. Defaults to MaxFloat64, which disables the limiter. 329 330 ### Per item rate limits 331 332 This by default returns a fixed base delay/backoff value but can be configured to return exponential values. 333 Per item rate limiter limits the number of times a particular item can be queued. This is based on exponential backoff where the backoff time for an item keeps increasing exponentially 334 if it is queued multiple times in a short period, but the backoff is reset automatically if a configured `cool down` period has elapsed since the last time the item was queued. 335 336 To configure the per item limiter you can set the following environment variables: 337 338 * `WORKQUEUE_FAILURE_COOLDOWN_NS` : The cool down period in nanoseconds, once period has elapsed for an item the backoff is reset. Exponential backoff is disabled if set to 0(default), eg. values : 10 * 10^9 (=10s) 339 * `WORKQUEUE_BASE_DELAY_NS` : The base delay in nanoseconds, this is the initial backoff used in the exponential backoff formula. Defaults to 1000 (=1μs) 340 * `WORKQUEUE_MAX_DELAY_NS` : The max delay in nanoseconds, this is the max backoff limit. Defaults to 3 * 10^9 (=3s) 341 * `WORKQUEUE_BACKOFF_FACTOR` : The backoff factor, this is the factor by which the backoff is increased for each retry. Defaults to 1.5 342 343 The formula used to calculate the backoff time for an item, where `numRequeue` is the number of times the item has been queued 344 and `lastRequeueTime` is the time at which the item was last queued: 345 346 - When `WORKQUEUE_FAILURE_COOLDOWN_NS` != 0 : 347 348 ``` 349 backoff = time.Since(lastRequeueTime) >= WORKQUEUE_FAILURE_COOLDOWN_NS ? 350 WORKQUEUE_BASE_DELAY_NS : 351 min( 352 WORKQUEUE_MAX_DELAY_NS, 353 WORKQUEUE_BASE_DELAY_NS * WORKQUEUE_BACKOFF_FACTOR ^ (numRequeue) 354 ) 355 ``` 356 357 - When `WORKQUEUE_FAILURE_COOLDOWN_NS` = 0 : 358 359 ``` 360 backoff = WORKQUEUE_BASE_DELAY_NS 361 ``` 362 363 ## HTTP Request Retry Strategy 364 365 In scenarios where network instability or transient server errors occur, the retry strategy ensures the robustness of HTTP communication by automatically resending failed requests. It uses a combination of maximum retries and backoff intervals to prevent overwhelming the server or thrashing the network. 366 367 ### Configuring Retries 368 369 The retry logic can be fine-tuned with the following environment variables: 370 371 * `ARGOCD_K8SCLIENT_RETRY_MAX` - The maximum number of retries for each request. The request will be dropped after this count is reached. Defaults to 0 (no retries). 372 * `ARGOCD_K8SCLIENT_RETRY_BASE_BACKOFF` - The initial backoff delay on the first retry attempt in ms. Subsequent retries will double this backoff time up to a maximum threshold. Defaults to 100ms. 373 374 ### Backoff Strategy 375 376 The backoff strategy employed is a simple exponential backoff without jitter. The backoff time increases exponentially with each retry attempt until a maximum backoff duration is reached. 377 378 The formula for calculating the backoff time is: 379 380 ``` 381 backoff = min(retryWaitMax, baseRetryBackoff * (2 ^ retryAttempt)) 382 ``` 383 Where `retryAttempt` starts at 0 and increments by 1 for each subsequent retry. 384 385 ### Maximum Wait Time 386 387 There is a cap on the backoff time to prevent excessive wait times between retries. This cap is defined by: 388 389 * `retryWaitMax` - The maximum duration to wait before retrying. This ensures that retries happen within a reasonable timeframe. Defaults to 10 seconds. 390 391 ### Non-Retriable Conditions 392 393 Not all HTTP responses are eligible for retries. The following conditions will not trigger a retry: 394 395 * Responses with a status code indicating client errors (4xx) except for 429 Too Many Requests. 396 * Responses with the status code 501 Not Implemented. 397 398 399 ## CPU/Memory Profiling 400 401 Argo CD optionally exposes a profiling endpoint that can be used to profile the CPU and memory usage of the Argo CD 402 component. 403 The profiling endpoint is available on metrics port of each component. See [metrics](./metrics.md) for more information 404 about the port. 405 For security reasons, the profiling endpoint is disabled by default. The endpoint can be enabled by setting the 406 `server.profile.enabled`, `applicationsetcontroller.profile.enabled`, or `controller.profile.enabled` key 407 of [argocd-cmd-params-cm](argocd-cmd-params-cm.yaml) ConfigMap to `true`. 408 Once the endpoint is enabled, you can use go profile tool to collect the CPU and memory profiles. Example: 409 410 ```bash 411 $ kubectl port-forward svc/argocd-metrics 8082:8082 412 $ go tool pprof http://localhost:8082/debug/pprof/heap 413 ```