Overview:

Jenkins is a well-established and extensively tested CI/CD tool. This article provides a step-by-step guide on deploying Jenkins as a containerized application running in a pod on Google Kubernetes Engine (GKE).

Why should you care:

Jenkins is a well-tested, well-established, and widely used CI/CD tool. As a platform-agnostic technology, it can be deployed on various platforms, each presenting its own unique challenges. This guide specifically addresses the task of deploying Jenkins in a Google Kubernetes Engine (GKE) cluster. This document serves as a comprehensive guide on how to achieve this deployment. Additionally, it provides insights into the intricacies of the deployment process and configuration, shedding light on the underlying mechanisms at work.

Get the code here: https://github.com/bitsector/deploy-jenkins-on-gke/blob/main/deployment.yaml

Let’s begin

Create a node pool specific for Jenkins, we only need one node for the controller:

gcloud container node-pools create devops-pool \\
  --cluster=$CLUSTER_NAME \\
  --machine-type=n1-standard-4 \\
  --num-nodes=1 \\
  --zone=$ZONE \\
  --project=$PROJECT_NAME

Wait for the command to finish, it may take a few minutes.

Get the node name

 kubectl get nodes \\
  -l cloud.google.com/gke-nodepool=devops-pool \\
  | grep -v NAME \\
  | cut -d' ' -f1

Label the node with the “jenkins-node” label

kubectl label nodes <node-name> jenkins-node=true

Create “devops-tool-suite” namespace

kubectl create namespace devops-tool-suite

Create a service account

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: admin-jenkins
rules:
  - apiGroups: [""]
    resources: ["*"]
    verbs: ["*"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-jenkins
  namespace: devops-tool-suite
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-jenkins
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: admin-jenkins
subjects:
- kind: ServiceAccount
  name: admin-jenkins
  namespace: devops-tool-suite