DevOps 5 min read

Modern DevOps Approach: GitOps Deployment Strategies and Automation for Kubernetes Applications with Argo CD

PROFSCODE Team 19 Jul 2026
Share:
GitOps in Kubernetes: A Guide to Declarative Continuous Deployment with Argo CD

GitOps in Kubernetes: A Guide to Declarative Continuous Deployment with Argo CD

In modern software development processes, rapid and reliable application deployment is critically important. While traditional CI/CD approaches often introduce operational complexities, the GitOps philosophy aims to reduce this complexity and simplify deployment processes. In this guide, you will learn step-by-step how to implement GitOps in a Kubernetes environment using Argo CD, a popular tool.

The GitOps Philosophy and its Advantages

GitOps is a "declarative" approach that defines your operational infrastructure and application state through a Git repository. Git serves as both a Single Source of Truth and an audit trail. Any infrastructure or application change starts with a commit to Git, and automation tools detect this commit to apply the desired state. This approach offers significant advantages such as easy rollback, auditing, and standardization of your system's state via the Git history.

What is Argo CD and Why Should it Be Preferred?

Argo CD is a declarative, GitOps-based continuous delivery tool for Kubernetes. It runs as a controller in your Kubernetes cluster and continuously monitors the target application state (Kubernetes manifests) defined in your Git repository. If it detects a drift between the cluster's current state and the target state in Git, it automatically synchronizes this state. The main benefits of Argo CD include:

  • Declarative and Automatic Synchronization: Application states are defined in Git, and Argo CD automatically synchronizes this state with the cluster.
  • Rich Web Interface: Provides a comprehensive web UI to monitor live application status, synchronization health, and history.
  • Drift Detection and Correction: Detects manual changes in the cluster and can revert them to the defined state in Git (or notify).
  • Easy Rollback: With the version control advantage provided by Git, you can easily roll back to any previous application state.
  • Multi-Cluster Support: Manage multiple Kubernetes clusters from a single Argo CD instance.

Step 1: Installing Argo CD on Your Kubernetes Cluster

Installing Argo CD on your Kubernetes cluster is quite straightforward. First, let's create a dedicated namespace for Argo CD and then apply the installation manifests:

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

After the installation is complete, ensure that the Argo CD pods are running:

kubectl get pods -n argocd

To access the Argo CD web interface, you can expose the argocd-server service externally with a NodePort or Port Forwarding. Here's a simple Port Forwarding example:

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

Now you can access the web interface at https://localhost:8080. The username for the first login is admin. Use the following command to retrieve the password:

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

Step 2: Deploying Your First Application with GitOps

Now let's deploy a simple Nginx application using the GitOps approach. First, create a Git repository containing the Kubernetes manifests for the application. For example, let's assume a repository at git@github.com:your-username/argocd-demo.git, and add a file named nginx-app.yaml to it:

# nginx-app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.19.10
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP

Commit and push this file to your Git repository. Next, we will create an Application resource to introduce this application to Argo CD. This resource tells Argo CD where the application is (the Git repository) and where it should be deployed (the Kubernetes cluster). You can do this either with the Argo CD CLI or by directly applying to Kubernetes. Let's use the CLI:

argocd app create nginx-gitops \
  --repo https://github.com/your-username/argocd-demo.git \
  --path . \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace default \
  --sync-policy automated --self-heal --prune

This command tells Argo CD to create a new application named nginx-gitops, use the manifests in the specified Git repository, and deploy them to the default namespace. --sync-policy automated enables automatic synchronization, --self-heal ensures that changes in the cluster are reverted to the state defined in Git, and --prune ensures that resources removed from Git are also deleted from the cluster.

Step 3: Observing and Managing the Deployment

Once the application is created, you can check its status from the Argo CD web interface or with the CLI:

argocd app get nginx-gitops
argocd app sync nginx-gitops

After a while, Argo CD will pull the manifests from your repository and apply them to your Kubernetes cluster. You will see that the application is running healthily and is synchronized with Git. If you make a change in your Git repository's nginx-app.yaml file and commit it (e.g., changing the replica count to 3), Argo CD will automatically detect this change and apply it to your cluster.

Best Practices with GitOps and Argo CD

  • Single Source of Truth: Keep all your application and infrastructure configurations in a single Git repository to simplify auditing.
  • Strategies for Multiple Environments: Use separate directories or branches for different environments like development, test, and production. Customize the same base manifests for different environments with tools like Kustomize or Helm.
  • Zero-Trust Deployments: Argo CD's operation within the Kubernetes cluster, requiring less external access, reduces security risks.
  • Rollback Capability: Leverage Git's version control benefits to perform fast and reliable rollbacks in case of faulty deployments.
  • Alerts and Notifications: Integrate Argo CD with monitoring tools like Prometheus, Grafana, and notification systems like Slack, Email to be instantly aware of anomalies or synchronization issues.

Conclusion

GitOps is a cornerstone of modern DevOps practices, offering a powerful methodology to simplify, automate, and enhance the security of application deployment in a Kubernetes environment. Thanks to tools like Argo CD, managing your infrastructure and applications as code has never been easier. By following the steps in this guide, you can set up your own GitOps workflow and revolutionize your software delivery processes.

Back to Blog

Comments (0)

No comments yet. Be the first to comment!

Submit Comment