Setting up private GKE automation using Terraform
Automate private Google Kubernetes Engine (GKE) deployment using Terraform for secure, scalable, and efficient cloud infrastructure.
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.
Requisites:
STEP - 1: Installation and configuration
STEP - 2: Service account and key setup
STEP - 3: Setting up Credentials in Jenkins
STEP- 4: Jenkins Pipeline Setup
1pipeline {
2 agent any
3 environment {
4 PROJECT_ID = <Your Project ID>
5 CLUSTER_NAME = < Your cluster name >
6 LOCATION = < Your region name >
7 CREDENTIALS_ID = “oceanic-granite-383005” // service account credential name
8 }
9
10 stages {
11 stage("Checkout code") {
12 steps {
13 git branch: 'main', url: < Your repository URL >
14 }
15 }
16 stage("Build image") {
17 steps {
18 script {
19 myapp = docker.build("<docker_repo_url>/<docker_image_name>:<docker_image_tag>>")
20 }
21 }
22 }
23
24 stage("Push image") {
25 steps {
26 script {
27 docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
28 myapp.push("latest")
29
30 }
31 }
32 }
33 }
34 stage('Deploy to GKE') {
35 steps{
36 step([
37 $class: 'KubernetesEngineBuilder',
38 projectId: env.PROJECT_ID,
39 clusterName: env.CLUSTER_NAME,
40 location: env.LOCATION,
41 manifestPattern: 'deployment.yml',
42 credentialsId: env.CREDENTIALS_ID,
43 verifyDeployments: true
44 ])
45 }
46 }
47 }
48}
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: deploy
5 labels:
6 app: node
7spec:
8 replicas: 1
9 selector:
10 matchLabels:
11 app: node
12 template:
13 metadata:
14 labels:
15 app: node
16 spec:
17 containers:
18 - name: node
19 image: <docker_repo_url>/<docker_image_name>:<docker_image_tag>
20 ports:
21 - containerPort: 4000
22
23
24 ---
25
26apiVersion: v1
27kind: Service
28metadata:
29 labels:
30 app: node
31 name: hello
32spec:
33 ports:
34 - port: 4000
35 protocol: TCP
36 targetPort: 4000
37 selector:
38 app: node
39 sessionAffinity: None
40 type: LoadBalancer
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!