- Deploy jenkins as pod on GKE cluster
- Use pods as agents to build and deploy application
- Create a jenkins ci/cd pipeline to deploy a nodejs app on GKE cluster
- Clone repository
- Edit project_id in terraform.tfvars with your project id and edit provider configuration
# initialize terraform
terraform init
# check plan
terraform plan
# apply the plan it will take some time to complete 😴
terraform apply --auto-approve
$ gcloud container clusters get-credentials gke-cluster --zone us-central1-a --project anwer-gcp ; gcloud compute ssh bastion-vm --project anwer-gcp --zone us-central1-a -- -4 -L8888:localhost:8888 -N -q -f && export HTTPS_PROXY=localhost:8888
kubectl apply -f ./jenkins/namespace.yaml
kubectl apply -Rf ./jenkins
$ kubectl get po -n jenkins-ns
NAME READY STATUS RESTARTS AGE
jenkins-server-65b987d59-gm9k4 1/1 Running 0 2m34s
$ kubectl exec -n jenkins-ns -it jenkins-server-65b987d59-gm9k4 -- /bin/bash
# inside pod
$ mkdir /var/jenkins_home/.kube
$ exit
# copy config file to jenkins pod
DevOps:$ kubectl cp -n jenkins-ns ~/.kube/config jenkins-server-65b987d59-gm9k4:/var/jenkins_home/.kube/config
goto MangeJenkins => Manage nodes and cloud => configure clouds => kubernetes
$ kubectl describe service jenkins-jnlp -n jenkins-ns
Endpoints: 10.48.0.24:50000
Create a pipeline to build nodejs_app on GKE cluster
Using a declarative pipeline to deploy the application on GKE cluster
Link to pipeline script
start by init ansible galaxy
ansible-galaxy init jenkins
terraform destroy --auto-approve
- Integrate jenkins with github webhooks for automatic ci/cd
- Integrate with slack for notifications
- Create infrastructure pipeline to provision the infrastructure on GCP (optional)
- Use helm to deploy the application on GKE cluster (optional)
- Create a dev and prod environment for the application and infrastructure
- Backup the jenkins_home directory to a bucket (optional)
This Article and kubernetes plugins Documentation I used to configure Docker with jenkins and dynamic agent
Application repository: contain the application code and the pipeline script