Deploy a Python web application on GKE using CI/CD Jenkins Pipeline using the following steps and high-level diagram:
- Implement a secure GKE Cluster
- Deploy and configure Jenkins on GKE
- Deploy the backend application on GKE using the Jenkins pipeline
Project.Demo.mp4
Tool | Purpose |
---|---|
Google Kubernetes Engine (GKE) | Google Kubernetes Engine (GKE) is a managed, production-ready environment for running containerized applications. |
Jenkins | Jenkins – an open-source automation server is enabling developers worldwide to reliably build, test, and deploy their software. |
Helm | Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes applications. |
Docker | Docker is a set of platform-as-a-service (PaaS) products that use OS-level virtualization to deliver software in containers |
Terraform | Terraform is an open-source infrastructure as a code software tool that enables you to safely and predictably create, change, and improve infrastructure. |
- Two subnets one for GKE and another for Bastion Host - NAT Gateway - Firewall to allow SSH Connection
- private container cluster resource with authorized networks configuration - node pool with count 3
- for Creating a Private VM to Connect with GKE Cluster
git clone hhttps://github.com/OmarMFathy219/ITI-Final-CI-CD-Project.git
After you clone the code you need to navigate to the
terraform
folder to build the infrastructure:
cd terraform/
terraform init
terraform plan
terraform apply
Now after the Infrastructure is built navigate to
Compute Engine
from the GCP console thenVM instances
and click the SSH toprivate-vm2
to run these commands:
sudo apt-get install kubectl
sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
gcloud auth login
to set your active Application Default Credentials to your account run these commands:
gcloud auth application-default login
Go to the
Kubernetes Engine
Page in yourClusters
tab you will find theprivate-cluster
Click on the
Action button
"Three dots" thenConnect
, Copy the command and paste it into theVM SSH window
gcloud container clusters get-credentials private-cluster --zone us-central1-a --project <Your-Project-ID>
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
sudo apt-get install apt-transport-https --yes
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
pull Jenkins with helm
helm repo add jenkins https://charts.jenkins.io
helm repo update
helm pull --untar jenkins/jenkins
cd jenkins
vim values.yaml
Replace the
ServiceType
value fromClusterIP
toLoadBlancer
in Line 129:
serviceType: LoadBalancer
Replace the
All InstallPlugins
version with thelatest
in line 241
installPlugins:
- kubernetes:latest
- workflow-aggregator:latest
- git:latest
- configuration-as-code:latest
Save the file and go back to the home directory
cd ..
helm install jenkins ./jenkins -n jenkins
kubectl exec --namespace jenkins -it svc/jenkins2 -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo
export SERVICE_IP=$(kubectl get svc --namespace jenkins jenkins2 --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
echo http://$SERVICE_IP:8080/login
- Build an image from Dockerfile
- Push the image to DockerHub
- Apply deployment for the app based on the image
- Apply LoadBalancer service for the app
Add your DockerHub Credentials
(Username and Password)
and save the id with this valueDockerHub-Cred
.
Go to GCP Console and navigate to
Service accounts
from theIAM & Admin
page.
Click on your
Service accounts
then click on theKEYS
Tab thenAdd Key
thenCreate new key
, forKey type
SelectJSON
Now go to Jenkins and Make a New credential, select
Secret
forcredentials kind
then upload the Service Account you just downloaded. NOTE: forSecret ID
enterService-Account-Cred
.
- Pull Code from GitHub
- Build the Application image using Docker
- Push Image to DockerHub
- Trigger CD Pipeline to Run
- Deploy our Application in GKE
terraform destroy