<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Amar Chand</title>
    <description>The latest articles on Forem by Amar Chand (@amarchand).</description>
    <link>https://forem.com/amarchand</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F857704%2Feefec7a4-0840-4f55-93da-6f672a1df2b6.png</url>
      <title>Forem: Amar Chand</title>
      <link>https://forem.com/amarchand</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/amarchand"/>
    <language>en</language>
    <item>
      <title>Sharding the Clusters across Argo CD Application Controller Replicas</title>
      <dc:creator>Amar Chand</dc:creator>
      <pubDate>Wed, 04 Oct 2023 10:26:56 +0000</pubDate>
      <link>https://forem.com/infracloud/sharding-the-clusters-across-argo-cd-application-controller-replicas-1dgh</link>
      <guid>https://forem.com/infracloud/sharding-the-clusters-across-argo-cd-application-controller-replicas-1dgh</guid>
      <description>&lt;p&gt;Argo CD is an open-source GitOps continuous delivery tool, which helps to automate the deployment of applications to Kubernetes clusters. With growing GitOps and Kubernetes adoption, Argo CD has emerged as one of the most popular choices in the GitOps ecosystem. This is one of the blog posts, where we dwell into different Argo CD related issues that we observed as part of our Argo CD enterprise support offering to our various customers.&lt;/p&gt;

&lt;p&gt;In this blog post, we will be diving deep into a specific problem that may occur with your Argo CD setup in case you’re using it to manage multiple clusters. But before we jump into the specific problem statement, let's quickly examine what Argo CD comprises internally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Components of Argo CD
&lt;/h2&gt;

&lt;p&gt;Argo CD comprises various components and each one has its own set of actions. You can see how the typical Argo CD’s architecture looks in the following diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7YopC3Wd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cszeq7lxkodl7yjywd1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7YopC3Wd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cszeq7lxkodl7yjywd1b.png" alt="Argo CD Architecture" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Image Source: &lt;a href="https://argo-cd.readthedocs.io/en/stable/#architecture"&gt;Argo CD Architecture&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;There are primarily three components of Argo CD, as visible in the above diagram:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;API&lt;/li&gt;
&lt;li&gt;Repository Service (also known as &lt;code&gt;Repo Server&lt;/code&gt;) &lt;/li&gt;
&lt;li&gt;Application Controller&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Out of the above three, the components of interest for this particular blog post are &lt;code&gt;Repository Service&lt;/code&gt; and &lt;code&gt;Application Controller&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Repository Service (aka Repo Server)
&lt;/h3&gt;

&lt;p&gt;The Repo server maintains the connection to the Git repositories where application manifests are stored. It listens to changes in the Git repositories and caches the latest changes. It is also responsible for generating Kubernetes manifests from the given application specification.&lt;/p&gt;

&lt;h3&gt;
  
  
  Application Controller
&lt;/h3&gt;

&lt;p&gt;Application Controller compares the live state (what is running in the cluster) and desired/target state (what is in the repo). If there is any difference between the live and desired state, it can optionally synchronize the live state to the desired/target state, which involves deploying, updating, or removing resources as necessary.&lt;/p&gt;

&lt;p&gt;There are many cases when you might want to consider scaling the Argo CD Application Controller, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High number of applications and resources&lt;/li&gt;
&lt;li&gt;Complex application dependencies&lt;/li&gt;
&lt;li&gt;Frequent updates&lt;/li&gt;
&lt;li&gt;Large cluster size&lt;/li&gt;
&lt;li&gt;Network latency, or connectivity issues between the Argo CD Application Controller and managed clusters&lt;/li&gt;
&lt;li&gt;High availability requirements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When an Argo CD Application Controller statefulset is scaled, from a user’s perspective it is expected that the Kubernetes clusters will be sharded across the replicas of the Application Controller uniformly. However, that is not the case. Let’s look into this in detail in the next section of the post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Once we had a situation where one of our customers ran into the problem of the non-uniform sharding process of the Argo CD Application Controller. The customer brought forward a problem where they were facing a slow synchronization issue despite having multiple replicas of the Argo CD Application Controller running for their clusters. &lt;/p&gt;

&lt;p&gt;First-hand, it seemed that the Application Controller was handling too many clusters earlier and was using too many resources. Hence, the customer went ahead and scaled up the Argo CD Application Controller statefulset. By doing so, it was expected that each replica of the Application Controller would focus on a subset of clusters, thus distributing the workload and memory usage. This process is known as sharding. Even &lt;a href="https://argo-cd.readthedocs.io/en/stable/operator-manual/high_availability/#argocd-application-controller"&gt;Argo CD’s official documentation suggests to leverage sharding&lt;/a&gt;. However, the sharding mechanism of the Argo CD Application Controller does not provide much help.&lt;/p&gt;

&lt;p&gt;When our Argo CD support engineers started looking deep into the problem, they found that some of the Argo CD Application Controller replicas were managing more clusters in comparison to other replicas and a couple of replicas were managing no clusters at all – which implies that increasing the number of replicas does not necessarily mean that your clusters will be sharded uniformly across the available replicas.&lt;/p&gt;

