Devops

GitOps with ArgoCD: Automated NGINX Deployment on Minikube

Argo CD Minikube



What is GitOps?

In today’s software world, everyone is familiar with the term deployment.

A deployment is the process of releasing a new version of your software application to production. Essentially, it’s your software delivery mechanism.

Typically, this process follows these stages: Building → Testing → Staging → Deploy to Production, often triggered after a Pull Request (PR) is approved and pushed.

The core goal of GitOps is to minimize manual interventions on the cluster CLI, make system management version-controllable, and manage not just application code, but the entire infrastructure as code, following a pull-based approach.

With GitOps, teams can quickly track who changed what and when, detect errors faster, and revert changes efficiently.

In practice, GitOps stores Kubernetes manifest files (Deployment, Service, Ingress, etc.) directly in Git, versioned and automatically applied to the cluster. In this way, Git becomes your single source of truth, replacing ad-hoc kubectl commands for cluster management.



Key Advantages of GitOps

1. Simplified Audit and Rollback:

With Git’s full history, every change is automatically recorded. If an issue arises, reverting to a previous version is as simple as performing a git revert.

2. Infrastructure as Code Management:

Infrastructure changes are implemented via Pull Requests (PRs). This allows for code review processes, early detection of errors, and ensures that infrastructure modifications are tracked and auditable just like application code.

3. CI/CD Integration:

GitOps streamlines the Continuous Delivery process. When a manifest file that has passed CI tests is pushed to Git, the GitOps tool automatically applies the changes to the cluster. Everything remains version-controlled, auditable, and traceable.



    Push-Based vs Pull-Based Deployment Models


    Deployment strategies are generally divided into Push-Based and Pull-Based model

    FeaturesPush ModelPull Model
    Deployment triggeringCI tool(eg. Jenkins)GitOps agent (eg. ArgoCD)
    ImplementionManuel interventionAutomatic sync(reconcile)
    ToolsJenkins, GitLab CIArgoCD, Flux


    In a push-based workflow, the CI/CD pipeline directly executes commands like kubectl apply to deploy changes. While this works, the deployment logic is embedded in the CI pipeline itself, and cluster access must be exposed, which can increase complexity and security risks.


    In a pull-based workflow, a GitOps tool such as ArgoCD continuously monitors your Git repository. When it detects changes, it automatically updates the cluster if there are differences. This approach improves security, reliability, and maintainability, keeping deployment logic separate from CI pipelines.



    How GitOps Deployment Works: Minikube Demo


    So, how does this system work in practice? Here’s a step-by-step GitOps deployment workflow:

    Demo

    1. Create a Deployment YAML file: For example, an nginx-deployment.yaml file contains all the definitions for your application.
    2. Commit the file to a Git repository: You specify which directory in the repository ArgoCD should monitor.
    3. ArgoCD continuously monitors the Git repository: When it detects any changes, it automatically applies the new configuration to the cluster.
    4. Application synchronization by ArgoCD: The application is updated automatically, reducing the risk of human error. Updates are fully tracked, versioned, and can be rolled back if necessary.



    Prerequisites

    If you are on Windows or Mac, make sure you have Docker Engine and Minikube installed.

    We will run the ArgoCD setup inside a Minikube cluster on Docker Desktop.

    Start your Minikube cluster with sufficient resources:

    minikube start —memory=4096 —cpus=4



    Install ArgoCD



    Create a dedicated namespace for ArgoCD:

    kubectl create namespace argocd
    



    Apply the official ArgoCD manifests:

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

    It may take up to 5 minutes for all ArgoCD pods to be up and running.



    Access ArgoCD Web UI

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


    Default login credentials:

    • Username: admin
    • Password: Retrieve it using:
    kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d && echo
    

    Web access: https://localhost:8080



    Create a New Repo


    In your GitHub profile, create a public repo, for example named nginx-demo-gitops.



    Prepare the Deployment YAML File



    Save the following as nginx-deployment.yaml and push it into your repo:

    mkdir nginx-app
    cd nginx-app/
    
    cat <<EOF > nginx-deployment.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:latest
            ports:
            - containerPort: 80
    EOF



    Pushing Your App to GitHub for GitOps Deployment


    Once you’ve created your repository, it’s time to push your Kubernetes manifests to GitHub /


    For this demo, I named my repository gitops-apps, but you can choose any name that fits your project.


    If you’re using an IDE like Cursor or VS Code, you can push your files directly from the editor. Alternatively, you can use the terminal with standard Git commands:

    For Git login on your terminal , generate tokens >> https://github.com/settings/tokens

    git init
    git remote add origin https://github.com/kullaniciadiniz/gitops-apps.git
    git add .
    git commit -m "Initial nginx deployment"
    git push -f origin main


    Now, let’s switch back to the ArgoCD dashboard to connect our GitHub repo and deploy the app.


    In the ArgoCD UI, under the syncPolicy section, we define the following:

    syncPolicy:
      automated:
        prune: true
        selfHeal: true
    • automated: Ensures ArgoCD automatically applies changes from your Git repository to the cluster.
    • prune: true: Removes resources from the cluster if they are deleted from the repo.
    • selfHeal: true: Even if someone makes manual changes directly on the cluster, ArgoCD will revert them to match the Git state.


    Thanks to this setup, your cluster is always kept in sync with the single source of truth — your Git repo.


    Now, inside the Edit as YAML editor, you can paste the following example configuration:

    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: nginx-app
      namespace: argocd
    spec:
      project: default
      source:
        repoURL: https://github.com/kullaniciadi/gitops-apps.git
        targetRevision: HEAD
        path: .
      destination:
        server: https://kubernetes.default.svc
        namespace: default
      syncPolicy:
        automated:
          prune: true
          selfHeal: true

    Cluster Url should be https://kubernetes.default.svc since this is a local cluster.


    Next, click the CREATE button to continue.

    Your application will now appear in the ArgoCD dashboard. If the Synced count on the left side does not show 1, it means there may be a mistake in your configuration.

    At this point, ArgoCD has synchronized the Desired state (from Git) with the Active state (running in the cluster).


    Now let’s make a small change inside the deployment in our Git repository and update the replica count.

    1. Go back to your gitops-apps repository.
    2. Open the nginx.yaml file.
    3. Change the line from:
    git add nginx-deployment.yaml
    git commit -m "Update replicas to 4"
    git push -f origin main



    Commit and push the changes back to GitHub.


    ArgoCD detects the drift and automatically syncs the replicas to 4


    From the ArgoCD web interface, you can view the application details and see the updated number of pods running in your Kubernetes cluster.


    By clicking on the repository link inside the ArgoCD application view, you can see all pushed versions up to the latest git push


    In the latest version, you can open the Details section to review the Summary column, where all the recent changes are clearly listed. This gives you a quick overview


    As you can see, in the latest version, the replica count has been successfully updated to 4, reflecting the change made in your Git repository and automatically synchronized by ArgoCD.

    In this article, we explored the fundamentals of GitOps and demonstrated step by step how to implement it using ArgoCD. Starting with a simple NGINX deployment, we gained insight into how even more complex real-world deployments can be managed efficiently with this approach.

    The GitOps methodology brings significant benefits to the software lifecycle in terms of automation, observability, and maintainability. Not only application code but also infrastructure configurations can now be version-controlled directly in Git, ensuring consistency, auditability, and faster recovery from errors.

    Related Articles

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Back to top button