SquareOps

Microservice Delivery on Kubernetes using Jenkins, Helm Charts, and ArgoCD

About

Microservice Delivery on Kubernetes using Jenkins, Helm Charts, and ArgoCD
Leverage Helm, ArgoCD, and Jenkins to facilitate continuous delivery of micro-services on Kubernetes, adhering to industry-leading best practices.

Industries

Share Via

Introduction

In the modern software development landscape, microservices and Kubernetes have become a preferred choice for building and deploying applications. The decoupled nature of microservices allows for scalability and maintainability. However, the management and delivery of these services on Kubernetes often present new challenges.

Some of these challenges include:

  1. Configuration Management: Handling the configuration of a large number of microservices can be complex and time-consuming, requiring a robust solution.
  2. Continuous Integration and Continuous Delivery (CI/CD) with Rollbacks and Version Control: Ensuring that applications are always up-to-date and having the ability to quickly revert to a stable previous version in case of issues are essential for maintaining a reliable software delivery pipeline.
  3. Monitoring Multiple Deployments: Keeping track of the status and health of various deployments across the Kubernetes cluster can be overwhelming without proper tools and automation.

Through this blog post, we will showcase an efficient solution to tackle these challenges using Jenkins, Helm charts, and ArgoCD.

Before we dwell deep into the Microservice Delivery Solution it’s crucial to have a robust Infrastructure in place for deploying these services. One popular tool for infrastructure provisioning and management is Terraform. By leveraging Terraform, you can define your infrastructure as code and ensure consistent and repeatable deployments.

At SquareOps, we have created a comprehensive guide on building the infrastructure for microservices on AWS using Terraform. We highly recommend referring to our GitHub repository SquareOps GitHub for detailed instructions and code samples.

In that guide, you will find step-by-step instructions on configuring the necessary resources such as Virtual Private Cloud (VPC), subnets, security groups, EKS cluster and Elastic Load Balancers (ELBs). Additionally, we cover topics such as autoscaling groups, EKS add-ons , Amazon RDS for database management, and integrating AWS services with your microservices architecture. Now , let’s jump back to Helm , Jenkins and ArgoCD for deployment.

Streamlining Microservices with Helm Charts

Helm, the package manager for Kubernetes, is at the core of our solution. Helm charts are a collection of files that describe a related set of Kubernetes resources. They provide a method to deploy applications onto the Kubernetes platform smoothly.

We maintain a single Git repository for all services’ Helm charts. Our structure includes a main chart, with each microservice chart added as a dependency. This approach enhances modularity and reusability, allowing each microservice to encapsulate its Kubernetes resources.

In this structure:

  • The charts directory contains a subdirectory for each microservice, which in turn includes its specific Helm chart.

  • Each microservice chart consists of a Chart.yaml file (the chart description), a values.yaml file (the default configuration values), and a templates directory that contains the Kubernetes resource definitions.

  • The main-chart directory contains the main Helm chart. It includes a Chart.yaml file, a values.yaml file, and a requirements.yaml file that lists each microservice chart, under /charts directory, as a dependency.

Application Environment Setup with ArgoCD

ArgoCD, a declarative GitOps continuous delivery tool for Kubernetes, ensures that our cluster configuration matches the state specified in the Git repository. It is a powerful tool that simplifies the process of deploying your applications configured with Helm charts.

Here, we’ll illustrate the steps to quickly use the Helm Git repository to create an application on the ArgoCD user interface (UI):

  1. Log into the ArgoCD UI: First, log into the ArgoCD UI using your credentials. The UI is typically accessed via a web browser at the ArgoCD server’s host.
  2. Once logged in, Connect the Git repository for Helm chart under Settings.
  3. Navigate to the “Applications” page and click on the “New Application” button.
  4. Fill in the Application Details and Create the Application:
    • Application Name: Choose a name for your application.
    • Project: Select the ArgoCD project where your application will reside.
    • Sync Policy: Choose ‘Manual’ for the start, you can change it to ‘Automatic’ later based on your requirements.
    • Repository URL: Select the Git URL of your Helm charts repository.
    • Revision: Specify the Git revision of your Helm charts repository (for example, a branch name like master or main).
    • Helm Chart: Enter the path to your main Helm chart within the repository (for example, main-chart).
    • Values Files: Add the path to your environment-specific values.yaml file in your repository. This file contains configuration overrides for your microservice Helm templates.

ArgoCD will fetch the specified Helm chart from your Git repository, apply the configuration overrides from your values.yaml file, and deploy the application to your Kubernetes cluster. By keeping separate values.yaml files for different environments, we can manage environment-specific configurations efficiently and prevent unnecessary conflicts.

