forked from tungbq/devops-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·65 lines (52 loc) · 1.69 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
log() {
local msg=$1
echo "-------------------------"
echo "> $msg"
echo "-------------------------"
}
# Init and configure Helm
log "Adding Jenkins repo and get latest updates"
helm repo add jenkinsci https://charts.jenkins.io
helm repo update
# Create Persistent Volume
log "Create the volume"
kubectl apply -f jenkins-volume.yaml
log "Check the volume"
kubectl get pv
# Create a service account
kubectl apply -f jenkins-sa.yaml
# Update the values manually: Done. TODO: Automate this step
# Deploy
log "Start deploying..."
chart="jenkinsci/jenkins"
# helm install jenkins -n jenkins -f jenkins-values.yaml $chart
helm upgrade --install jenkins -n jenkins -f jenkins-values.yaml $chart
# Check deployment
log "Check deployment"
kubectl get pods -n jenkins
# Waiting for port up and running
pod_name_from_helm="jenkins-0"
while [[ $(kubectl get pods -n jenkins $pod_name_from_helm -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod - $pod_name_from_helm" && sleep 1; done
# Get metadata
log "Get 'admin' password"
jsonpath="{.data.jenkins-admin-password}"
secret=$(kubectl get secret -n jenkins jenkins -o jsonpath="$jsonpath" | xargs -0)
log $(echo $secret | base64 --decode)
# Portforward
## kill prev
log "Kill prev port"
### Run the pgrep command to search for the process running on the port 8090
PID=$(pgrep -f "port-forward 8090:8080")
if [[ "$PID" != "" ]]; then
log "Killing $PID"
kill -9 $PID
fi
log "Port forwarding..."
nohup kubectl port-forward service/jenkins 8090:8080 -n jenkins &
log "Waiting 15s for port forward process completed..."
sleep 15
# login URL
login_url="http://localhost:8090/login"
log $login_url
curl $login_url