GitOps-based CI/CD on Kubernetes: A Guide

Automating Continuous Integration (CI) and Continuous Deployment (CD) on Kubernetes with a GitOps approach provides an efficient way to develop, test, and deploy applications. In this blog post, we demonstrate using CircleCI for continuous integration and Argo CD for continuous deployment on a Kubernetes cluster.

Step 1: Setting up CircleCI

CircleCI automates builds and tests in Kubernetes. By configuring a workflow in a YAML file, we define the steps for CircleCI, including running tests, building Docker images, and pushing these images to a container repository like Docker Hub.

version: 2
jobs:
test:
docker:
– image: circleci/python:3.8
steps:
– checkout
– run: pytest

build:
docker:
– image: docker:19.03.12
steps:
– checkout
– setup_remote_docker
– run: docker build -t myapp:latest .

push:
docker:
– image: docker:19.03.12
steps:
– setup_remote_docker
– run: echo “$DOCKER_PASSWORD” | docker login -u “$DOCKER_USERNAME” –password-stdin
– run: docker push myapp:latest

workflows:
version: 2
build-deploy:
jobs:
– test
– build:
requires:
– test
– push:
requires:
– build

Step 2: Installing and Configuring Argo CD

Argo CD manages continuous deployment on Kubernetes. After installation, we connect Argo CD with GitHub and configure the application for deployment. This involves setting up access permissions, adding clusters, and configuring applications for automatic synchronization.

# Installing Argo CD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.1.4/manifests/install.yaml

# Connecting with GitHub
argocd login localhost:8080
argocd account update-password
argocd cluster add minikube

Step 3: Linking Argo CD with GitHub and Manual Deployment

Argo CD synchronizes deployments with a GitHub repository. By linking with GitHub and configuring the application, we can automate deployments. We also introduce the option to manually trigger synchronization of the application with the repository, offering flexibility and control over the deployment process.

Step 4: Testing the Continuous Deployment Setup

Once configuration is complete, we test the Continuous Deployment system by making a change in the project and triggering a new build of the application. We observe how Argo CD detects the changes and automatically updates the application on the Kubernetes cluster.

Conclusion

With CircleCI for continuous integration and Argo CD for continuous deployment, we have a powerful toolkit for automating Kubernetes workflows. Using a GitOps approach organizes our CI/CD processes around Git, enabling efficient and consistent development.

Through this tutorial, you’ve created a basic pipeline for developing, testing, and deploying applications on Kubernetes. You can use these tools to develop and further customize your own GitOps CI/CD system. For more information on Git and DevOps tools, we recommend our other tutorials and resources.

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: