Jsonnet Adventures: Deploying our application to ArgoCD!
Published: 2024-01-31 19:09:22

Hello fellow Kubernetes enthusiasts! In my previous blog posts we explored the basics of Jsonnet and how to use it to generate Kubernetes manifests. Now, I'm thrilled to finally get to the deployment of our production-ready, Jsonnet-templated application to ArgoCD.

## Prerequisites

> I am expecting you to have a basic understanding of ArgoCD and Kubernetes for this one. If you need a refresher, check out some resources online (before I create my own tutorials on these topics):
> - [ArgoCD](https://argo-cd.readthedocs.io/en/stable/getting_started/)
> - [Nginx Ingress Controller & Cert Manager](https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes)

Before diving in, here's a quick overview of what you need to follow along:

- Read through [Jsonnet Introduction](https://dev.to/kubeden/introduction-to-jsonnet-the-yamljson-templating-language-n5g)
- Read through [Jsonnet Adventures: Functions, Conditionals, and Advanced Templates](https://dev.to/kubeden/jsonnet-adventures-functions-conditionals-and-advanced-templates-4cd3)
- Jsonnet Templates Repository: All the Jsonnet templates in those tutorials are stored in [kubeden/tutorials](https://github.com/kubeden/tutorials) and you can use it as reference.
- Application Repository: The source code for the Simple Node App is in [kubeden/simple-nod-app](https://github.com/kubeden/simple-nod-app). Yes, that is a typo lol
- Docker Repository: The application's Docker image is available at [kuberdenis/simple-node-app](https://hub.docker.com/repository/docker/kuberdenis/simple-node-app/general).

## ArgoCD and Jsonnet

ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It allows us to deploy applications to Kubernetes using Git repositories as the source of truth. ArgoCD also supports Jsonnet, allowing us to deploy Jsonnet templates directly to Kubernetes.

I repeat - ArgoCD support Jsonnet out of the box! This is a huge advantage, as we can leverage Jsonnet's power to create dynamic Kubernetes manifests, and deploy them using ArgoCD.

## The Deployment Process

- Jsonnet Templates: Using Jsonnet, I generated Kubernetes manifests that are both dynamic and maintainable.
- ArgoCD Application: I created an application in ArgoCD pointing to the simple-node-app repository with a path to my *prd* directory. With a simple sync of the application, ArgoCD deployed the application to my Kubernetes cluster.

## The Result

The application, now live, dynamically greets users with the name provided in the YOUR_NAME environment variable.

Here is how the application looks like in ArgoCD:
![image.png](https://cdn.devdojo.com/images/january2024/image.png)

And here is the application itself:
![image-1.png](https://cdn.devdojo.com/images/january2024/image-1.png)

Now if we update the YOUR_NAME environment variable in the parameters.libsonnet file, and sync the application in ArgoCD, we can see the application dynamically update:
![image-2.png](https://cdn.devdojo.com/images/january2024/image-2.png)

This small, yet powerful demonstration shows the flexibility and power of combining Jsonnet for templating Kubernetes for ArgoCD.

## Conclusion

If you made it this far, thank you for reading! I hope you enjoyed this series and learned something new. I am planning to continue writing about Jsonnet and other Kubernetes-related topics, so stay tuned!

For the next Jsonnet post, I am thinking of diving deep into combining multiple templating languages and use Jsonnet + Helm to deploy Grafana and Prometheus.

Thank you for following along and if you feel like chatting, feel free to hit me up on [x/twitter](https://x.com/kubeden)!

And *drums* ... closing gif!
![gif-link](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExOGdzbHM2ZjBjamxweW1udnp4ZGhvYzdhajNrOHVkdmRjOWJsNnF5bSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/Dh5q0sShxgp13DwrvG/giphy.gif)