Create CI/CD pipeline with Jenkins and Google Kubernetes Engine (GKE)
Welcome to a journey of automation and efficiency! Authors: Akash Acharya & Nishant Nath
In this comprehensive guide, we'll delve into the intricate art of constructing a robust and streamlined CI/CD pipeline. With the prowess of Jenkins, Docker Hub, and GitHub, we'll navigate the intricate pathways of software development, culminating in the seamless deployment of our applications onto the dynamic landscape of a Kubernetes Cluster hosted on Google Kubernetes Engine (GKE). Join us as we unlock the potential of automation, empowering your development endeavors with precision and agility.
Quick summary of the tools
Jenkins: Jenkins is an open-source automation server that facilitates continuous integration (CI) and continuous delivery (CD) pipelines. It automates the building, testing, and deployment of software projects, enabling teams to rapidly deliver high-quality code changes.
Docker Hub: Docker Hub is a cloud-based repository service provided by Docker for storing, sharing, and managing Docker container images. It serves as a centralized platform for developers to access a vast library of pre-built Docker images and collaborate on containerized applications.
GitHub: GitHub is a web-based platform for version control and collaboration, primarily used for hosting Git repositories. It offers features like code review, issue tracking, and project management tools, making it a central hub for software development teams to collaborate on code, manage projects, and track changes efficiently.
Requisites:
We need a running Jenkins server with SSH access to it.
The first step is to prepare Jenkins to work with Docker and Kubernetes. This involves installing Docker and Kubernetes command-line tools on the Jenkins cloud server and installing the Jenkins GKE plugin.
Install docker on the Jenkins server following this link.
Install the "Docker Pipeline" & "Google Kubernetes Engine" plugins in Jenkins from the 'Dashboard > Manage Jenkins > Manage Plugins page
STEP - 2: Service account and key setup
Jenkins will interact with the Kubernetes cluster using a Google Cloud Platform service account. For this, we need to set up the service account and give it API access.
Next, navigate to the "IAM & admin > Service accounts" page and create a new service account. For this demo, I have created a service account with the name "Jenkins" Assign the "Kubernetes Engine Admin" role.
Next, create a new JSON key for the service account. Download and save this key, as it will be needed by Jenkins.
STEP - 3: Setting up Credentials in Jenkins
We will use the Jenkins credentials store for the pipeline to communicate with the Kubernetes cluster and the Docker Hub registry
Navigate to the "Dashboard > Manage Jenkins > Manage Credentials" menu item.
Select the "System" sub-menu" and the "Global credentials" domain
Click the "Add credentials" link. Select the "Username with password" credential type and enter your Docker Hub username and password in the corresponding fields. Set the "ID" field to dockerID. Click "OK" to save the changes
Click the "Add credentials" link. Select the "Google Service Account from private key" credential type and set the project name (which doubles as the credential identifier) to multi-k8s. Select the "JSON key" radio button and upload the JSON key obtained in the previous step in Setting up the GCP Account. Click "OK" to
Build the pipeline in Jenkins and it should be complete with success till the Deploy to GKE step, which would indicate that it is working fine.
Login to the GCP console and navigate to the Kubernetes Engine > Services & Ingress. Your application should be listed there
Click the Endpoint link and your Web page should greet with you a Happy message.
In conclusion, by harnessing the power of Jenkins, Docker Hub, GitHub, and Google Kubernetes Engine, we've not just built a CI/CD pipeline, but we've paved the road to seamless deployment nirvana. Embrace automation, empower your development journey, and let your code take flight with the wings of innovation.
Happy deploying, fellow tech enthusiasts!
Subscribe to our newsletter
Stay updated with industry trends, expert tips, case studies, and exclusive Tweeny updates to help you build scalable and innovative solutions.