Skip to content

Commit

Permalink
Initialled by Alan
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpeng committed Nov 22, 2019
1 parent 58a3702 commit 8a75fc1
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ cd install-kube-prometheus
bash deploy.sh
```

注意deploy.sh适合K8s 1.16及以上版本,如果是K8s 1.15及以下,则使用以下命令:

```
cd install-kube-prometheus
bash deploy-on-k8s-1.15-and-lower.sh
```

**4. 删除Kube-Prometheus**

执行命令:
Expand Down
93 changes: 93 additions & 0 deletions deploy-on-k8s-1.15-and-lower.sh
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

0 comments on commit 8a75fc1

Please sign in to comment.