DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • GitOps: Flux vs Argo CD
  • The Why and When of GitOps
  • Multi-Cluster Kubernetes Sealed Secrets Management in Jenkins
  • KubeVirt Implementation: Who Needs It and Why?

Trending

  • Doris: Unifying SQL Dialects for a Seamless Data Query Ecosystem
  • Failure Handling Mechanisms in Microservices and Their Importance
  • How to Configure and Customize the Go SDK for Azure Cosmos DB
  • GDPR Compliance With .NET: Securing Data the Right Way
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. GitOps for Seamless Software Deployment

GitOps for Seamless Software Deployment

This article explores GitOps, focusing on using ArgoCD and Jenkins CI/CD for seamless software deployment. It guides you through setting up a GitOps workflow.

By 
Rajesh Gheware user avatar
Rajesh Gheware
DZone Core CORE ·
Jan. 25, 24 · Analysis
Likes (1)
Comment
Save
Tweet
Share
4.0K Views

Join the DZone community and get the full member experience.

Join For Free

In the ever-evolving landscape of software deployment, GitOps has emerged as a game-changer, streamlining the journey from code to cloud. This article will explore GitOps using ArgoCD, a prominent GitOps operator, focusing on two repositories: the application repository gitops-apps-hello and the source of truth repository gitops-k8s-apps. We'll delve into setting up a workflow that integrates these repositories with ArgoCD for seamless deployment. Fork these repos and replace the references in the below article to experiment on your own.

Understanding GitOps With ArgoCD

GitOps is more than just a buzzword; it's a paradigm that leverages Git as the single source of truth for infrastructure and application configurations. Integrating GitOps with ArgoCD enhances the deployment process offering a robust solution for managing Kubernetes clusters.

Key Benefits:

  • Automated Deployments: Changes in the Git repository automatically trigger deployments.
  • Improved Traceability: Every change is traceable through Git commits.
  • Enhanced Security: Git's inherent security features bolster the deployment process.

Setting Up a GitOps Workflow With ArgoCD

To exploit the full potential of GitOps, let's set up a workflow using the specified repositories and ArgoCD.

Pre-Requisites:

  • A Kubernetes cluster.
  • Access to the specified Git repositories.
  • ArgoCD is installed on your Kubernetes cluster.

Step 1: Install ArgoCD

Install ArgoCD on your Kubernetes cluster. You can use the following command:

Shell
 
kubectl create namespace argocd

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


Step 2: Access ArgoCD UI

Once installed, access the ArgoCD UI by port-forwarding:

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


Then, visit http://localhost:8080 in your browser.

Step 3: Connect Repositories

Connect the application repo and the source of the truth repo to ArgoCD:

Shell
 
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64

sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd

argocd login localhost:8080 --username admin --password <password>


Shell
 
argocd repo add https://github.com/brainupgrade-in/gitops-apps-hello
argocd repo add https://github.com/brainupgrade-in/gitops-k8s-apps


Step 4: Define an Application in ArgoCD

Define an application in ArgoCD that points to the gitops-k8s-apps repository. This can be done either via the UI or the CLI. Here's an example using the CLI:

Shell
 
argocd app create argocd --repo https://github.com/brainupgrade-in/gitops-k8s-apps.git --path argocd/apps --dest-server https://kubernetes.default.svc --dest-namespace argocd


Shell
 
curl -o argocd-cm.yaml  https://raw.githubusercontent.com/brainupgrade-in/gitops-k8s-apps/main/argocd/overlays/argocd-cm.yaml

kubectl patch cm argocd-cm -n argocd --type strategic --patch-file argocd-cm.yaml

curl -o argocd-repo-server-deploy.yaml https://raw.githubusercontent.com/brainupgrade-in/gitops-k8s-apps/main/argocd/overlays/argocd-repo-server-deploy.yaml

kubectl patch deployment argocd-repo-server -n argocd --type strategic --patch-file argocd-repo-server-deploy.yaml


Automating Deployments

With ArgoCD, changes in the gitops-k8s-apps repository automatically triggers deployments in your Kubernetes cluster. ArgoCD continuously monitors this repository and ensures that the cluster's state matches the desired state defined in the repository.

Example: Updating an Application