Once your application is deployed, you can monitor its status and health directly from the ArgoCD UI. Click on your application to view its details. Here you will see a visualization of your application’s dependencies and related Kubernetes resources. This graph is an incredibly useful feature of ArgoCD that lets you see the state of your application at a glance.

Agro CD

Building and Deploying with Jenkins Pipeline

Jenkins, a popular open-source automation server, is our tool of choice for Continuous Integration and Continuous Deployment (CI/CD). With its multibranch pipeline feature, we can create and manage a pipeline for each branch in our Git repository.

Here’s an example of a Jenkins multibranch pipeline for a Node.js application:

In this Jenkinsfile, the Unit Test stage runs only when a pull request is raised from a branch matching the feature-* pattern to the develop branch.

The Docker Build and Push and Approval stages run only for the develop and master branches. the pipeline builds Docker images and pushes them to the Amazon Elastic Container Registry (ECR)

On a successful push to ECR, the pipeline triggers a manual approval step for deployment on the development and production environments, respective to the develop and master branches.

jenkins-pipelines

The Deploy stage includes steps to clone the Helm chart repo, update the Docker image tag in the respective environment’s values.yaml file, and push the changes back to the Git repository. The environment is determined based on the branch name.

Conclusion

The combination of Kubernetes, Jenkins, Helm Charts, and ArgoCD provides a comprehensive solution to seamless Microservice Onboarding, to Kubernetes efficiently.

At SquareOps Technologies, we specialize in implementing advanced pipeline workflows that includes DevSecOps, performance testing, Blue-green deployments, Rollbacks, DB migrations, Notifications etc.

We can offer an in-depth, customized implementation to expedite your microservice onboarding process. Contact us today to discover how we can optimize your microservice delivery.

Frequently asked questions

What is the role of Jenkins in a microservice delivery pipeline on Kubernetes?

Jenkins automates the Continuous Integration (CI) part of the pipeline, handling tasks like building code, running tests, and packaging microservices into Docker images. It then pushes these images to a container registry for deployment.

How does Helm simplify Kubernetes deployments for microservices?

Helm is a package manager for Kubernetes that uses Helm charts to define, install, and upgrade applications. Helm charts allow you to configure and manage microservices in a reusable, consistent way, making it easier to deploy complex applications on Kubernetes.

What is ArgoCD, and how does it support microservice delivery?

ArgoCD is a Continuous Deployment (CD) tool for Kubernetes that provides GitOps-style deployment. It synchronizes Kubernetes manifests (often generated by Helm) from a Git repository to ensure the cluster’s configuration matches the codebase, enabling automated and declarative deployments.

How do Helm Charts work in a CI/CD pipeline?

Helm Charts are templates for deploying applications on Kubernetes. Jenkins can package microservices as Docker images, and then Helm Charts define the configurations for deploying these images in Kubernetes. ArgoCD or Jenkins can then apply these charts in the cluster.

How can I automate deployments with ArgoCD in a microservices environment?

ArgoCD automatically syncs the desired application state in Git with the Kubernetes cluster. When a new version of the Helm chart is committed to Git, ArgoCD detects the change, pulls the updated chart, and deploys it to Kubernetes.

How can I handle different environments (e.g., dev, staging, production) using Helm?

Helm allows you to use values files specific to each environment (e.g., values-dev.yaml, values-prod.yaml). You can pass the appropriate file during deployment to customize configurations like resource limits, replica counts, and environment-specific variables.

What are the benefits of using GitOps with ArgoCD for microservices?

GitOps with ArgoCD ensures that your Kubernetes configurations are stored in version control, providing a single source of truth. It allows for easy rollbacks, auditing, and reproducibility, and it automatically syncs cluster state with Git, ensuring configurations are always up-to-date.

How does Jenkins integrate with ArgoCD to facilitate CD?
How does Jenkins integrate with ArgoCD to facilitate CD?
Jenkins can trigger updates to Git repositories that ArgoCD watches. For example, after Jenkins builds and pushes a Docker image, it updates the Helm chart values in Git, prompting ArgoCD to detect the changes and deploy the updated image.
How can I rollback a deployment using ArgoCD?

ArgoCD provides a rollback feature that allows you to revert to previous application versions directly from its UI or CLI. ArgoCD keeps track of application versions, so you can select the desired version to roll back to if a deployment fails.

What are some best practices for managing microservices on Kubernetes with Helm and ArgoCD?

Best practices include: using separate Helm charts or subcharts for each microservice, maintaining environment-specific configuration files, implementing automated tests and linting for Helm charts, and leveraging GitOps with ArgoCD for version control and automated deployments. This ensures consistency, reliability, and an organized deployment process.

Related Posts