Last active
April 21, 2024 04:33
-
-
Save vfarcic/b0a32051da5ae3dea09e596689d7cf24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://gist.github.com/b0a32051da5ae3dea09e596689d7cf24 | |
################################# | |
# Running Jenkins In Kubernetes # | |
# Tutorial And Review # | |
# https://youtu.be/2Kc3fUJANAc # | |
################################# | |
# Referenced videos: | |
# - GitHub CLI - How to manage repositories more efficiently: https://youtu.be/BII6ZY2Rnlc | |
# - Kaniko - Building Container Images In Kubernetes Without Docker: https://youtu.be/EgwVQN6GNJg | |
# - Kustomize - How to Simplify Kubernetes Configuration Management: https://youtu.be/Twtbg6LFnAg | |
######### | |
# Setup # | |
######### | |
# Create a Kubernetes cluster with NGINX Ingress | |
gh repo fork vfarcic/jenkins-demo \ | |
--clone | |
cd jenkins-demo | |
# If NOT EKS | |
export INGRESS_HOST=$(kubectl \ | |
--namespace ingress-nginx \ | |
get svc ingress-nginx-controller \ | |
--output jsonpath="{.status.loadBalancer.ingress[0].ip}") | |
# If EKS | |
export INGRESS_HOSTNAME=$(kubectl \ | |
--namespace ingress-nginx \ | |
get svc ingress-nginx-controller \ | |
--output jsonpath="{.status.loadBalancer.ingress[0].hostname}") | |
# If EKS | |
export INGRESS_HOST=$(\ | |
dig +short $INGRESS_HOSTNAME) | |
echo $INGRESS_HOST | |
# Repeat the `export` commands if the output is empty | |
# If the output contains more than one IP, wait for a while longer, and repeat the `export` commands. | |
# If the output continues having more than one IP, choose one of them and execute `export INGRESS_HOST=[...]` with `[...]` being the selected IP. | |
export REGISTRY_SERVER=https://index.docker.io/v1/ | |
# Replace `[...]` with the registry username | |
export REGISTRY_USER=[...] | |
# Replace `[...]` with the registry password | |
export REGISTRY_PASS=[...] | |
# Replace `[...]` with the registry email | |
export REGISTRY_EMAIL=[...] | |
cat kustomize/base/ingress.yaml \ | |
| sed -e "[email protected]@jenkins-demo.$INGRESS_HOST.nip.io@g" \ | |
| tee kustomize/overlays/production/ingress.yaml | |
cat kustomize/base/ingress.yaml \ | |
| sed -e "[email protected]@jenkins-demo.$INGRESS_HOST.nip.io@g" \ | |
| tee kustomize/overlays/preview/ingress.yaml | |
cat Jenkinsfile \ | |
| sed -e "s@vfarcic@$REGISTRY_USER@g" \ | |
| sed -e "[email protected]@$INGRESS_HOST.nip.io@g" \ | |
| tee Jenkinsfile | |
cat jenkins-values.yaml \ | |
| sed -e "s@hostName: .*@hostName: jenkins.$INGRESS_HOST.nip.io@g" \ | |
| tee jenkins-values.yaml | |
kubectl create namespace production | |
kubectl create namespace previews | |
###################### | |
# Installing Jenkins # | |
###################### | |
pwd | |
helm repo add jenkinsci https://charts.jenkins.io | |
helm repo update | |
gh repo view jenkinsci/helm-charts --web | |
cat jenkins-values.yaml | |
helm upgrade --install \ | |
jenkins jenkinsci/jenkins \ | |
--namespace jenkins \ | |
--create-namespace \ | |
--values jenkins-values.yaml \ | |
--wait | |
######################### | |
# Creating Jenkins jobs # | |
######################### | |
echo http://jenkins.$INGRESS_HOST.nip.io | |
# Open it in browser | |
kubectl --namespace jenkins \ | |
get secret jenkins \ | |
--output jsonpath="{.data.jenkins-admin-password}" \ | |
| base64 --decode && echo | |
######################### | |
# Exploring Jenkinsfile # | |
######################### | |
cat Jenkinsfile | |
######################### | |
# Exploring PodTemplate # | |
######################### | |
cat jenkins-pod.yaml | |
kubectl --namespace jenkins \ | |
create secret \ | |
docker-registry regcred \ | |
--docker-server $REGISTRY_SERVER \ | |
--docker-username $REGISTRY_USER \ | |
--docker-password $REGISTRY_PASS \ | |
--docker-email $REGISTRY_EMAIL | |
################################## | |
# Defining roles and permissions # | |
################################## | |
cat roles.yaml | |
kubectl apply --filename roles.yaml | |
############################ | |
# Creating GitHub webhooks # | |
############################ | |
gh repo view --web | |
echo http://jenkins.$INGRESS_HOST.nip.io/github-webhook/ | |
# Copy and paste the address into the webhook *Payload URL* field | |
########################### | |
# Creating a pull request # | |
########################### | |
git checkout -b my-feature | |
# Open config.toml and change something | |
git add . | |
git commit -m "Is this a new feature?" | |
git push --set-upstream origin my-feature | |
gh pr create \ | |
--title "My feature" \ | |
--body "I'm too lazy to write descriptions" | |
##################### | |
# Building mainline # | |
##################### | |
gh repo view --web | |
# Navigate to the PR and merge it. | |
git checkout master | |
git pull | |
echo http://jenkins-demo.$INGRESS_HOST.nip.io | |
# Open it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment