๐ Deploying a React.js App Using Helm on Kubernetes: A Step-by-Step Guide with CI/CD ๐
Written by Sivaranjan with sample notes
In today's fast-paced tech environment, continuous deployment and integration are critical for maintaining competitive advantage. One of the most efficient ways to manage your deployments is through Kubernetes and Helm. Today, I will share how I deployed a React.js app using Helm with CI/CD stages including SCM checkout, SonarQube analysis, Docker build, Docker push, and Kubernetes deployment. Let's dive in! ๐
๐ฏ Objectives
Checkout Code from Source Control Management (SCM)
Analyze Code Quality with SonarQube
Build Docker Image of the React.js app
Push Docker Image to a Registry
Deploy Application on Kubernetes using Helm
๐ ๏ธ Tools Used
SCM: GitHub
Code Quality: SonarQube
Containerization: Docker
Container Registry: Docker Hub
Orchestration: Kubernetes (K8s)
Package Manager: Helm
CI/CD: Jenkins
๐ Prerequisites
A running Kubernetes cluster
Helm installed
Jenkins for CI/CD pipeline
SonarQube server
Docker Hub account
๐ Step 1: SCM Checkout ๐๏ธ
Start by checking out the code from your GitHub repository. This is typically the first step in your Jenkins pipeline.
stage('SCM Checkout') {
steps {
git 'https://github.com/your-username/your-repo.git'
}
}
๐ Step 2: SonarQube Analysis ๐งน
Next, analyze the code quality using SonarQube. This ensures your code adheres to the required standards and is free of critical bugs.
stage('SonarQube Analysis') {
steps {
script {
def scannerHome = tool 'SonarQubeScanner'
withSonarQubeEnv('SonarQube') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
๐๏ธ Step 3: Docker Build ๐ณ
Build the Docker image for the React.js app. This encapsulates your app and its dependencies into a portable container.
stage('Docker Build') {
steps {
script {
docker.build("your-username/your-app:${env.BUILD_ID}")
}
}
}
๐ Step 4: Docker Push ๐ค
Push the Docker image to Docker Hub. This makes your image available for deployment.
stage('Docker Push') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials') {
docker.image("your-username/your-app:${env.BUILD_ID}").push()
}
}
}
}
๐ฆ Step 5: Deploy on Kubernetes using Helm ๐ณ๏ธ
Finally, deploy your app on Kubernetes using Helm. Helm simplifies the deployment process by managing Kubernetes manifests as charts.
stage('Helm Deploy') {
steps {
script {
sh "helm upgrade --install my-app ./helm-chart --set image.tag=${env.BUILD_ID}"
}
}
}
๐ Conclusion
Deploying a React.js application on Kubernetes using Helm, while incorporating a robust CI/CD pipeline, ensures your application is always up-to-date, reliable, and scalable. Leveraging tools like Jenkins, SonarQube, Docker, and Helm allows for seamless automation and efficient management of your application lifecycle. ๐
By following these steps, you can achieve continuous deployment and integration with minimal manual intervention, allowing your development team to focus on building amazing features and improving code quality. Happy coding! ๐