-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
MyImageRepositoryIP=`cat components.txt |grep "Harbor Address" |awk '{print $3}'` | ||
MyImageRepositoryProject=library | ||
KubePrometheusVersion=`cat components.txt |grep "KubePrometheus Version" |awk '{print $3}'` | ||
NAMESPACE=monitoring | ||
|
||
######### Push images ######### | ||
docker load -i file/kube-prometheus-images-v$KubePrometheusVersion.tar | ||
|
||
for file in $(cat file/images-list.txt); do docker tag $file $MyImageRepositoryIP/$MyImageRepositoryProject/${file##*/}; done | ||
|
||
echo 'Images taged.' | ||
|
||
for file in $(cat file/images-list.txt); do docker push $MyImageRepositoryIP/$MyImageRepositoryProject/${file##*/}; done | ||
|
||
echo 'Images pushed.' | ||
|
||
######### Update deploy yaml files ######### | ||
cd file | ||
rm -rf kube-prometheus-$KubePrometheusVersion | ||
tar zxvf kube-prometheus-v$KubePrometheusVersion-origin.tar.gz | ||
cd kube-prometheus-$KubePrometheusVersion | ||
sed -i "s/quay.io\/coreos/$MyImageRepositoryIP\/$MyImageRepositoryProject/g" $(grep -lr "quay.io/coreos" ./ |grep .yaml) | ||
sed -i "s/quay.io\/prometheus/$MyImageRepositoryIP\/$MyImageRepositoryProject/g" $(grep -lr "quay.io/prometheus" ./ |grep .yaml) | ||
sed -i "s/grafana\/grafana/$MyImageRepositoryIP\/$MyImageRepositoryProject\/grafana/g" $(grep -lr "grafana/grafana" ./ |grep .yaml) | ||
sed -i "s/gcr.io\/google_containers/$MyImageRepositoryIP\/$MyImageRepositoryProject/g" $(grep -lr "gcr.io/google_containers" ./ |grep .yaml) | ||
sed -i "s/k8s.gcr.io/$MyImageRepositoryIP\/$MyImageRepositoryProject/g" $(grep -lr "k8s.gcr.io" ./ |grep .yaml) | ||
|
||
# Wait for CRDs to be ready, we need to split all yaml files to two parts | ||
mkdir phase2 | ||
mv manifests/0prometheus-operator-serviceMonitor.yaml phase2/ | ||
mv manifests/alertmanager-alertmanager.yaml phase2/ | ||
mv manifests/alertmanager-serviceMonitor.yaml phase2/ | ||
mv manifests/kube-state-metrics-serviceMonitor.yaml phase2/ | ||
mv manifests/node-exporter-serviceMonitor.yaml phase2/ | ||
mv manifests/prometheus-prometheus.yaml phase2/ | ||
mv manifests/prometheus-rules.yaml phase2/ | ||
mv manifests/prometheus-serviceMonitor.yaml phase2/ | ||
mv manifests/prometheus-serviceMonitorApiserver.yaml phase2/ | ||
mv manifests/prometheus-serviceMonitorCoreDNS.yaml phase2/ | ||
mv manifests/prometheus-serviceMonitorKubeControllerManager.yaml phase2/ | ||
mv manifests/prometheus-serviceMonitorKubeScheduler.yaml phase2/ | ||
mv manifests/prometheus-serviceMonitorKubelet.yaml phase2/ | ||
mv manifests/grafana-serviceMonitor.yaml phase2/ | ||
mv manifests phase1 | ||
mkdir manifests | ||
mv phase1 manifests | ||
mv phase2 manifests | ||
|
||
######### Deploy prometheus operator and kube-prometheus ######### | ||
|
||
kctl() { | ||
kubectl --namespace "$NAMESPACE" "$@" | ||
} | ||
|
||
kubectl apply -f manifests/phase1 | ||
|
||
# Wait for CRDs to be ready. | ||
printf "Waiting for Operator to register custom resource definitions..." | ||
|
||
crd_servicemonitors_status="false" | ||
until [ "$crd_servicemonitors_status" = "True" ]; do sleep 1; printf "."; crd_servicemonitors_status=`kctl get customresourcedefinitions servicemonitors.monitoring.coreos.com -o jsonpath='{.status.conditions[1].status}' 2>&1`; done | ||
|
||
crd_prometheuses_status="false" | ||
until [ "$crd_prometheuses_status" = "True" ]; do sleep 1; printf "."; crd_prometheuses_status=`kctl get customresourcedefinitions prometheuses.monitoring.coreos.com -o jsonpath='{.status.conditions[1].status}' 2>&1`; done | ||
|
||
crd_alertmanagers_status="false" | ||
until [ "$crd_alertmanagers_status" = "True" ]; do sleep 1; printf "."; crd_alertmanagers_status=`kctl get customresourcedefinitions alertmanagers.monitoring.coreos.com -o jsonpath='{.status.conditions[1].status}' 2>&1`; done | ||
|
||
until kctl get servicemonitors.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done | ||
until kctl get prometheuses.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done | ||
until kctl get alertmanagers.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done | ||
|
||
echo 'Phase1 done!' | ||
|
||
kubectl apply -f manifests/phase2 | ||
cd ../../ | ||
|
||
echo 'Phase2 done!' | ||
|
||
kubectl apply -f template/prometheus-service.yaml | ||
kubectl apply -f template/alertmanager-service.yaml | ||
kubectl apply -f template/grafana-service.yaml | ||
|
||
echo 'NodePorts are set for services.' | ||
|
||
kubectl apply -f addon/k8s | ||
|
||
echo 'Kube-Prometheus is installed.' | ||
|
||
#kubectl apply -f addon/etcd-monitor.yaml |