Automating CI/CD Pipelines with Azure DevOps for Kubernetes Deployments: A GARUPA Case Study

Automating CI/CD Pipelines with Azure DevOps for Kubernetes Deployments: A GARUPA Case Study
CI/CD Pipeline Flux

In the world of software development, Continuous Integration and Continuous Deployment (CI/CD) pipelines are indispensable for automating the processes of integrating code changes and deploying applications. This blog post explores a practical implementation of a CI/CD pipeline using Azure DevOps, focusing on a Kubernetes deployment for GARUPA, a Brazilian ride-hailing app. This case study provides insights into automating deployments, managing secrets, and ensuring a smooth and scalable deployment process.

Introduction to the Project

GARUPA, a Brazilian ride-hailing app, has its backend infrastructure orchestrated with Kubernetes. To ensure efficient, error-free deployments and updates, GARUPA utilizes Azure DevOps for its CI/CD processes. This setup allows for automated builds and deployments, ensuring that new features, bug fixes, and updates are seamlessly integrated and deployed across production environments.

Setting Up the CI/CD Pipeline

The CI/CD pipeline for GARUPA is configured in Azure DevOps, structured around various stages including Build and Deployment. The pipeline is triggered by changes in the development branch, ensuring that the latest code changes are automatically built, tested, and deployed.

Trigger and Resources

The pipeline is initiated upon any change in the development branch, with no prerequisites for pull requests. This setup ensures that the deployment process is streamlined, allowing for quicker integration of new changes. The resources utilized in this pipeline include the project's own repository, emphasizing the self-contained nature of the deployment process.

name: GARUPA-SOLICITACAO-CI-DEV
trigger:
  - dev
pr: none
resources:
  - repo: self

Configuration and Secrets

variables:
  - group: garupa-request-configmap-dev
  - group: garupa-request-secret-dev
  - group: garupa-var-dev
  • Variable Groups: Incorporates variable groups for configuration maps, secrets, and other environment-specific variables, centralizing configuration management.

Token Replacement Tasks

steps:
  - task: qetza.replacetokens.replacetokens-task.replacetokens@3
    displayName: "Replace tokens workers"
    ...
  • Token Replacement: Utilizes the Replace Tokens task (qetza.replacetokens.replacetokens-task.replacetokens@3) to replace placeholders in Kubernetes YAML files with actual values from the variable groups. This step is crucial for configuring the application and its environment dynamically.

Base64 Transformation Scripts

- script: |
    #!/bin/bash
    ...
    displayName: "Transform base64 solicitacao secret"
  • Base64 Transformations: Executes bash scripts to convert specified secrets into base64, preparing them for Kubernetes secret objects. This ensures sensitive information is securely handled and applied.

Docker Build and Push

- task: Docker@2
  displayName: buildAndPush
  ...
  • Docker Image Creation: Builds and pushes the Docker image to the specified container registry. It tags the image with the build ID and latest, facilitating versioning and deployment.

Kubernetes Configuration Artifacts

- task: PublishBuildArtifacts@1
  displayName: "Kubernetes YAML"
  ...
  • Kubernetes Artifacts: Publishes Kubernetes YAML files as build artifacts, making them available for deployment stages or for auditing purposes.

Variables and Environments

Key variables such as the VM image name and the project name are defined at the beginning, providing a customizable and flexible approach to different project environments. These variables are crucial for defining the runtime environment and project specifics, ensuring that the pipeline is adaptable to various configurations.

variables:
  vmImageName: "ubuntu-latest"
  projectName: "Garupa-Request"

Building the Application

The Build stage is the first crucial step, where the application is built using the specified VM image. This stage is detailed with tasks like token replacement in Kubernetes YAML files, which is essential for configuring the application according to environment-specific variables and secrets. The process includes steps for handling secrets and configurations dynamically, converting specific values to base64 for Kubernetes compatibility.

stages:
  - stage: Build
    displayName: Build stage
    jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: $(vmImageName)

Deployment to Kubernetes

After building the application, the pipeline proceeds to deploy the updated version to Kubernetes. This process involves replacing image tags with the build ID, ensuring that the most recent image is deployed. The deployment makes use of Docker for building and pushing the image to a container registry, followed by updating Kubernetes deployments with the new image version.

Practical Insights

Automating Secret Management

One of the highlights of this CI/CD pipeline is the automation of secret management. By incorporating scripts to transform certain values to base64 and replacing tokens in configuration files, GARUPA ensures that sensitive information is securely managed and injected into the deployment process without manual intervention.

Dynamic Configuration

The use of replace tokens tasks before deployment allows for dynamic configuration of the application. This flexibility is crucial for adapting to different environments and scenarios, ensuring that the application can be easily configured according to specific requirements.

Streamlining Deployments

By automating the build and deployment processes, GARUPA significantly reduces the risk of human errors, streamlines deployments, and ensures that updates can be rapidly and safely deployed to production environments. This automation is key to maintaining high availability and continuous improvement of the application.

Conclusion

The CI/CD pipeline detailed in this case study showcases a robust approach to automating deployments in a Kubernetes environment using Azure DevOps. By focusing on automation, secret management, and dynamic configuration, GARUPA exemplifies how modern applications can leverage CI/CD pipelines to improve efficiency, security, and scalability in their deployment processes.

For organizations looking to optimize their deployment strategies, this case study serves as a practical guide, demonstrating the benefits of automating CI/CD pipelines and providing a blueprint for implementing similar processes in their projects.

This approach not only saves time and resources but also enhances the reliability and consistency of application deployments, a critical factor in today's fast-paced development landscape.

Subscribe to codingwithalex

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe