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:
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.
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.
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):
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.