Skip to content
ImagineWorld

Future and Conclusion

node_idnode-book_argo-cd-in-practice_chapter-09-future-and-conclusion
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num9
chapter_titleFuture and Conclusion
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

In this chapter, we will describe the democratization of GitOps under common practices. We will go through GitOps Engine and the kubernetes-sigs / cli-utils libraries and understand how various GitOps operators out there will be able to reuse a common set of GitOps features.

Lastly, we will go through the learnings of this book and what is next after you have finished reading the Argo CD in Practice book.

The main topics we will cover are as follows:

  • Democratizing GitOps
  • What is GitOps Engine?
  • What is kubernetes-sigs / cli-utils?
  • Wrap up

For this chapter, we assume that you have already familiarized yourself with the kubectl commands. Additionally, you will need the following:

The code can be found at the book’s companion GitHub repository (ch09).

In this section, we will go through the various Go libraries that have been created in order to provide a common set of core features for the different GitOps operators in the industry. We will go through the following items:

  • What is GitOps Engine?
  • What is cli-utils for Kubernetes SIGs?

The Argo CD team announced the implementation of GitOps Engine a few years back. Different GitOps operators in the industry address several different use cases but they are all mostly a similar set of core features. Based on this, the Argo CD team had an idea to build a reusable library that implements the core GitOps principles. The core features of GitOps Engine are the following:

  • A cache
  • Diffing and reconciliation
  • Health assessment
  • Synchronization
  • Engine

Argo CD is already updated and uses GitOps Engine and, in parallel, still keeps the enterprise features so it can bring the GitOps power to enterprise organizations too. The features that Argo CD delivers to GitOps as a service to large enterprises and that are not part of GitOps Engine are the following:

  • Single sign-on integration
  • Role-based access control
  • Custom resource definitions abstractions such as Application and Project, which we have already discussed in earlier chapters

All these features combined with GitOps Engine enable engineering teams to adopt GitOps much easier. Let’s take a look at the GitOps agent, a real example using GitOps Engine that has been built by the Argo team.

The Argo team, based on GitOps Engine, created a basic GitOps operator that leverages the GitOps Engine packages we described to support simple GitOps operations use cases. So, the agent doesn’t include any of the features of Argo CD, such as multi-repositories, single sign-on, or multi-tenancy.

The main idea around the GitOps agent is to inspire us to use the reusable library of GitOps Engine and share feedback with the Argo team or contribute to GitOps Engine with extra features.

The core difference between the GitOps agent and Argo CD is that the agent supports syncing a Git repository in the same cluster where it is deployed.

The agent has two modes we can use:

  • Namespaced: The agent only manages the resources in the same namespace where it is deployed.
  • Full cluster: The agent manages the whole cluster where it is deployed.

First, let’s install the agent in a namespaced mode using the following commands:

kubectl create ns example-namespaced
kubectl apply -f https://raw.githubusercontent.com/PacktPublishing/ArgoCD-in-Practice/main/ch09/namespaced/namespaced.yaml
serviceaccount/gitops-agent created
role.rbac.authorization.k8s.io/gitops-agent created
rolebinding.rbac.authorization.k8s.io/gitops-agent created
deployment.apps/gitops-agent created

Now, let’s check the status of the deployment:

kubectl -n example-namespaced rollout status deploy/gitops-agent
Waiting for deployment "gitops-agent" rollout to finish: 0 of 1 updated replicas are available...
deployment "gitops-agent" successfully rolled out

If we check the logs of the GitOps agent, we will see that the synchronization finished successfully:

"msg"="Synchronization triggered by API call"
"msg"="Syncing" "skipHooks"=false "started"=false
"msg"="Tasks (dry-run)" "tasks"=[{}]
"msg"="Applying resource Deployment/app in cluster: "https://10.96.0.1:443, namespace: example-namespaced"
"msg"="Updating operation state. phase: -> Running, message: '' -> 'one or more tasks are running'"
"msg"="Applying resource Deployment/app in cluster: https://10.96.0.1:443, namespace: example-namespaced"
"msg"="Adding resource result, status: 'Synced', phase: 'Running', message: 'deployment.apps/app created'" "kind"="Deployment" "name"="app" "namespace"="example-namespaced" "phase"="Sync"
"msg"="Updating operation state. phase: Running -> Succeeded, message: 'one or more tasks are running' -> 'successfully synced (all tasks run)'"

We can see that there are two new Pods based on the example deployment we pointed the GitOps agent toward:

[figure owed: Figure 9.1 – The GitOps agent namespaced mode successfully completed ]

Figure 9.1 – The GitOps agent namespaced mode successfully completed

If we check the YAML manifest we used, we will see that we have deployed two containers. The first container is about the GitOps agent and the second is k8s git-sync, which pulls a Git repository in a local directory, and we mount this directory to the GitOps agent container. Specifically, it’s defined as the following:

- image: argoproj/gitops-agent:latest
name: gitops-agent
command:
- gitops
- /tmp/git/repo
- --path
- ch09/namespaced/example
- --namespaced
volumeMounts:
- mountPath: /tmp/git
name: git

The preceding is the container of the GitOps agent, which will use the ch09/namespaced/example path to sync and deploy the relevant Kubernetes resources included in this directory:

- image: k8s.gcr.io/git-sync:v3.1.6
name: git-sync
args:
- --webhook-url
- http://localhost:9001/api/v1/sync
- --dest
- repo
- --branch
- main
env:
- name: GIT_SYNC_REPO
value: https://github.com/PacktPublishing/ArgoCD-in-Practice
volumeMounts:
- mountPath: /tmp/git
name: git

The preceding is a sidecar container of the Kubernetes git-sync, which will use the Git repository at the book’s companion GitHub repository to sync and deploy the relevant Kubernetes resources included in this directory.

Similarly, we can deploy the GitOps agent in full cluster mode by removing the --namespaced CLI flag, and then the GitOps agent can manage Kubernetes resources in any cluster namespace.

We have a full picture of what GitOps Engine is and its components and we got our first view of the GitOps agent and how we can use it for very simple cases. It’s time to wrap up what we learned in this book and what the future is after this.

In parallel with the Argo team, a Kubernetes SIG has been formed to cover topics such as kubectl and focus on the standardization of the CLI framework and its dependencies. This SIG group created a set of Go libraries called cli-utils in order to create an abstraction layer for kubectl and it has evolved to support server-side use in GitOps controllers too. The core features of cli-utils for GitOps are the following:

  • Pruning
  • Status interpretation
  • Status lookup
  • Diff and preview
  • Waiting for reconciliation
  • Resource ordering
  • Explicit dependency ordering
  • Implicit dependency ordering
  • Applying time mutation

The Kubernetes SIG team for cli-utils created a CLI called kapply, which is not intended to be for production use, but it gives us a chance to understand the features and how we can better utilize the set of libraries provided in it.

Let’s now see an example of using kapply and cli-utils by deploying a simple service with them. First, we need to clone the cli-utils repo and build the kapply CLI with the following command:

git clone [email protected]:kubernetes-sigs/cli-utils.git
make build

Validate that the CLI is working with the following command:

kapply --help
Perform cluster operations using declarative configuration
Usage:
kapply [command]
Available Commands:
apply Apply a configuration to a resource by package directory or stdin
completion Generate the autocompletion script for the specified shell
destroy Destroy all the resources related to configuration
diff Diff local config against cluster applied version
help Help about any command
init Create a prune manifest ConfigMap as a inventory object
preview Preview the apply of a configuration
status

We will create an example Kubernetes deployment and use the Preview feature to see which commands will be executed. You can find the example deployment in the Git repo under the ch09/cli-utils-example/deployment.yaml path. First, we need to create the inventory template that will be used in order to track the namespace and the inventory ID for the inventory objects in the Kubernetes deployment:

cd ch09/cli-utils-example
kapply init $PWD
namespace: example-cli-utils is used for inventory object

This command will create a file called inventory-template.yaml and its Kubernetes ConfigMap, which will observe the namespace we see in the output and the inventory ID. Now, let’s run the Preview feature command and observe the output:

kapply preview $PWD
Preview strategy: client
inventory update started
inventory update finished
apply phase started
deployment.apps/app apply successful
apply phase finished
inventory update started
inventory update finished
apply result: 1 attempted, 1 successful, 0 skipped, 0 failed

The output gives us a preview of the commands that are going to run, but nothing is applied yet and this runs only on the client side. So, if we try to see all the resources in the Kubernetes cluster, we should see no resources created. The next step is to run the same command with server validation, which means a preview of the Kubernetes cluster:

kapply preview $PWD –-server-side
Preview strategy: server
inventory update started
inventory update finished
apply phase started
deployment.apps/app apply failed: namespaces "example-cli-utils" not found
apply phase finished
inventory update started
inventory update finished
apply result: 1 attempted, 0 successful, 0 skipped, 1 failed
E0929 00:49:04.607170 47672 run.go:74] "command failed" err="1 resources failed"

In this case, we see that validation with the Kubernetes server returns an error. The reason is that the namespace to which the deployment manifest refers doesn’t exist. Let’s create the namespace and then try to apply the deployment:

kubectl create namespace example-cli-utils
namespace/example-cli-utils created
# Apply the deployment
kapply apply $PWD --reconcile-timeout=1m --status-events
inventory update started
inventory update finished
apply phase started
deployment.apps/app apply successful
apply phase finished
reconcile phase started
deployment.apps/app reconcile pending
deployment.apps/app is InProgress: Replicas: 0/2
deployment.apps/app is InProgress: Replicas: 0/2
deployment.apps/app is InProgress: Replicas: 0/2
deployment.apps/app is InProgress: Available: 0/2
deployment.apps/app is InProgress: Available: 1/2
deployment.apps/app is Current: Deployment is available. Replicas: 2
deployment.apps/app reconcile successful
reconcile phase finished
inventory update started
inventory update finished
apply result: 1 attempted, 1 successful, 0 skipped, 0 failed
reconcile result: 1 attempted, 1 successful, 0 skipped, 0 failed, 0 timed out