&lt;p&gt;To find how the clusters are sharded, you can use the &lt;code&gt;argocd&lt;/code&gt; command line utility. If it is not available, you can install it by following the &lt;a href="https://argo-cd.readthedocs.io/en/stable/cli_installation/"&gt;Argo CD CLI installation steps&lt;/a&gt;. Once installed and connected to the Argo CD server, you can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;argocd admin cluster stats
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will show the shard allocated to each of the clusters managed by the connected Argo CD instance. Following is a snippet of the output of the above command:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The below snippet is not a complete snippet and its whole purpose is to understand how to infer the output of &lt;code&gt;argocd admin cluster stats&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SERVER                          SHARD  CONNECTION  NAMESPACES COUNT  APPS COUNT  RESOURCES COUNT
https://kubernetes.default.svc  0                  4                 65          217
&amp;lt;redacted&amp;gt;                      4                  4                 65          217
&amp;lt;redacted&amp;gt;                      4                  5                 73          228
&amp;lt;redacted&amp;gt;                      3                  4                 65          217
&amp;lt;redacted&amp;gt;                      0                  4                 65          217
&amp;lt;redacted&amp;gt;                      1                  5                 73          228
&amp;lt;redacted&amp;gt;                      3                  4                 65          217
&amp;lt;redacted&amp;gt;                      4                  4                 65          217
&amp;lt;redacted&amp;gt;                      4                  5                 73          228
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above snippet, first column contains the server address of the particular Kubernetes cluster, and the second column contains the index of the Argo CD Application Controller replica that is incharge of maintaining the live state of the respective cluster. E.g. First cluster with Server address as &lt;code&gt;https://kubernetes.default.svc&lt;/code&gt; is being maintained by Argo CD Application Controller's replica with index &lt;code&gt;0&lt;/code&gt;, or in other words, it is &lt;code&gt;argocd-application-controller-0&lt;/code&gt;. Please note that all the replicas of Argo CD Application Controller have the index number as a suffix. So, it means that shard &lt;code&gt;0&lt;/code&gt; means &lt;code&gt;argocd-application-controller-0&lt;/code&gt;, shard &lt;code&gt;1&lt;/code&gt; means &lt;code&gt;argocd-application-controller-1&lt;/code&gt; and so on.&lt;/p&gt;

&lt;p&gt;If you look at the above snippet, you can see that four of the clusters are being handled by the &lt;code&gt;argocd-application-controller-4&lt;/code&gt; pod. &lt;code&gt;argocd-application-controller-0&lt;/code&gt; and &lt;code&gt;argocd-application-controller-3&lt;/code&gt; handles two clusters each, and &lt;code&gt;argocd-application-controller-1&lt;/code&gt; handles 1 cluster only.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;As the first step of troubleshooting, our professional support engineers decided to analyze the Argo CD Application Controller’s logs. When checking the logs for further troubleshooting, they found the following log multiple times in all the replicas of the Argo CD Application Controller:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Time can be different for different logs, as the log message was the same, we did not add more logs here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;time="2023-07-21T11:27:12Z" level=info msg="Ignoring cluster &amp;lt;cluster-server-address&amp;gt;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When our team dug deeper into the issue looking for the sharding logic, they found that the sharding function has been written in such a way that it assigns the particular replica of the Argo CD Application Controller to manage a cluster, based on the &lt;a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids"&gt;UUID&lt;/a&gt; of the secret storing the cluster (considering we are not manually interfering with the sharding process). &lt;/p&gt;

&lt;h3&gt;
  
  
  Logic behind Sharding in Argo CD Application Controller
&lt;/h3&gt;

&lt;p&gt;The following flow diagram depicts how the sharding logic works internally in the Argo CD codebase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The diagram depicts the sharding logic of Argo CD version &amp;lt; 2.8.0. With the release of Argo CD 2.8.0, this sharding logic is now known as the &lt;code&gt;legacy&lt;/code&gt; sharding algorithm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xig4Iva5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yc4hoo6n6ei52lhg0usq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xig4Iva5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yc4hoo6n6ei52lhg0usq.png" alt="Argo CD Application Controller Sharding Logic" width="800" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Argo CD Application Controller Sharding Logic)&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution for uniform cluster sharding across Argo CD Application Controller replicas
&lt;/h2&gt;

&lt;p&gt;In the present day, there are two ways to handle such a scenario:&lt;/p&gt;

&lt;p&gt;A. Using round-robin algorithm&lt;br&gt;&lt;br&gt;
B. Manually defining the shard&lt;/p&gt;

&lt;p&gt;In our case, our team went ahead with Solution B, as that was the only solution present when the issue occurred. However, with the release of &lt;a href="https://github.com/argoproj/argo-cd/releases/tag/v2.8.0"&gt;Argo CD 2.8.0&lt;/a&gt; (released on August 7, 2023), things have changed - for the better :). Now, there are two ways to handle the sharding issue with the Argo CD Application Controller:&lt;/p&gt;
&lt;h3&gt;
  
  
  Solution A: Use the Round-Robin sharding algorithm (available only for Argo CD 2.8.0 and later releases)
&lt;/h3&gt;

&lt;p&gt;An issue was raised on GitHub for the &lt;a href="https://github.com/argoproj/argo-cd/issues/9633"&gt;sharding algorithm of Argo CD Application Controller&lt;/a&gt; and that issue has been fixed in &lt;a href="https://github.com/argoproj/argo-cd/tree/v2.8.0"&gt;Argo CD 2.8.0&lt;/a&gt; by &lt;a href="https://github.com/argoproj/argo-cd/pull/13018"&gt;pull request 13018&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It means that users can upgrade to 2.8.0 or any later version and configure the sharding algorithm to get rid of this issue. If you don't want to (or can't) upgrade to 2.8.0, you might want to go for Solution B. &lt;/p&gt;

&lt;p&gt;However, it has to be noted that the new round-robin sharding algorithm is not the default sharding algorithm for the Argo CD Application Controller at the time of writing this blog post, it is still using the legacy sharding algorithm as the default one.&lt;/p&gt;
&lt;h4&gt;
  
  
  How to configure the Argo CD Application Controller to use a round-robin sharding algorithm?
&lt;/h4&gt;

&lt;p&gt;For configuring the sharding algorithm in Argo CD 2.8.0 or later, we need to set &lt;code&gt;controller.sharding.algorithm&lt;/code&gt; to &lt;code&gt;round-robin&lt;/code&gt; in &lt;code&gt;argocd-cmd-params-cm&lt;/code&gt; configmap. If you have installed Argo CD using manifest files, connect to the cluster on which Argo CD is running, update the namespace in the following command, and run the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl patch configmap argocd-cmd-params-cm &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;argocd-namespace&amp;gt; &lt;span class="nt"&gt;--type&lt;/span&gt; merge &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s1"&gt;'{"data":{"controller.sharding.algorithm":"round-robin"}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After updating the configmap successfully, roll out the restart of the Argo CD Application Controller statefulset using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl rollout restart &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;argocd-namespace&amp;gt; statefulset argocd-application-controller
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, to verify that the Argo CD Application Controller is using a &lt;code&gt;round-robin&lt;/code&gt; sharding algorithm, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; argocd-application-controller-0 &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nb"&gt;env&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;ARGOCD_CONTROLLER_SHARDING_ALGORITHM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected output should be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;ARGOCD_CONTROLLER_SHARDING_ALGORITHM&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;round-robin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case you maintain Argo CD using Helm, then you can add &lt;code&gt;controller.sharding.algorithm: "round-robin"&lt;/code&gt; key-value pair under &lt;code&gt;.config.params&lt;/code&gt; in values file and install/upgrade the setup, to get the similar results.&lt;/p&gt;

&lt;p&gt;In case you maintain Argo CD using Argo CD Operator, then you can add &lt;code&gt;ARGOCD_CONTROLLER_SHARDING_ALGORITHM&lt;/code&gt; environment variable under &lt;a href="https://argocd-operator.readthedocs.io/en/latest/reference/argocd/#controller-options"&gt;controller&lt;/a&gt; in the &lt;a href="https://argocd-operator.readthedocs.io/en/latest/reference/argocd/#controller-options"&gt;ArgoCD resource&lt;/a&gt; specification and set its value to &lt;code&gt;'round-robin'&lt;/code&gt;. Make sure you have enabled the sharding for controller using &lt;code&gt;Sharding.enabled&lt;/code&gt; flag under &lt;a href="https://argocd-operator.readthedocs.io/en/latest/reference/argocd/#controller-options"&gt;controller&lt;/a&gt;. Apply the configuration once the changes are done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution B: Manually define the shard
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This is a workaround in case the user doesn’t want to upgrade the running Argo CD instance or manually want to manage the sharding.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Define the shard for a new cluster
&lt;/h4&gt;

&lt;p&gt;If you are adding a new cluster, mention the index of the &lt;code&gt;application-controller&lt;/code&gt; replica which you require to manage the cluster, against the &lt;code&gt;shard&lt;/code&gt; key, while defining the particular cluster secret. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Secret&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;secret-name&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;argocd.argoproj.io/secret-type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cluster&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;secret-namespace&amp;gt;&lt;/span&gt;
&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Opaque&lt;/span&gt;
&lt;span class="na"&gt;stringData&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;cluster-name&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;server&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;server-url&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;shard&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;desired-application-controller-replica-index-here&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value of &lt;code&gt;shard&lt;/code&gt; would be at the &lt;code&gt;.stringData.shard&lt;/code&gt; location while entering the data. When you'll check the secret again, you can find the base64 encoded value of the &lt;code&gt;shard&lt;/code&gt; key at &lt;code&gt;.data.shard&lt;/code&gt; in the secret. Please note that the value of &lt;code&gt;shard&lt;/code&gt; should be in &lt;code&gt;string&lt;/code&gt; format, not in &lt;code&gt;int&lt;/code&gt; format. You might want to use quotes for that.&lt;/p&gt;

&lt;p&gt;If you want to add the cluster imperatively, mention the index of the &lt;code&gt;application-controller&lt;/code&gt; replica which you require to manage the cluster, against the &lt;code&gt;--shard&lt;/code&gt; argument. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;argocd cluster add &amp;lt; context-here &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--shard&lt;/span&gt; &amp;lt;desired-application-controller-replica-index-here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that you need to enter an &lt;code&gt;int&lt;/code&gt; value if you are adding the cluster imperatively.&lt;/p&gt;

&lt;h4&gt;
  
  
  Update the shard for an existing cluster
&lt;/h4&gt;

