Monday, December 23, 2024
HomeKubernetesArgoCDHow to Deploy the Application automatically using Argo CD

How to Deploy the Application automatically using Argo CD

Back to Argo CD…!! So far on Argo CD we have see how to create the deploy Argo CD and create the application manually. In this post let’s see how we can automate the Argo CD application creation. We all aware of and also seen in previous post Argo CD makes pull based GitOps deployment. In sort it simply listens to the repo and apply the manifest files to the cluster. Same will be applied here, we can keep all the configuration in repo including its internals, Rest will be taken care by Argo CD.

In this post will see couple of application created automatically from github.

Prerequisites:

Let’s create sample deployments

Before we created the Argo CD Applications, lets create the basic deployment, let’s create the sample deployments with nginx. I have followed the folder structure, argocd/example/app-of-app in my repository and inside that have create two applications.

Here the sample deployments for your reference.

Webapp-1:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp-1
  labels:
    app: webapp-1
spec:
  replicas: 4
  selector:
    matchLabels:
      app: webapp-1
  template:
    metadata:
      labels:
        app: webapp-1
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

Webapp-2:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp-2
  labels:
    app: webapp-2
spec:
  replicas: 3
  selector:
    matchLabels:
      app: webapp-2
  template:
    metadata:
      labels:
        app: webapp-2
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

We are good with our deployment, now we should create Argo CD Applications pointing to this deployment Manifests.

Argo CD can be configured in three different ways: using the GUI, using the CLI, or using Kubernetes Manifest files. In previous post we have seen first two options, now let’s see third method.

Create the following Manifest files in a new folder argocd/test-apps. This is test-apps/webapp-1.yml:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: webapp-1
  namespace: argocd
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: argocd-app1
    server: https://kubernetes.default.svc
  project: default
  source:
    path: argocd/example/app-of-app/webapp-1
    repoURL: https://github.com/foxutech/kubernetes.git
    targetRevision: HEAD

This is test-apps/webapp-2.yml:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: webapp-2
  namespace: argocd
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: argocd-app2
    server: https://kubernetes.default.svc
  project: default
  source:
    path: argocd/example/app-of-app/webapp-2
    repoURL: https://github.com/foxutech/kubernetes.git
    targetRevision: HEAD

You may notice here we are creating Kubernetes object called Application in the argocd namespace. This object contains the source Git repository and destination server details. Your applications are pointing to the deployment we have created before.

Create main application

We are all set on our repo side, it’s time to mention in Argo CD to refer this apps, for that we should create main or master or central application, to find this application and deploy the nginx. This pattern is called the App of Apps pattern, where one Application contains the instructions to deploy multiple Applications. For this you can create the application via GUI and let’s name it as master-app with the following configuration:

Once it has been created, master-apps begin syncing in the GUI, After the sync is complete, your two Nginx applications appear in the GUI as well.

Since we didn’t enable AutoSync, manually sync webapp-1 and webapp-2. Once synced, your Nginx replicas are deployed for all two apps.

You can refer the sync and real-time demo on below video.

That’s it for now, this app of apps pattern in one of the critical solutions for multiple use case, you can manage the multiple automated tools on Kubernetes with ArgoCD in GitOps way, like the application keep growing and has multiple changes, mostly monitoring tools on devops platform. Which need multiple changes often to add/change the monitoring rules.

In coming posts, will see more example application with multiple scenarios to manage on Kubernetes directly and via ArgoCD or GitOps way.

You can follow us on social media, to get some short knowledges regularly.

RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments