本系列文章:node
第一章:九析帶你輕鬆完爆 helm3 安裝
第二章:九析帶你輕鬆完爆 helm3 公共倉庫nginx第三章:九析帶你輕鬆完爆 helm3 私有倉庫git
第四章:九析帶你輕鬆完爆 helm3 chartapi
第五章:九析帶你輕鬆完爆 helm3 release瀏覽器
第六章:九析帶你輕鬆完爆 helm3 gitlab服務器
第七章:九析帶你輕鬆完爆 helm3 nginx-ingressapp
第八章:九析帶你輕鬆完爆 helm3 gitlab nfside
第九章:九析帶你輕鬆完爆 helm3 nexusgitlab
第十章:九析帶你輕鬆完爆 helm3 heapsterfetch
目錄
1 前言
2 下載 Prometheus
3 建立 prometheus 命名空間
4 安裝 prometheus
4.1 修改 deployment apiVersion
4.2 添加 daemonset selector
4.3 添加 deployment selector
4.4 修改 ingress apiVersion
4.5 驗證 prometheus 安裝
5 安裝 nfs
6 建立 pv
7 驗證 prometheus
8 修改 service type
9 訪問 prometheus
1 前言
本文采用 helm v3.0.0;k8s v1.16.3。
2 下載 Prometheus
helm 搜索 Prometheus:
helm search repo prometheus
helm 下載解壓 Prometheus:
helm fetch stable/prometheus
tar -zxvf prometheus-5.4.0.tgz
3 建立 prometheus 命名空間
kubectl create ns prometheus
4 安裝 prometheus
第一個 prometheus 是 helm release 名,第二個是命名空間,第三個是 prometheus 本地解壓縮目錄。
helm install prometheus -n prometheus prometheus
4.1 修改 deployment apiVersion
若是在安裝過程當中有以下錯誤:
Error: unable to build kubernetes objects from release manifest: unable to recognize "": no matches for kind "Deployment" in version "extensions/v1beta1"
執行以下語句輕鬆完爆:
grep -irl 'extensions/v1beta1' prometheus/ | xargs sed -i 's#extensions/v1beta1#apps/v1#g'
4.2 添加 daemonset selector
若是再次安裝有以下錯誤:
Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(DaemonSet.spec): missing required field "selector" in io.k8s.api.apps.v1.DaemonSetSpec
編輯 templates/node-exporter-daemonset.yaml 文件,添加以下內容:
4.3 添加 deployment selector:
再次安裝若是報以下錯:
Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec
編輯 templates/alertmanager-deployment.yaml 文件,添加以下內容:
編輯 templates/kube-state-metrics-deployment.yaml 文件,添加以下內容:
編輯 templates/pushgateway-deployment.yaml 文件,添加以下內容:
編輯 templates/server-deployment.yaml 文件,添加以下內容:
4.4 修改 ingress apiVersion
再次安裝若是報以下錯:
Error: unable to build kubernetes objects from release manifest: unable to recognize "": no matches for kind "Ingress" in version "apps/v1"
編輯 templates/alertmanager-ingress.yaml 文件,將 apps/v1 修改成 extenstions/v1beta1:
4.5 驗證 prometheus 安裝
若是執行安裝後,顯示以下內容:
執行以下操做語句,若是出現以下結果,則說明安裝成功:
helm list -n prometheus
但安裝成功,並不表明運行成功。還須要作進一步的配置。
5 安裝 nfs
如何安裝 nfs 服務器,請參考本人《輕鬆完爆 nfs 安裝》,不用擔憂,簡單到爆,讓你分分鐘輕鬆完爆。
mkdir -p /data/nfs/prometheus/2g
mkdir -p /data/nfs/prometheus/8g
chmod 777 -R /data/nfs/prometheus
systemctl restart nfs
6 建立 pv
安裝完 nfs 後,查看 prometheus pvc:
kubectl get pvc -n prometheus
發現 pvc 處於 pending 狀態,緣由在於並無可用的 pv 能夠使用,須要手動建立 pv。
發現 pvc 的申請規格有 2 種,分別是 2Gi 和 8Gi。下面分別建立 pv 資源文件, 注意這裏的 server 地址就是 nfs 服務器所在地址。
建立 pv-prometheus-2g.yaml 文件,內容以下:
apiVersion: v1
kind: PersistentVolume
metadata:
name: prometheus-2g
spec:
capacity:
storage: 2Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
nfs:
server: 10.110.101.106
path: /data/nfs/prometheus/2g
建立 pv-prometheus-8g.yaml 文件,內容以下:
apiVersion: v1
kind: PersistentVolume
metadata:
name: prometheus-8g
spec:
capacity:
storage: 8Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
nfs:
server: 10.110.101.106
path: /data/nfs/prometheus/8g
執行以下語句建立 pv:
kubectl apply -f pv-prometheus-2g.yaml
kubectl apply -f pv-prometheus-8g.yaml
查看 pvc 狀態:
kubectl get pvc -n prometheus
自此,pvc 和 pv 已經關聯。
7 驗證 prometheus
查看 prometheus pod 運行狀態,發現 prometheus-server 並無啓動成功:
kubectl get pod -n prometheus
查看容器日誌狀態發現報以下錯誤:
err="Error loading config couldn't load configuration (--config.file=/etc/config/prometheus.yml): parsing YAML file /etc/config/prometheus.yml: yaml: line 160: mapping values are not allowed in this context"
解決方案:
kubectl edit configmap -n prometheus prometheus-prometheus-server
定位 「target_label: kubernetes_pod_namealerting:」
修改成:
修改完保存退出,而後刪除 prometheus-prometheus-server pod,讓控制器再從新生成新的 pod,從而讀取修改過的 configmap 信息。再次查看整個 pod 狀態,發現所有啓動成功:
8 修改 service type
將 prometheus service type 修改成 NodePort 類型:
kubectl patch svc -n prometheus prometheus-prometheus-server -p '{"spec": {"type": "NodePort"}}'
kubectl get svc -n prometheus
9 訪問 prometheus
打開瀏覽器,訪問 prometheus-server,注意端口正確,本人是 30347:
自此,helm3 安裝 prometheus 輕鬆完爆。