&lt;p&gt;In case you have an existing cluster for which you manually want to define the shard, then you will need to edit the particular cluster secret and add the following block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;stringData&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;shard&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;desired-application-controller-replica-index-here&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value of the shard would be at the &lt;code&gt;.stringData.shard&lt;/code&gt; location while entering the data. When you'll check the secret again, you can find the base64 encoded value of the &lt;code&gt;shard&lt;/code&gt; key at &lt;code&gt;.data.shard&lt;/code&gt; in the secret. Please note that the value of &lt;code&gt;shard&lt;/code&gt; should be in &lt;code&gt;string&lt;/code&gt; format, not in &lt;code&gt;int&lt;/code&gt; format. You might want to use quotes for that.&lt;/p&gt;

&lt;p&gt;Once the sharding was done, the way different clusters were distributed evenly and efficiently managed by the Argo CD sharding process can be seen using the below graph:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V0qGxLHM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5eb0vmys3ge0qwkq5i0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V0qGxLHM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5eb0vmys3ge0qwkq5i0m.png" alt="Argo CD Cluster Distribution" width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Argo CD Cluster Distribution)&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So, we learned how to use different approaches to deal with the improper sharding mechanism of the Argo CD Application Controller. Though using the built-in solution (round-robin sharding algorithm) makes more sense generally, there are cases when you might want to leverage manual sharding. For example, if you have three clusters, where the first two clusters are running 400 applications each, but the third cluster is running 800 applications, it makes sense to share one shard between the first two clusters and dedicate one shard to the third cluster.&lt;/p&gt;

&lt;p&gt;It is being discussed at the time of writing, that the round-robin sharding algorithm in Argo CD 2.8.0 is still having some problems with logging (it is generating too many logs), however, the change seems to be a step in the right direction and the &lt;a href="https://github.com/argoproj/argo-cd/issues/14337"&gt;issue&lt;/a&gt; is being worked upon right now. It should be fixed soon.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Scaling the Application Controller should be done judiciously and should be aligned with the actual needs of your environment. Monitoring the performance and resource utilization of the Application Controller can help you make informed decisions about when and how to scale.&lt;/p&gt;

&lt;p&gt;We at InfraCloud also help our customers with this kind of assessment and implement Argo CD to cater to their requirements well. If you are looking for help with GitOps adoption using Argo CD, do check our &lt;a href="https://www.infracloud.io/argo-cd-consulting-support/"&gt;Argo CD consulting capabilities and expertise&lt;/a&gt; to know how we can help with your GitOps adoption journey. If you’re looking for managed on-demand Argo CD support, check our &lt;a href="https://www.infracloud.io/argo-cd-support/"&gt;Argo CD support model&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I hope you found this post informative. For more posts like this one, subscribe to our weekly newsletter. I’d love to hear your thoughts on this post, so do start a conversation on &lt;a href="https://www.linkedin.com/in/amardargad/"&gt;LinkedIn&lt;/a&gt; :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Resources
&lt;/h2&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/argoproj/argo-cd/issues/9633"&gt;GitHub issue&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/argoproj/argo-cd/pull/13018"&gt;Pull Request&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/argoproj/argo-cd/releases/tag/v2.8.0"&gt;Release Notes of Argo CD 2.8.0&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Community Support
&lt;/h3&gt;

&lt;p&gt;If you want to connect to the Argo CD community, please join &lt;a href="https://slack.cncf.io"&gt;CNCF Slack&lt;/a&gt;. You can join &lt;code&gt;#argo-cd&lt;/code&gt; and many other channels too.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>shardingclusters</category>
      <category>argocdapplicationcontroller</category>
      <category>argocd</category>
    </item>
    <item>
      <title>Getting Started with ArgoCD</title>
      <dc:creator>Amar Chand</dc:creator>
      <pubDate>Tue, 07 Mar 2023 12:10:16 +0000</pubDate>
      <link>https://forem.com/amarchand/getting-started-4fc8</link>
      <guid>https://forem.com/amarchand/getting-started-4fc8</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In this blog, we shall discuss what ArgoCD is, and how to install it.&lt;/p&gt;

&lt;h2&gt;
  
  
  ArgoCD
&lt;/h2&gt;

&lt;p&gt;Quoting &lt;a href="https://argo-cd.readthedocs.io/en/stable/"&gt;ArgoCD's website&lt;/a&gt;, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ArgoCD is a declarative, gitops Continuous Delivery tool for Kubernetes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what is declarative? What is GitOps? and What is Continuous Delivery? Let's understand them one by one, in reverse order.&lt;/p&gt;

&lt;h3&gt;
  
  
  Continuous Delivery
&lt;/h3&gt;

&lt;p&gt;Continuous Delivery is a software engineering approach, in which code changes are automatically prepared for release in production.&lt;/p&gt;

&lt;p&gt;Continuous Delivery is often aided by Continuous Integration. The process says that, once a developer pushes some code, Continuous Integration is leveraged to test the code. Once the code is tested and all the tests are passed, Continuous Delivery tools take the baton, and deploy the code into various environments (i.e. QA, Staging, etc).&lt;/p&gt;

&lt;h3&gt;
  
  
  GitOps
&lt;/h3&gt;

&lt;p&gt;The term &lt;code&gt;GitOps&lt;/code&gt; was coined in 2017 by &lt;a href="https://www.weave.works/"&gt;Weaveworks&lt;/a&gt;. Since its inception, it has caught a lot of attention.&lt;/p&gt;

&lt;p&gt;GitOps is a way of implementing Continuous Deployment for cloud native applications.&lt;/p&gt;