Integrating Jenkins CI/CD into our GitOps workflow adds another layer of automation and control, especially when updating applications. Jenkins can be used to automate the process of building, testing, and deploying changes to our application repository, brainupgrade-in/gitops-apps-hello, and then updating our source of truth repository, brainupgrade-in/gitops-k8s-apps, which in turn triggers ArgoCD to deploy these changes to the Kubernetes cluster.

Setting up Jenkins for Application Updates

  • Jenkins Installation and Setup: First, ensure Jenkins is installed and properly configured. You should have a Jenkins server with the necessary plugins for Git and Kubernetes.
  • Creating a Jenkins Pipeline: Create a new Jenkins pipeline that is triggered by changes in the gitops-apps-hello repository. This pipeline will handle the build and test processes for the application.
Properties files
 
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                // Commands to build the application
                sh 'echo Building Application...'
            }
        }
        stage('Test') {
            steps {
                // Commands to test the application
                sh 'echo Running Tests...'
            }
        }
        stage('Update Source of Truth') {
            steps {
                // Updating the gitops-k8s-apps repository with the new application version
                script {
                    // Fetch the new image tag or build number
                    def newImageTag = 'my-app-image:1.1.0' // Example tag
                    // Clone the source of truth repository
                    sh 'git clone https://github.com/brainupgrade-in/gitops-k8s-apps.git'
                    sh 'cd gitops-k8s-apps'
                    // Update the Kubernetes manifests with the new image tag
                    sh "sed -i 's|newTag: .*|newTag: ${newImageTag}|' ./hello/e2e/kustomization.yaml"
                    // Commit and push the changes
                    sh 'git commit -am "Update app version"'
                    sh 'git push origin main'
                }
            }
        }
    }
}


  • Handling Repository Credentials: Ensure Jenkins has the necessary credentials to access both Git repositories. This can be set up in the Jenkins credentials store.
  • Webhooks for Triggering Builds: Set up webhooks in the gitops-apps-hello repository to trigger the Jenkins pipeline automatically whenever there's a push to the repository.
  • Pipeline Execution: When changes are pushed to the gitops-apps-hello repository, the Jenkins pipeline triggers. It builds and tests the application, and if these stages succeed, it proceeds to update the gitops-k8s-apps repository with the new application version.
  • ArgoCD Deployment: Once Jenkins pushes the updated Kubernetes manifests to the gitops-k8s-apps repository, ArgoCD detects these changes. ArgoCD then synchronizes the changes, deploying the updated application version to the Kubernetes cluster.

Benefits of Using Jenkins in the GitOps Workflow

  • Automated Testing and Building: Jenkins automates the build and test phases, ensuring that only thoroughly tested applications are deployed.
  • Traceability: Every change is logged and can be traced back through Jenkins builds, providing an audit trail.
  • Flexibility: Jenkins pipelines can be customized to include additional stages like security scanning or integration testing.
  • Efficiency: This integration streamlines the process from code change to deployment, reducing manual intervention and speeding up the release process.

Integrating Jenkins into our GitOps workflow for updating applications adds a robust, automated pipeline that ensures reliability and efficiency in deployments. This combination of Jenkins for CI/CD and ArgoCD for GitOps offers a powerful toolset for modern cloud-native application deployment.

Best Practices for GitOps With ArgoCD

  1. Immutable Infrastructure: Treat infrastructure as code; all changes should be through Git.
  2. Review and Approval Processes: Use pull requests and code reviews for changes in the Git repositories.
  3. Regular Monitoring: Keep an eye on the ArgoCD dashboard for the status of applications.
  4. Security Practices: Implement secure access controls and audit trails for both repositories.

Conclusion

Mastering GitOps with ArgoCD is a stepping stone towards efficient and reliable software deployment. By leveraging the robustness of Git and the automation capabilities of ArgoCD, we can achieve a seamless deployment process. This approach resonates with modern software development needs, ensuring a smoother and more controlled path from code to cloud. As we continue to innovate, embracing methodologies like GitOps will be pivotal in shaping efficient and secure software deployment landscapes.

Git Kubernetes Software deployment Jenkins (software) Infrastructure

Published at DZone with permission of Rajesh Gheware. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • GitOps: Flux vs Argo CD
  • The Why and When of GitOps
  • Multi-Cluster Kubernetes Sealed Secrets Management in Jenkins
  • KubeVirt Implementation: Who Needs It and Why?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!