Application Deploy to Kubernetes with Argo CD and K3d

Overview

  • Argo CD is a solution that allows us to keep track of the status of apps running on a Kubernetes cluster. This is accomplished by specifying the state as YAML-based configurations within a GitHub repository. It monitors running programs in real-time and compares the actual, live state to the desired target state.
  • It supports webhook alerts from GitHub, GitLab, and Bitbucket and can handle a variety of Kubernetes manifests, including Jsonnet, Kustomize applications, Helm charts, and YAML/JSON files.
  • In this post, We’ll learn how to utilize Argo CD to synchronize and deploy an application from a GitHub repository

Prerequisites

  1. Have a k3d (or any Kubernetes engine of your choice) cluster up with at least one worker node up. Look here for more info
  2. Knowledge of Kubernetes commands.
  3. Have argo installed locally using brew install argocd .

STEP 1 — Basic Kubernetes Setup

Validate if you have a cluster up with kubectl get nodes. This should return nodes with Ready status.

kubectl get nodes

STEP 2 — Setup Argo CD namespace & installation of scripts

Create argocd namespace in the cluster & run the Argo CD script

kubectl create namespace argocd

Now, run Argo CD install script

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

See if all Kubernetes pods are up with

kubectl get pods -n argocd

STEP 3 — Accessing Argo CD UI

Argo UI by default will run on port 80. To access it on port 8090 or any other alternative port on the local machine, run the following command

kubectl port-forward -n argocd svc/argocd-server 8080:443

Open localhost:8080 on the web browser to view Argo CD UI

The username here will beadmin . To get the password run the following command,

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=”{.data.password}” | base64 -d; echo

Also, log in to Argo CD via command line to deploy through the command line with the command

argocd login

STEP 4 — Deploying Example application to Argo CD

Now we will deploy an example application that is maintained by Argo CD to test the functionality.

To create an app we run the following command specifying the example repo and passing the default destination and namespace.

argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default

we can check the status of the guestbook application

argocd app get helm-guestbook

It will show that the status is OutOfSync which is normal. It means the application has not yet been deployed.

To sync(deploy) the application, we run

argocd app sync guestbook

Now if go to our Argo CD UI, we see helm-guestbook as one of our applications.

To view the guestbook application running you do the following

Get pod name by running

kubectl get pods

Then use the output to port-forward the pod.

kubectl port-forward helm-guestbook-d9cdf5d87-2gd9n 9090:80

You can now access the guestbook application at localhost:9090

What if you have multiple apps?

If you have multiple apps you can use the idea of “app of apps” to enable controlling apps at a higher level. Argo CD can sync each application into Kubernetes repeatedly by going through a hierarchy of directories containing independent apps. We need to configure the Argo CD helm chart file where we can set recurse: true to recurse directory.

Conclusion

In this blog, we saw the basic setup, installation & deployment of Argo CD on Kubernetes using k3d. Hope this will help you in understanding Argo CD. For more in-depth, you can refer to the official documentation.

Connect with me on LinkedIn

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store