&lt;p&gt;NOTE: Continuous Deployment is almost same to Continuous Delivery, the only difference is that application deployment in production environment requires Approval in Continuous Delivery, while Continuous Deployment directly deploys the code in the production as well.&lt;/p&gt;

&lt;p&gt;The main idea behind GitOps is to have a Git repository, which contains the declarative description of the desired infrastructure for the particular environments (let's say production) and an automated process to keep the production environment in the desired state. ArgoCD is one such tool which is capable of doing this.&lt;/p&gt;

&lt;p&gt;We will understand this more when we'll deploy our first application using ArgoCD.&lt;/p&gt;

&lt;h3&gt;
  
  
  Declarative
&lt;/h3&gt;

&lt;p&gt;ArgoCD is declarative in nature. It means that whatever state we define in a manifest file will be achieved by ArgoCD. There is no need to define the procedure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing ArgoCD
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pre-requisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;a kuebrnetes cluster (We shall be using Minikube as a primary cluster for further blogs in this series, to know how to install minikube, please refer to &lt;a href="https://minikube.sigs.k8s.io/docs/start/"&gt;Minikube documentation&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;kubectl&lt;/code&gt; utility to interact with the kubernetes cluster you have access to (To install kubectl utility, please refer to &lt;a href="https://kubernetes.io/docs/tasks/tools/#kubectl"&gt;Kubernetes documentation&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;There are multiple ways to install Argo CD. You can simply install it by applying plain manifests. You can also use helm chart to deploy it. In case you have an OCP/OKD cluster, then most probably you might want to go with Operator based installation. We are going to discuss the manifests way and helm way in this blog. For operator based installation, please refer the &lt;a href="https://argocd-operator.readthedocs.io/en/latest/install/start/"&gt;official Argo CD Operator documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The most beginner-friendly way to install Argo CD is to directly deploy it using plain Kubernetes manifests. Run the following commands to do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create namespace argocd
kubectl apply &lt;span class="nt"&gt;-n&lt;/span&gt; argocd &lt;span class="nt"&gt;-f&lt;/span&gt; https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to install Argo using Helm chart,then first add the Argo CD repository to your helm repositories list using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm repo add argo https://argoproj.github.io/argo-helm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have already added the repository, please run the following command to fetch the information about updated versions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have added the helm repository, run the following command to install Argo CD using helm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm &lt;span class="nb"&gt;install &lt;/span&gt;argocd argo/argo-cd &lt;span class="nt"&gt;--version&lt;/span&gt; 5.43.0 &lt;span class="nt"&gt;-n&lt;/span&gt; argocd &lt;span class="nt"&gt;--create-namespace&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will install Argo CD in &lt;code&gt;argocd&lt;/code&gt; namespace. In the next blog post of this series, we will explore how to login, and we will also deploy our first application via Argo CD.&lt;/p&gt;

</description>
      <category>argocd</category>
      <category>gitops</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Securing Kubernetes Cluster using Kubescape and kube-bench</title>
      <dc:creator>Amar Chand</dc:creator>
      <pubDate>Mon, 25 Jul 2022 09:47:15 +0000</pubDate>
      <link>https://forem.com/infracloud/securing-kubernetes-cluster-using-kubescape-and-kube-bench-5cck</link>
      <guid>https://forem.com/infracloud/securing-kubernetes-cluster-using-kubescape-and-kube-bench-5cck</guid>
      <description>&lt;p&gt;With businesses adopting cloud native technology, Kubernetes has emerged as a primary tool of choice for container orchestration. Deploying and managing applications has never been easier. However, securing clusters has been much like uncharted waters with containers. Attackers find and exploit new ways to break into the systems while the community works round the clock to protect it.&lt;/p&gt;

&lt;p&gt;To improve the security of clusters, one needs to understand what it is and how it works. For this, one needs a detailed analysis of the cluster including the file system where Kubernetes components' configurations are stored, line by line analysis of the artifacts, etc. Institutes like NSA, MITRE, CIS, etc. release benchmarks and keep upgrading them for maintaining the security of Kubernetes clusters. However, these benchmarks cover so many details that it becomes a very lengthy process to check things manually.&lt;/p&gt;

&lt;p&gt;While exploring how to set up vulnerability assessment scans for the Kubernetes clusters, we came across two tools: kube-bench and Kubescape.&lt;/p&gt;

&lt;p&gt;In this blog post, we shall discuss open source offerings of these tools, what their capabilities are, how they work, which frameworks they use, when to use them and why, and how they complement each other. So, let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is kube-bench?
&lt;/h2&gt;

&lt;p&gt;kube-bench is a tool from &lt;a href="https://www.aquasec.com" rel="noopener noreferrer"&gt;Aqua Security&lt;/a&gt;. It is an open source offering that analyzes the cluster against &lt;a href="https://www.cisecurity.org/cis-benchmarks/" rel="noopener noreferrer"&gt;Centre for Internet Security guidelines&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does kube-bench work?
&lt;/h3&gt;

&lt;p&gt;kube-bench is a tool that doesn't run continuously on your cluster. Rather, one can run it on all the nodes using simple commands. The test is divided in different sections, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Master Node Security Configuration&lt;/li&gt;
&lt;li&gt;etcd Node Configuration&lt;/li&gt;
&lt;li&gt;Control Plane Configuration&lt;/li&gt;
&lt;li&gt;Worker Node Security Configuration&lt;/li&gt;
&lt;li&gt;Kubernetes Policies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every section publishes its own tests, remediations for the tests that are failing or in warning, and its summary (count of PASS/FAIL/WARN/INFO checks). At the end, an overall summary is published. Following are some small snippets of output of the kube-bench scan on a minikube cluster:&lt;/p&gt;

&lt;h4&gt;
  
  
  Checks Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[INFO] 1 Master Node Security Configuration
[INFO] 1.1 Master Node Configuration Files
[FAIL] 1.1.1 Ensure that the API server pod specification file permissions are set to 644 or more restrictive (Automated)
[FAIL] 1.1.2 Ensure that the API server pod specification file ownership is set to root:root (Automated)
[FAIL] 1.1.3 Ensure that the controller manager pod specification file permissions are set to 644 or more restrictive (Automated)
[FAIL] 1.1.4 Ensure that the controller manager pod specification file ownership is set to root:root (Automated)
[FAIL] 1.1.5 Ensure that the scheduler pod specification file permissions are set to 644 or more restrictive (Automated)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[INFO] 1.2 API Server
[WARN] 1.2.1 Ensure that the --anonymous-auth argument is set to false (Manual)
[PASS] 1.2.2 Ensure that the --token-auth-file parameter is not set (Automated)
[PASS] 1.2.3 Ensure that the --kubelet-https argument is set to true (Automated)
[PASS] 1.2.4 Ensure that the --kubelet-client-certificate and --kubelet-client-key arguments are set as appropriate (Automated)
[FAIL] 1.2.5 Ensure that the --kubelet-certificate-authority argument is set as appropriate (Automated)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Remediations Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.1.1 Run the below command (based on the file location on your system) on the
master node.
For example, chmod 644 /etc/kubernetes/manifests/kube-apiserver.yaml
1.1.2 Run the below command (based on the file location on your system) on the master node.
For example,
chown root:root /etc/kubernetes/manifests/kube-apiserver.yaml
1.1.3 Run the below command (based on the file location on your system) on the master node.
For example,
chmod 644 /etc/kubernetes/manifests/kube-controller-manager.yaml
1.1.4 Run the below command (based on the file location on your system) on the master node.
For example,
chown root:root /etc/kubernetes/manifests/kube-controller-manager.yaml
1.1.5 Run the below command (based on the file location on your system) on the master node.
For example,
chmod 644 /etc/kubernetes/manifests/kube-scheduler.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.2.1 Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml
on the master node and set the below parameter.
--anonymous-auth=false
1.2.5 Follow the Kubernetes documentation and setup the TLS connection between
the apiserver and kubelets. Then, edit the API server pod specification file
/etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the
--kubelet-certificate-authority parameter to the path to the cert file for the certificate authority.
--kubelet-certificate-authority=&amp;lt;ca-string&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Summary Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;24 checks PASS
27 checks FAIL
13 checks WARN
0 checks INFO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Deployment methods
&lt;/h3&gt;

&lt;p&gt;kube-bench can be executed as a simple command on the host, as a container on the host using Docker command, or as a job inside Kubernetes Cluster. In case it is run inside a container/pod, it will need access to the PID namespace of the host system. The methods to run kube-bench in AKS, EKS, GKE, On-prem cluster, Openshift and ACK (Alibaba Cloud Container Service For Kubernetes) are different but well &lt;a href="https://github.com/aquasecurity/kube-bench/blob/main/docs/running.md" rel="noopener noreferrer"&gt;documented&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  When to use kube-bench?
&lt;/h3&gt;

&lt;p&gt;kube-bench's analysis is great when it scans nodes (master node, worker node, etcd node). It gives very precise instructions regarding ownership and permissions for configuration files as well as for flags and arguments that are wrongly configured. It also gives commands directly wherever applicable. However, we experienced that the outputs were more of guidelines when it came to scanning artifacts inside the cluster. There was no specific information about which artifact had misconfiguration. Following are some of the examples of checks and remediation under the Kubernetes Policies section:&lt;/p&gt;

&lt;h4&gt;
  
  
  Checks
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[INFO] 5 Kubernetes Policies
[INFO] 5.1 RBAC and Service Accounts
[WARN] 5.1.1 Ensure that the cluster-admin role is only used where required (Manual)
[WARN] 5.1.2 Minimize access to secrets (Manual)
[WARN] 5.1.3 Minimize wildcard use in Roles and ClusterRoles (Manual)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[INFO] 5.2 Pod Security Policies
[WARN] 5.2.1 Minimize the admission of privileged containers (Automated)
[WARN] 5.2.2 Minimize the admission of containers wishing to share the host process ID namespace (Automated)
[WARN] 5.2.3 Minimize the admission of containers wishing to share the host IPC namespace (Automated)
[WARN] 5.2.4 Minimize the admission of containers wishing to share the host network namespace (Automated)
[WARN] 5.2.5 Minimize the admission of containers with allowPrivilegeEscalation (Automated)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Remediations
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5.1.1 Identify all clusterrolebindings to the cluster-admin role. Check if they are used and if they need this role or if they could use a role with fewer privileges.
Where possible, first bind users to a lower privileged role and then remove the clusterrolebinding to the cluster-admin role :
kubectl delete clusterrolebinding [name]
5.1.2 Where possible, remove get, list and watch access to secret objects in the cluster.
5.1.3 Where possible replace any use of wildcards in clusterroles and roles with specific objects or actions.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5.2.1 Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.privileged field is omitted or set to false.
5.2.2 Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.hostPID field is omitted or set to false.
5.2.3 Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.hostIPC field is omitted or set to false.
5.2.4 Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.hostNetwork field is omitted or set to false.
5.2.5 Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.allowPrivilegeEscalation field is omitted or set to false.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Such outputs don’t give a clear picture about the cluster. For instance, the above output does not provide any information about the specific fields/clusterrolebindings which violate the security controls. And if your cluster is large, then this kind of information does not help much.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integrations with other tools
&lt;/h3&gt;

&lt;p&gt;At the time of writing this blog, kube-bench does not offer any native integration with other tools. However, AWS Security Hub has added it as an open source tool integration. Here are more &lt;a href="https://aws.amazon.com/about-aws/whats-new/2020/12/aws-security-hub-adds-open-source-tool-integration-with-kube-bench-and-cloud-custodian/" rel="noopener noreferrer"&gt;details on kube-bench integrations with other tools&lt;/a&gt;. Apart from this, kube-bench also provides an output of the scan in JSON format, so that if you want to make reports or create alerts on the basis of cluster scan results, you can create a script around it.&lt;/p&gt;

&lt;p&gt;So, this was all about kube-bench. As we saw above, it is great when we want to secure the cluster from the nodes' end. However, it does not provide pinpoint information when it comes to checking vulnerabilities in Kubernetes artifacts' configurations. These can be very well covered using the other tool that we are about to discuss and has grown popular recently, called Kubescape.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Kubescape?
&lt;/h2&gt;

&lt;p&gt;Kubescape is a tool from &lt;a href="https://www.armosec.io" rel="noopener noreferrer"&gt;ARMO Security&lt;/a&gt;. Its open source offering analyzes the cluster against &lt;a href="https://media.defense.gov/2022/Mar/01/2002947139/-1/-1/0/CTR_NSA_NETWORK_INFRASTRUCTURE_SECURITY_GUIDANCE_20220301.PDF" rel="noopener noreferrer"&gt;NSA&lt;/a&gt; and &lt;a href="https://www.mitre.org/capabilities/cybersecurity/overview/cybersecurity-resources/standards" rel="noopener noreferrer"&gt;MITRE&lt;/a&gt; guidelines. Apart from these two, Armo themselves have developed two security frameworks for Kubernetes, named ArmoBest and DevOpsBest, which work with Kubescape. &lt;/p&gt;

&lt;h3&gt;
  
  
  How does Kubescape work?
&lt;/h3&gt;

&lt;p&gt;Kubescape has capabilities to run inside your cluster as well as in a CI/CD pipeline. This flexibility allows you to keep a constant check on your clusters as well as CI/CD pipelines. &lt;/p&gt;

&lt;p&gt;Unlike kube-bench, Kubescape's tests are not divided into sections. Rather, Kubescape uses controls. In Kubescape's ecosystem, NSA/MITRE/ArmoBest/DevOpsBest guidelines are broken into small sets of policies (known as controls). Each control has its own set of rules against which the cluster or pipeline is scanned. Using the web interface, you can also create your own framework to use with Kubescape by combining the controls provided on the portal. Once the configuration is scanned, it sends the details to the &lt;a href="https://https://cloud.armosec.io/" rel="noopener noreferrer"&gt;ARMO's portal&lt;/a&gt;. You can also see the security posture of your cluster/pipeline from the web interface itself. A major difference between kube-bench and Kubescape is that Kubescape goes into specific details, when it comes to check Kubernetes artifacts. On the portal, Kubescape navigates you exactly to the line in a particular artifact/s configuration due to which a control is failing (example has been shared in the image below):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2azicy7bue64bsaay2u3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2azicy7bue64bsaay2u3.png" alt="Kubescape Web UI showing a line in a particular configuration where the issue lies"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you do not wish to use ARMO's portal, you can simply scan your cluster/pipeline. The issue with that is you don't get to schedule your scans natively from Kubescape. However, you can use utilities like cron for that. Following are some examples of CLI output:&lt;/p&gt;

&lt;h4&gt;
  
  
  Controls check example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[control: Naked PODs - https://hub.armo.cloud/docs/c-0073] failed 😥
Description: It is not recommended to create PODs without parental Deployment, ReplicaSet, StatefulSet etc.Manual creation if PODs may lead to a configuration drift and other untracked changes in the system. Such PODs won't be automatically rescheduled by Kubernetes in case of a crash or infrastructure failure. This control identifies every POD that does not have a corresponding parental object.
Failed:
 Namespace default
   Pod - bus
 Namespace kube-system
   Pod - storage-provisioner
Summary - Passed:22   Excluded:0   Failed:2   Total:24
Remediation: Create necessary Deployment object for every POD making any POD a first class citizen in your IaC architecture.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[control: Enforce Kubelet client TLS authentication - https://hub.armo.cloud/docs/c-0070] passed 👍
Description: Kubelets are the node level orchestrator in Kubernetes control plane. They are publishing service port 10250 where they accept commands from API server. Operator must make sure that only API server is allowed to submit commands to Kubelet. This is done through client certificate verification, must configure Kubelet with client CA file to use for this purpose.
Summary - Passed:2   Excluded:0   Failed:0   Total:2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Summary Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FRAMEWORKS: DevOpsBest (risk: 43.94), MITRE (risk: 15.93), ArmoBest (risk: 27.62), NSA (risk: 30.72)
+-----------------------------------------------------------------------+------------------+--------------------+---------------+--------------+
|                             CONTROL NAME                              | FAILED RESOURCES | EXCLUDED RESOURCES | ALL RESOURCES | % RISK-SCORE |
+-----------------------------------------------------------------------+------------------+--------------------+---------------+--------------+
| Access Kubernetes dashboard                                           |        0         |         0          |      98       |      0%      |
| Access container service account                                      |        41        |         0          |      45       |     91%      |
| Access tiller endpoint                                                |        0         |         0          |       0       |   skipped    |
| Allow privilege escalation                                            |        24        |         0          |      25       |     96%      |
| Allowed hostPath                                                      |        4         |         0          |      25       |     16%      |
.
.
.
.
.
+-----------------------------------------------------------------------+------------------+--------------------+---------------+--------------+
|                           RESOURCE SUMMARY                            |       131        |         0          |      185      |    28.35%    |
+-----------------------------------------------------------------------+------------------+--------------------+---------------+--------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Deployment methods
&lt;/h3&gt;

&lt;p&gt;Kubescape can be deployed on any Kubernetes cluster for routine check-ups, as well as in the CI/CD pipeline to ensure that no misconfiguration can make its way to production. It can be run on any machine, given that the kubeconfig file to access the cluster should be present on the machine.&lt;/p&gt;

&lt;p&gt;One can install it or run it using a simple set of commands that are available on &lt;a href="https://portal.armo.cloud" rel="noopener noreferrer"&gt;ARMO's portal&lt;/a&gt;. Once you sign-up on ARMO's portal, you get an account ID. You also get a set of commands containing this account ID so that all your clusters or CI/CD scans can show up on one single page. The following image shows how do those commands look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1te1fyn8ycwoutayb5ti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1te1fyn8ycwoutayb5ti.png" alt="Kubescape Web UI showing command line instructions to install Kubescape"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to run Kubescape inside an air-gapped Kubernetes cluster, then you can install Kubescape utility from &lt;a href="https://github.com/armosec/kubescape#install" rel="noopener noreferrer"&gt;Kubescape's Github repository&lt;/a&gt; and follow the instructions under &lt;a href="https://github.com/armosec/kubescape#offlineair-gaped-environment-support" rel="noopener noreferrer"&gt;Offline/Air-gaped Environment Support&lt;/a&gt; section present on Kubescape's Github repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where it is best to use?
&lt;/h3&gt;

&lt;p&gt;Kubescape can work efficiently on your regular cluster as well as ephemeral clusters (ones created for CI/CD checkup). Kubescape shines when it comes to the configuration of artifacts inside the cluster (in other words, Kubernetes Objects). The reason behind this is the detailed analysis available on ARMO's portal for every check that gets failed. On ARMO's portal, you get the issue drilled down to the single line in your configuration due to which a control is failing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integrations
&lt;/h3&gt;

&lt;p&gt;Kubescape natively provides integration with Prometheus, Slack, Jenkins, CircleCI, Github, GitLab, Azure-DevOps, GCP-GKE, AWS-EKS etc.. The steps for integration are well documented at both &lt;a href="https://hub.armosec.io/docs" rel="noopener noreferrer"&gt;ARMO's official docs&lt;/a&gt; and &lt;a href="https://portal.armo.cloud/settings/integrations" rel="noopener noreferrer"&gt;Integrations page on ARMO's portal&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Both Kubescape and kube-bench are different in terms of what frameworks they support, how they are deployed, and the way they perform scans and provide results. It is better to say that both have their own strong areas. kube-bench proves its mettle when it comes to scanning the host, file permissions and ownership, flags for different Kubernetes control plane components. On the other hand, Kubescape shows its worth when it comes to scanning the objects inside the cluster, such as pods, namespaces, accounts, etc.. Keep in mind that ARMO's portal is a hosted solution, and for using it, you will have to share information about in-cluster resources with it via Kubescape. However, as we discussed above, you can also use Kubescape in CLI only mode (as mentioned under Offline/Air-gaped Environment Support section in Kubescape's GitHub repository).&lt;/p&gt;

&lt;p&gt;To summarize, I believe both kube-bench and Kubescape complement each other. kube-bench should be used while setting up the cluster or adding up a new host in the cluster, as files permissions and ownership types of things are one-time tasks and it is very important to save the cluster's configuration from unauthorized access. Once the cluster/new host is up and running, Kubescape could be used for regular scans of artifacts inside the cluster as it drills down the issue to the single line of configuration.&lt;/p&gt;

&lt;p&gt;I hope you found this post informative and engaging. For more posts like this one, do subscribe to our weekly newsletter. I’d love to hear your thoughts on this post, so do start a conversation on &lt;a href="https://www.linkedin.com/in/amardargad/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; :)&lt;/p&gt;

&lt;p&gt;Looking for help with cloud native security? do check out our capabilities how we’re helping startups &amp;amp; enterprises as an &lt;a href="https://www.infracloud.io/cloud-native-security-services/" rel="noopener noreferrer"&gt;DevSecOps consulting services provider&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>kubescape</category>
      <category>kubebench</category>
      <category>security</category>
    </item>
  </channel>
</rss>