In the output, we see all the phases have been passed to the successful deployment in the cluster. Now, let’s change the number of replicas in the deployment manifest from 2 to 3, apply it again, and see the output:

kapply apply $PWD --reconcile-timeout=1m --status-events
deployment.apps/app is Current: Deployment is available. Replicas: 2
inventory update started
inventory update finished
apply phase started
deployment.apps/app apply successful
apply phase finished
reconcile phase started
deployment.apps/app reconcile pending
deployment.apps/app is InProgress: Deployment generation is 2, but latest observed generation is 1
deployment.apps/app is InProgress: Replicas: 2/3
deployment.apps/app is InProgress: Replicas: 2/3
deployment.apps/app is InProgress: Available: 2/3
deployment.apps/app is Current: Deployment is available. Replicas: 3
deployment.apps/app reconcile successful
reconcile phase finished
inventory update started
inventory update finished
apply result: 1 attempted, 1 successful, 0 skipped, 0 failed
reconcile result: 1 attempted, 1 successful, 0 skipped, 0 failed, 0 timed out

In the output, we clearly observe that there is a difference between the manifest state and the cluster state and this is the reason that the status is reconciled as pending.

This was a demonstration of one of the multiple features provided by cli-utils and gave us a good view of the capabilities and how we can leverage them in our own implementation and use cases. In the next section, we will summarize what we have learned in this book and what is next after this book.

When Argo CD started back in 2018, nobody could have predicted its success. It had a good foundation (the Application CRD with its source, the Git repository where the manifests are located, and the destination, which is the cluster and namespace where deployments are performed), was well received, understood, and a good fit for the whole GitOps concept.

It also had the right context. Back then, as now, Helm was the most used application deployment tool for Kubernetes, and it was in the V2 version. This meant it came with a component called Tiller installed on the cluster (https://helm.sh/docs/faq/changes\_since\_helm2/#removal-of-tiller), which was used to apply the manifests, and that component was seen as a big security hole. With Argo CD, you could have still used Helm charts, but you didn’t need Tiller to perform the installation as manifests were generated and applied to the destination cluster by a central Argo CD installation. I remember back then we saw this as a major benefit.

There were many other features that put it in front of the competition, such as a great UI where you could see how deployments were happening in your cluster (which also became a good tool for Kubernetes onboarding), a good CLI (which operators like myself were able to use for troubleshooting, providing more info than the UI), or single sign-on, (which opened the path to adoption in the enterprise world, as having each tool with its own access control was considered too big of a risk to have it wrongly configured).

Fast forward 4 years, and these days (October 2022), the project has almost 11,000 stars and over 800 contributors, showing a healthy ecosystem that most likely is going to grow in the next few years. The Argo umbrella includes four main projects: Argo CD, Argo Workflows, Argo Events, and Argo Rollouts, and they are now part of the incubating projects in CNCF. These are considered mature and stable ones, and with relevant usage in production. There is only one more step for Argo, and that is to reach the graduated stage, to join projects such as Kubernetes, Prometheus, Helm, or Envoy, which would mean an even wider adoption and more contributors – things that will probably happen in the next few years.

We already had the second edition of ArgoCon (https://www.youtube.com/playlist?list=PLj6h78yzYM2MbKazKesjAx4jq56pnz1XE) in September 2022, which was the first one with on-site attendance, as 2021 was only online. ArgoCon is a vendor-neutral event, organized by the community and following CNCF best practices, such as having a proper program committee. We also have two companies now offering a commercial Argo CD platform, which is again a good sign of a healthy ecosystem. We can mention that this book is a step in the same direction.

All these show that now is a good time to consider adopting GitOps and not hesitate to give Argo CD a chance.

Congrats on reading and participating in the practical parts of the book – it was a really long road and now you are reading the last section of the book.

In this book, we started by helping you get familiarized with GitOps, Kubernetes, and Kubernetes operators. After this, we continued with more advanced topics and real-life implementations for introducing Argo CD and its components, bootstrapping a Kubernetes cluster in a repeatable manner, operating and troubleshooting Argo CD, making Argo CD easy to be adapted in enterprise organizations with access control features, and designing production-ready Argo CD delivery pipelines with complex deployment strategies.

In each chapter, we presented you the code and the inspiration to try building and implementing your own solutions on Argo CD and how it can help us to implement complex orchestrate scenarios with Sync Waves and phases and enable complex deployment strategies with Argo Rollouts.

Finally, we went through the democratization of GitOps and how GitOps Engine or kubernetes-sigs / cli-utils can set the basis for the future of OpenGitOps and the standardized approach to implementing GitOps.

The Argo project is a suite of services and in the future, it may turn out to be a good idea to develop a book to present an integration between them that uses Argo CD, Argo Rollouts, Argo Events, and Argo Workflows, leveraging the full suite in an end-to-end solution.