Troubleshooting Argo CD
local graph
Chapter 7 — Troubleshooting Argo CD
Section titled “Chapter 7 — Troubleshooting Argo CD”In this chapter, we will see how to address some of the issues you are most likely to run into during your day-to-day work with Argo CD. We will go through the installation procedure and see what can happen if we try to have more than one installation in the same cluster. This is a valid scenario for organizations that have many clusters deployed in development (dev) and production (prod) and need to split the load to different Argo CD instances. Then, we will discover how to use a specific version of Helm, different than the one embedded in the Docker image. Sometimes, this is needed because a newer version of a templating engine can bring some breaking changes and you would need more time to prepare for the upgrade, but you still want to have the performance improvements of the new Argo CD version. Argo CD has become much more stable in recent years—it is a mature application used by many organizations in production, but there are still cases when a good old restart is needed, so we will see how to perform this correctly. We will finish the chapter with some explanations around performance, and go through and explain in detail those configuration parameters and environment variables that can make a difference to overall performance.
In this chapter, we’re going to cover the following main topics:
- Initial setup
- Addressing day-to-day issues
- Improving performance
Technical requirements
Section titled “Technical requirements”For this chapter, we will start with a new installation of Argo CD (actually, more than one), but it will not be in the argocd namespace, so it will be a fresh and different start.
We are going to write quite a lot of YAML Ain’t Markup Language (YAML), so a code editor will be needed, and as usual, I’ll go with Visual Studio Code (VS Code) (https://code.visualstudio.com). All the changes we will make can be found at the book’s companion GitHub repository in the ch07 folder.
Initial setup
Section titled “Initial setup”Almost all of the tutorials, blogs, and articles out there discuss installing Argo CD in the argocd namespace, and it does make sense as it is a specific namespace—it will not collide with other applications. But there are cases when that might not be possible—I am talking about when multiple instances of Argo CD are installed in the same Kubernetes cluster. This is a valid scenario when we want to split clusters that an Argo CD instance is managing, such as one that takes care of prod clusters and another the non-prod ones. Another scenario could be when they take care of the same clusters but only specific namespaces from it, so a model of an Argo CD instance per team. We will follow the scenario with prod and non-prod installations.
When we have two or more Argo CD installations in the same cluster, there are a couple of things we need to pay attention to. First is the fact that when we install it in the cluster, there are some Custom Resource Definitions (CRDs) (https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) being applied to allow us to create Applications and AppProjects resources. These definitions should be created only once, so only one Argo CD instance should apply them. So, we need to decide which of the two instances—prod or non-prod—will take care of the cluster where we actually installed them (as the CRDs will be installed on that cluster).
Usually, the job of site reliability engineers (SREs) is to create a self-service platform for developers in order to deploy their work to production, so most likely we will need to run more applications, not just Argo CD. We might need Prometheus Operator (https://prometheus-operator.dev), maybe ChartMuseum (https://chartmuseum.com) for storing Helm charts, or something like Harbor (https://goharbor.io) if we want to host our own container registry, or even host our own continuous integration/continuous deployment (CI/CD) system such as Tekton (https://tekton.dev). We will run all these applications in the same cluster, and we usually name it the Platform cluster. In order to deploy all these, we can have a third Argo CD instance that will take care of everything we want to set up in this Platform cluster, including applying the Argo CD CRDs. You can see what a setup involving three Argo CD instances in the same cluster would look like in the following diagram—a prod instance that takes care of all our production clusters, a non-prod instance that takes care of our dev, test, and staging clusters (this will be our test instance where we will verify the upgrades and any other configuration changes), and—finally—a Platform instance that takes care of the Platform cluster (including the installation of prod and non-prod instances):

Figure 7.1 – Multiple Argo CD instances on the same cluster
First, let’s deploy the Argo CD Platform instance, which is a complete installation, including the CRDs, and we will use Kustomize to deploy it. We can install it in an imperative way by first running kubectl apply to create a namespace and then using kustomize build to apply the remote resources from the Argo CD GitHub repository. But it is better to use a declarative approach because we can also enable the self-management part, which means the resources for all three installations should be stored in a Git repository (or more than one) to be able to update them via pull requests (PRs).
There are two options here—have all the installation manifests in the same repository on different branches named platform, prod, non-prod, or store all of them in separate folders in the same branch. When working with different branches, you will always need to pay attention to which one you open the PRs to as they go to the default branch, so mistakes could happen. That’s why it’s maybe easier to go with one Git repository with a folder for each installation. In our case, for simplicity, we will have one folder for each under the ch7/initial-setup folder in the official repository the book’s companion GitHub repository (but normally, they should be under root). We are starting with installing the initial Platform instance, which will be under ch7/initial-setup/argocd-platform.
We will create a resources folder and, inside it, a namespace.yaml file with the following content:
apiVersion: v1kind: Namespacemetadata: name: argocd-platformOutside the resources folder, we will create a kustomization.yaml file, like so:
apiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationnamespace: argocd-platformbases: - github.com/argoproj/argo-cd/manifests/ha/cluster-install?ref=v2.1.6resources: - resources/namespace.yamFrom the folder where the kustomization.yaml file resides (when you have one repository per instance that should be in the root of the repository), run the following command to make the installation:
kustomize build . | kubectl apply -f -After everything has been applied, we can run this command to see the running Pods in the newly created namespace, in order to check that our installation was done:
kubectl get pods -n argocd-platformThe result should be a list of Pods similar to this:
NAME READY STATUS RESTARTS AGEargocd-application-controller-0 1/1 Running 0 4margocd-dex-server-6bf7f6876c-xghc6 1/1 Running 0 4margocd-redis-5b6967fdfc-m5qff 1/1 Running 0 4margocd-repo-server-685cb7dbdd-qk6xp 1/1 Running 0 4margocd-server-bfb77d489-tbqww 1/1 Running 0 4mNow that we have the Platform installation, we can start deploying the prod and non-prod ones (prod will be under ch7/initial-setup/argocd-prod, while non-prod will be under ch7/initial-setup/argocd-nonprod). For this part of the demo, we will provide instructions only for the non-prod installation, as the prod one should follow the same steps. We will continue with the declarative way and the namespace.yaml file under the resources folder and the kustomization.yaml file outside, but this time we will apply them with an Application custom resource (CR) because we already have an instance that can handle them.
Here is the namespace.yaml file for non-prod:
apiVersion: v1kind: Namespacemetadata: name: argocd-nonprodWe will create a kustomization.yaml file where we will not use the cluster-install manifests but instead the namespace-install ones. We will see the differences between such installations right after we finish the installation. Here’s the code we need to execute:
apiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationnamespace: argocd-nonprodbases: - github.com/argoproj/argo-cd/manifests/ha/namespace-install?ref=v2.1.6resources: - resources/namespace.yamlThen, we create an Application file that will point to the repository and folder where we will have the kustomization.yaml file. I named the file argocd-nonprod-app.yaml, and it should look like this:
apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: name: argocd-nonprodspec: destination: namespace: argocd-nonprod server: https://kubernetes.default.svc project: default source: path: ch7/initial-setup/argocd-nonprod repoURL: https://github.com/PacktPublishing/ArgoCD-in-Practice.git targetRevision: main syncPolicy: automated: prune: falseOnce we have all those files created, we can apply the Application file with kubectl, using the following command:
kubectl apply -f argocd-nonprod-app.yaml -n argocd-platformUnfortunately, the result will not be the expected one, and we will get an error similar to this one:
failed to sync cluster https://10.96.0.1:443: failed to load initial state of resource CertificateSigningRequest.certificates.k8s.io: certificatesigningrequests.certificates.k8s.io is forbidden: User "system:serviceaccount:argocd-platform:argocd-application-controller" cannot list resource "certificatesigningrequests" in API group "certificates.k8s.io" at the cluster scopeThis is what the details page of the argocd-nonprod Application file will look like. See the 2 Errors red text—if you click on it, you will get a similar error message to the previous one:

Figure 7.2 – Errors while applying argocd-nonprod Application file
The problem comes from the fact that in the Kustomize cluster installation, the namespace is hardcoded to argocd for the ClusterRoleBinding resources for both application controller and server components. Because of this, the Argo CD Platform installation does not have access to the resources it needs to watch and create in the cluster, and so it gives the previous error. So, if we can update those ClusterRoleBnding manifests, everything should start working.
Note – Cluster versus Namespace installation with Helm
When using Helm manifests for the installation, two parameters control the cluster role-based access control (RBAC) installation: .Values.server.clusterAdminAccess.enabled and .Values.controller.clusterAdminAccess.enabled. They are enabled by default, so you need to set them to false when you want to perform a namespace installation, and we don’t have the same issue when performing a cluster install in a different namespace than argocd because the namespace is templated to namespace: {{ .Release.Namespace }}.
The change we are doing is in for the Argo CD Platform installation, and we are updating two ClusterRoleBinding resources in order to use the ServiceAccount instances from the argocd-platform namespace. We will create a patches folder under argocd-platform, and in this new folder, we will create a file called argocd-application-controller-clusterrolebinding.yaml with this content:
apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: argocd-application-controllersubjects:- kind: ServiceAccount name: argocd-application-controller namespace: argocd-platformWe will need to do the same for the argocd-server ServiceAccount instance. We need another file called argocd-server-clusterrolebinding.yaml in the patches folder, having this content:
apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: argocd-serversubjects:- kind: ServiceAccount name: argocd-server namespace: argocd-platformIn order for the files to be used by our installation to perform the namespace change, we need entries for them in the kustomization.yaml file. It should look like this:
apiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationnamespace: argocd-platformbases: - github.com/argoproj/argo-cd/manifests/cluster-install?ref=v2.1.6resources: - resources/namespace.yamlpatchesStrategicMerge: - patches/argocd-application-controller-clusterrolebinding.yaml - patches/argocd-server-clusterrolebinding.yamlNow, if we apply the Kustomize manifests again, as follows, then we should get a correct installation under the argocd-platform namespace:
kustomize build . | kubectl apply -f -Now, we have the ClusterRoleBinding resources linked to the ServiceAccount instance from the correct namespace; this allows Argo CD to list those resource types, so we should not get the error anymore when we install the non-prod or prod instances.
After the initial setup is done and we have all our instances of Argo CD up and running, we are ready to connect to clusters and deploy applications. But sometimes, things will not go according to plan, and we might need to perform some basic restarts, or we might need to use specific versions of our templating engine. Next, we are going to cover these two scenarios.
Addressing day-to-day issues
Section titled “Addressing day-to-day issues”In this section, we will discuss a few issues you would encounter on what we will call Day 2. If we mark Day 0 as the moment when we prepare the GitOps and Argo CD adoption and start working on proofs of concept (POCs) and Day 1 when we actually start implementing and deploying our GitOps solution, then Day 2 would be when we are in production, and we need to take care of the whole live setup. We went through important topics such as high availability (HA), disaster recovery (DR), and observability in Chapter 3, Operating Argo CD, and now we will see some issues that don’t fall into any of these categories.
Restarting components
Section titled “Restarting components”Back in 2018 when we started with Argo CD, we had cases when we deployed a new version of one of our microservices and the synchronization just got stuck. The user interface (UI) showed that the reconciliation loop was ongoing, but nothing was happening, there was no progress, and no error was displayed. That’s when a good old restart of the application controller would fix the issue. In time, with every new version released, Argo CD became more stable and reliable, and we had fewer instances of situations where a restart was needed.
Because every business demand and every environment are different, and an application built with Python doesn’t start or stop the same way as one built with Java, a restart might still save the day from time to time. Let’s see how that should be properly executed without getting Pods or—even worse—Deployments or StatefulSets deleted.
If you have access to the cluster, there is a simple command you can execute in order to trigger a restart, and that is kubectl rollout restart. If you encounter issues with synchronizations, then you can try to restart the application controller. This is usually deployed in Kubernetes as a StatefulSet, and the command would look like this (assuming the installation was done in the argocd namespace and the StatefulSet name is argocd-application-controller, which is the default value):
kubectl rollout restart sts argocd-application-controller -n argocdIf you are using Helm to install Argo CD, the Helm chart uses a Deployment for the application controller by default (the controller.enableStatefulSet parameter is false). In this case, the command would look like this:
kubectl rollout restart deploy argocd-application-controller -n argocdThe repository servers we would restart when encountering issues with generating the manifests and the command would look like this:
kubectl rollout restart deploy argocd-repo-server -n argocdFor the server, the restart could be useful when the command-line interface (CLI) or the UI stops responding because the server has some issues. In such cases, use the following command:
kubectl rollout restart deploy argocd-server -n argocdWe could restart Dex if we have problems with the single sign-on process, like so:
kubectl rollout restart deploy argocd-dex-server -n argocdA Redis restart is not recommended as that would throw away the cache, and there would be a performance penalty because a lot of manifests need recalculation.
In a normal situation, you should try to understand why the process was stuck, why Argo CD is not responding, and address the underlying issue. But sometimes, there is no time to deal with that and we need a fast solution to unblock the situation, which then allows us to gain some time to start debugging without someone being blocked.
Using a specific version of Helm
Section titled “Using a specific version of Helm”Argo CD has the main templating tools inside its own container image. So, each new version of Argo CD comes bundled with a specific version of Helm or Kustomize. For example, version 2.0 has Helm 3.5.1 and Kustomize 3.9.4 (a complete list of tools and their version can be found at https://github.com/argoproj/argo-cd/blob/v2.0.0/hack/tool-versions.sh), while version 2.1 came with Helm 3.6 and Kustomize 4.2 (a complete list can be seen at https://github.com/argoproj/argo-cd/blob/v2.1.0/hack/tool-versions.sh). We have situations when our manifests depend on a specific version of the templating tool we are using. We might need more time to upgrade from Kustomize 3 to 4, but we do want to start using Argo CD 2.1 because of all the bug fixes and improvements it brings. Or, it can be the other way around, where we might need a newer version of a templating tool that has a fix for a bug that created problems for us recently.
One way to use specific versions of any tool is to create your own Argo CD container image. This way, you have control of everything, you decide which version is suited for your YAML templates, and you can even remove some of the bundled tools if you know you don’t need them, thus resulting in a smaller container image. The problem with this approach is that it requires quite a bit of work: you need to build the image, push it to a container registry, and then do this for any new patch or minor versions—and there can be a few. Upgrading Argo CD is a pretty simple task, especially when using a self-managed instance, but now with your own container image, it can become a burden.
There is an easier way to use a specific version of Helm or any other templating tool. We can use an init container in our repository server deployment that will download the tool binary and then replace it in the container image. It might sound complicated, but it is pretty simple to set up, and using this method, we can upgrade Argo CD following the same process as always, because the init container part is separated from the main container. Next, we will see how we can do this with a Helm installation of Argo CD 2.1, which comes with Helm 3.6, but instead, we would like to have Helm 3.5.1 deployed. For how this can be accomplished for a Kustomize installation, we have the details in the official documentation at https://argo-cd.readthedocs.io/en/stable/operator-manual/custom_tools.
We can go through the process and see what it would look like when the installation is done via Helm and what would be the overwrites needed for the values.yaml file.
First, we need to define a new volume, which will be called custom-tools and will be of type emptyDir. This type of volume uses the default storage type used by the node, but we should not worry about the size as the file is around 40 megabytes (MB). If the container is restarted, we will not have any problems as the volume contents are not lost—this only happens when the Pod is removed from the node.
Once we have the volume, we will mount it to both the init container and to the main container where all the Argo CD files are located. When we mount it to the main container, it is important that we specify the subPath: helm entry because this assures that we remove the previous file (the version of Helm we want to replace) and that the mountPath is set to /usr/local/bin/helm, which is the new file that we will retrieve in the init container.
In the init container, which is an alpine:3.15 image, we are mounting the same volume and downloading the desired version of Helm into it using wget.
Create a new file called values-overwrite.yaml and put the following content into it (the file can also be found in the official repository under the ch7/day-to-day/custom-helm/values-overwrite.yaml path):
repoServer: volumes: - name: custom-tools emptyDir: {} volumeMounts: - mountPath: /usr/local/bin/helm name: custom-tools subPath: helm initContainers: - name: download-tools image: alpine:3.15 command: [sh, -c] args: - wget -qO- https://get.helm.sh/helm-v3.5.1-linux-amd64.tar.gz | tar -xvzf - && mv linux-amd64/helm /custom-tools/ volumeMounts: - mountPath: /custom-tools name: custom-toolsIf you want to test the update, you can easily install Argo CD via Helm with this command:
helm install argocd argo/argo-cd -n argocd -f values-overwrite.yamlWe did the example for Helm, but you can see that it would not be hard to modify it to use a specific version of Kustomize, the only changes being under the init container download part and mounting the volume in the correct path in the main container.
You can also see that the main container is separated from the init one, the only common point being the volume where we are downloading the new binary. This is why it is possible to upgrade Argo CD to the next patch version and still keep the benefits of having a fixed version of your template engine.
Improving performance
Section titled “Improving performance”Throughout the book, we have touched on the topic of performance a few times by explaining some of the settings or environment variables used to get better results from an Argo CD installation. For example, in Chapter 3, Operating Argo CD, we explained the ARGOCD_EXEC_TIMEOUT environment variable for repository servers, which you can use to increase the time allocated for Helm or Kustomize to generate manifests so that you will not receive timeouts. In the same chapter, we discussed setting resources and increasing the number of replicas for all components and how this can be achieved. We are not going through those things again; instead, we are going to take a close look at some parameters we can use in order to control the application controller and repository server performance. These are flags that need to be set on the command that starts the containers.
Application controller
Section titled “Application controller”The application controller is the component where the work is being initiated. Whenever you click the Sync button from the UI, use the argocd app sync CLI command, or make an application programming interface (API) call directly to the server to start a synchronization or when poll timeout happens (by default, every 3 minutes), in the end, it is the application controller that performs the synchronization procedure, and we have some parameters that we can pass to its container at the start in order to influence this work. We will discuss them one by one, as follows:
--status-processors—This is the parameter that specifies how many applications can be reconciled at the same time, concurrently. So, it makes sense that if you have an instance handling many applications, you would have a bigger value for it. The official documentation mentions the value of 50 for 1,000 applications, the default value being 20.--operation-processors—This has a default value of 10 and allows us to specify how many concurrent sync operations we can have. For 1,000 applications, it is recommended to go with 25.--repo-server-timeout-seconds—The application controller passes the job of generating manifests to the repository server containers. This takes time, as in many cases it needs to fetch artifacts from the internet (such as Helm downloading a chart from a registry or Kustomize downloading a remote base), and this is how much the application controller waits for the repository server to generate manifests before failing with aContext deadline exceededexception. So, if this happens, increase the value of the parameter, the default being 60 seconds.--kubectl-parallelism-limit—After manifest generation is complete, we need to apply the manifests to the destination clusters. When we explained the GitOps concept in Chapter 1, GitOps and Kubernetes, we saw this is done declaratively with akubectl applycommand. This parameter is used to specify how many concurrentkubectlexecutions we can have, and the default is 20. You can increase it if you want your applications to be synchronized faster, but a big value might start triggering out-of-memory (OOM) kills for the container, so pay attention to the metrics.
For setting different values for these parameters on a Helm installation, you have them parameterized under controller.args or use the controller.extraArgs array, so the values.yaml file would look like this (I only show the section that corresponds to these parameters, while the complete override can be found in the official repository at the book’s companion GitHub repository, in the ch7/performance-improvement/helm-installation/override-values.yaml file):
controller: args: statusProcessors: "50" operationProcessors: "25" repoServerTimeoutSeconds: "60" extraArgs: - --kubectl-parallelism-limit=30Note – Application Controller Additional Arguments
There are some additional flags present in the Helm values file: appResyncPeriod was deprecated in favor of the timeout.reconciliation setting in the argocd-cm ConfigMap, and selfHealTimeout, which is related to changes in live-cluster-triggering synchronizations, so it doesn’t necessarily affect performance.
Now that we have discovered the parameters that can influence the performance of application controllers, we can check the ones related to repository servers.
Repository server
Section titled “Repository server”The repository server is responsible for generating manifests that can simply be applied to the destination cluster with a kubectl apply command. So, it will take Helm, Kustomize, or Jsonnet templates and generate final YAML manifests from them. Generated manifests are also cached for a 24-hour period on the basis that if the commit secure hashing algorithm (SHA) of the Git repository did not change, there is no need to regenerate manifests, and the cached version can be used. Here are some flags and environment variables that we can pass to the repository server container to influence manifest generation:
--parallelismlimit—This refers to how much manifest generation can be done concurrently. The default value is 0, which means there is no limit at all, and this increases the chance of getting an OOM exception that will restart the container. That is why it is useful to track OOM restarts (we looked at this in Chapter 3, Operating Argo CD, in the Enabling observability section), and once you see you have quite a few of those, you can introduce a limit. There is also an environment variable you can use instead of flag:ARGOCD_REPO_SERVER_PARALLELISM_LIMIT.--repo-cache-expiration—This is the duration for which manifests are cached, and the default value is 24 hours. Normally, you should not modify this value, but depending on your deploy frequency, you can go even higher. Setting a smaller value will reduce the benefit of caching because it makes Argo CD recalculate the manifests, and that’s an expensive operation.ARGOCD_GIT_ATTEMPTS_COUNTenvironment variable—This is used to specify how many times we try to transform the tag, branch reference, orHEADof the Git repository default branch into the corresponding commit SHA. This operation is done many times, and sometimes it can fail, which leads to failed synchronizations. The default value is 1, which means no retries, so it would be safe to set a value bigger than 1.ARGOCD_EXEC_TIMEOUTenvironment variable—When manifest generation for Helm or Kustomize happens, it is likely that there will be a need to download something—either a Helm chart from a registry or a remote base for Kustomize. This adds to the time needed to generate manifests, which can also take some time—especially for big Helm charts—and with this variable, we can control the timeout for the manifest generation inside the repository server. The default value is 90 seconds, but if you see a lot of failed reconciliations, you can increase it. Also, please note that this is connected to the--repo-server-timeout-secondsflag from the application controller, and they should have similar values.
If you need to use different values for Helm parameters, we need to specify them under repoServer.extraArgs for the flags and under env for the environment variables. The updated section of the values.yaml file would look like this (a complete override can be found in the official repository at the book’s companion GitHub repository, in the ch7/performance-improvement/helm-installation/override-values.yaml file):
repoServer: extraArgs: - --parallelismlimit=5 - --repo-cache-expiration=24 env: - name: "ARGOCD_GIT_ATTEMPTS_COUNT" value: "3" - name: "ARGOCD_EXEC_TIMEOUT" value: "300s"The main server application does not have any flags that could affect performance because the repository server and application controller do the heavy lifting. The server has the main task of exposing an API that is consumed by the web UI, CLI, and any other custom tools that we might build (for example, by using curl).
Summary
Section titled “Summary”In this chapter, we went through some things that can happen with Argo CD that you would not expect, from an issue that can occur at installation to how restarts can be performed safely and how to stick to a specific version of a templating engine. In the end, we took a closer look at some of the most important configuration parameters and environment variables that could affect and improve the performance of two of the most important components of Argo CD: the repository server and the application controller.
In the next chapter, we will take a close look into how we can perform different checks and validations on the YAML file we are pushing to Argo CD in order to catch as many issues as possible before applying the manifests to production.
Further reading
Section titled “Further reading”For more information, refer to the following resources:
- Argo CD and Kustomize: https://redhat-scholars.github.io/argocd-tutorial/argocd-tutorial/03-kustomize.html
- Kubernetes
emptyDirvolume type: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir - More and better explanations on how
mountPathandsubPathwork together: https://stackoverflow.com/questions/65399714/what-is-the-difference-between-subpath-and-mountpath-in-kubernetes/65399827 - General troubleshooting techniques of Kubernetes applications: https://kubernetes.io/docs/tasks/debug-application-cluster/debug-application/
- Performance tuning is an ongoing thing—watch this thread for more details and developments: https://github.com/argoproj/argo-cd/issues/3282