Skip to content

Instantly share code, notes, and snippets.

@andrehcampos
Last active April 11, 2022 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrehcampos/b93a752999d8edff21bf23dd18bf4fc0 to your computer and use it in GitHub Desktop.
Save andrehcampos/b93a752999d8edff21bf23dd18bf4fc0 to your computer and use it in GitHub Desktop.
[Lab] Jenkins On Kubernetes Engine
# Reference docs:
# https://cloud.google.com/solutions/jenkins-on-kubernetes-engine-tutorial
# https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes
#
# Open a Cloud Shell and run:
# $ curl https://gist.githubusercontent.com/andrehcampos/b93a752999d8edff21bf23dd18bf4fc0/raw/cc8d7d84399d1f4a4f59d43e83227be440084d11/jenkins-on-kubernetes-engine.sh |bash
gcloud config set compute/zone us-east1-d
git clone https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes.git
cd continuous-deployment-on-kubernetes
gcloud compute networks create jenkins
# NOTE: not executed, info only
# $ gcloud compute firewall-rules create <FIREWALL_NAME> --network jenkins --allow tcp,udp,icmp --source-ranges <IP_RANGE>
# $ gcloud compute firewall-rules create <FIREWALL_NAME> --network jenkins --allow tcp:22,tcp:3389,icmp
gcloud container clusters create jenkins-cd \
--network jenkins \
--scopes "https://www.googleapis.com/auth/projecthosting,storage-rw"
gcloud container clusters list
gcloud container clusters get-credentials jenkins-cd
kubectl cluster-info
gcloud compute images create jenkins-home-image --source-uri https://storage.googleapis.com/solutions-public-assets/jenkins-cd/jenkins-home-v3.tar.gz
gcloud compute disks create jenkins-home --image jenkins-home-image --zone us-east1-d
gcloud compute disks list
# NOTE: Jenkins pass
# --argumentsRealm.passwd.jenkins=PASSWORD --argumentsRealm.roles.jenkins=admin
# Your user / password is: jenkins / PASSWORD
PASSWORD=`openssl rand -base64 15`; echo "Your password is $PASSWORD"; sed -i.bak s#CHANGE_ME#$PASSWORD# jenkins/k8s/options
kubectl create ns jenkins
kubectl create secret generic jenkins --from-file=jenkins/k8s/options --namespace=jenkins
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=$(gcloud config get-value account)
kubectl apply -f jenkins/k8s/
kubectl get pods --namespace jenkins
kubectl get svc --namespace jenkins
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /tmp/tls.key -out /tmp/tls.crt -subj "/CN=jenkins/O=jenkins"
kubectl create secret generic tls --from-file=/tmp/tls.crt --from-file=/tmp/tls.key --namespace jenkins
kubectl apply -f jenkins/k8s/lb/ingress.yaml
kubectl describe ingress jenkins --namespace jenkins
@divyang4481
Copy link

jenkins-home-v3.tar.gz does not exist

gcloud compute images create jenkins-home-image --source-uri https://storage.googleapis.com/solutions-public-assets/jenkins-cd/jenkins-home-v3.tar.gz
ERROR: (gcloud.compute.images.create) Could not fetch resource:

  • The resource 'jenkins-cd/jenkins-home-v3.tar.gz' of type 'Google Cloud Storage object' was not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment