Prometheus+Grafana+Pushgateway部署
部署Prometheus&Grafana
step1.下载项⽬git项⽬
git clone github/coreos/kube-prometheus.git
step2.拉取镜像
因为某些镜像被墙了,所以需要⼿动从阿⾥云上拉取镜像
该镜像是kube-state-metrics部署中所需要的⼀个镜像,下⾯进⾏镜像下载:
addon-resizer
sudo docker pull mirrorgooglecontainers/addon-resizer:1.8.4
#显⽰以下信息则代表下载成功
1.8.4: Pulling from mirrorgooglecontainers/addon-resizer
Digest:sha256:737c634a95f04bffbcd8d3a833745cc26d4d42e8a759ca75b8b8b407ef40b780
Status: Image is up to date for mirrorgooglecontainers/addon-resizer:1.8.4
docker.io/mirrorgooglecontainers/addon-resizer:1.8.4
#然后将仓库名称:tag修改成部署的yaml⽂件对应的信息。
sudo docker tag mirrorgooglecontainers/addon-resizer:1.8.io/addon-resizer:1.8.4
prometheus
#从阿⾥云拉取镜像
sudo docker pull registry-hangzhou.aliyuncs/google_containers/prometheus
#显⽰以下信息代表镜像拉取成功
Using default tag: latest
latest: Pulling from google_containers/prometheus
Digest: sha256:a36643ecff25461626eb259e11309dbbff400839a0a90e2dea19c34267abd0a3
Status: Image is up to date for registry-hangzhou.aliyuncs/google_containers/prometheus:latest
registry-hangzhou.aliyuncs/google_containers/prometheus:latest
#修改tag
sudo docker tag registry-hangzhou.aliyuncs/google_containers/prometheus quay.io/prometheus/prometheus
其余的镜像在部署过程中可以正常下载,在后续的同学的部署中如果遇到镜像不能下载,可以⾃⼰寻镜像⽹站进⾏下载并修改tag。step3. 修改grafana-service.yaml
进⼊下载好的项⽬中修改yaml⽂件,使得外⽹可以通过nodePort⽅式访问Grafana:
cd ~/kube-prometheus/manifests
vim grafana-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: grafana
name: grafana
namespace: monitoring
spec:
type: NodePort #增加类型NodePort
ports:
- name: http
nodePort: 30006 #⼿动设定访问端⼝30006
port: 3000
targetPort: http
selector:
app: grafana
step4. 修改prometheus-service.yaml
进⼊下载好的项⽬中修改yaml⽂件,使得外⽹可以通过nodePort⽅式访问prometheus
apiVersion: v1
kind: Service
metadata:
labels:
prometheus: k8s
name: prometheus-k8s
namespace: monitoring
spec:
type: NodePort #增加类型NodePort
ports:
- name: web
port: 9090
nodePort: 30007#⼿动设定访问端⼝30007
targetPort: web
selector:
app: prometheus
prometheus: k8s
sessionAffinity: ClientIP
step5.开始部署prometheus + grafana
在开始之前,确认你的manifests⽬录下有这些yaml⽂件
cd ~/kube-prometheus/manifests
ls
00namespace-namespace.yaml                                        node-exporter-clusterRole.yaml
0prometheus-operator-0alertmanagerCustomResourceDefinition.yaml    node-exporter-daemonset.yaml
0prometheus-operator-0prometheusCustomResourceDefinition.yaml      node-exporter-serviceAccount.yaml
0prometheus-operator-0prometheusruleCustomResourceDefinition.yaml  node-exporter-serviceMonitor.yaml
0prometheus-operator-0servicemonitorCustomResourceDefinition.yaml  node-exporter-service.yaml
0prometheus-operator-clusterRoleBinding.yaml                      prometheus-adapter-apiService.yaml
0prometheus-operator-clusterRole.yaml                              prometheus-adapter-clusterRoleAggregatedMetricsReader.yaml
0prometheus-operator-deployment.yaml                              prometheus-adapter-clusterRoleBindingDelegator.yaml
0prometheus-operator-serviceAccount.yaml                          prometheus-adapter-clusterRoleBinding.yaml
0prometheus-operator-serviceMonitor.yaml                          prometheus-adapter-clusterRoleServerResources.yaml
nodeselector
0prometheus-operator-service.yaml                                  prometheus-adapter-clusterRole.yaml
alertmanager-alertmanager.yaml                                    prometheus-adapter-configMap.yaml
alertmanager-secret.yaml                                          prometheus-adapter-deployment.yaml
alertmanager-serviceAccount.yaml                                  prometheus-adapter-roleBindingAuthReader.yaml
alertmanager-serviceMonitor.yaml                                  prometheus-adapter-serviceAccount.yaml
alertmanager-service.yaml                                          prometheus-adapter-service.yaml
grafana-dashboardDatasources.yaml                                  prometheus-clusterRoleBinding.yaml
grafana-dashboardDefinitions.yaml                                  prometheus-clusterRole.yaml
grafana-dashboardSources.yaml                                      prometheus-prometheus.yaml
grafana-deployment.yaml                                            prometheus-roleBindingConfig.yaml
grafana-serviceAccount.yaml                                        prometheus-roleBindingSpecificNamespaces.yaml
grafana-serviceMonitor.yaml                                        prometheus-roleConfig.yaml
grafana-service.yaml                                              prometheus-roleSpecificNamespaces.yaml
kube-state-metrics-clusterRoleBinding.yaml                        prometheus-rules.yaml
kube-state-metrics-clusterRole.yaml                                prometheus-serviceAccount.yaml
kube-state-metrics-deployment.yaml                                prometheus-serviceMonitorApiserver.yaml
kube-state-metrics-roleBinding.yaml                                prometheus-serviceMonitorCoreDNS.yaml
kube-state-metrics-role.yaml                                      prometheus-serviceMonitorKubeControllerManager.yaml
kube-state-metrics-serviceAccount.yaml                            prometheus-serviceMonitorKubelet.yaml
kube-state-metrics-serviceMonitor.yaml                            prometheus-serviceMonitorKubeScheduler.yaml
kube-state-metrics-service.yaml                                    prometheus-serviceMonitor.yaml
node-exporter-clusterRoleBinding.yaml                              prometheus-service.yaml
确认⽆误之后,开始下⾯的步骤
cd ~/kube-prometheus
kubectl create -f manifests/ || true
#由于部署所需的资源中存在竞争性,即前⾯的服务部署可能需要⽤到后⾯的安装的资源,所以下⾯的apply命令可能需要执⾏两遍kubectl apply -f manifests/ 2>/dev/null || true
#再次执⾏该命令
kubectl apply -f manifests/ 2>/dev/null || true
#查看部署的pod信息
kubectl  get pod -n monitoring -o wide
#节点部署信息
alertmanager-main-0                  2/2    Running  0          17h  10.244.1.29    hp-55  <none>          <none> alertmanager-main-1                  2/2    Running  0          17h  10.244.4.26    hp-52  <none>          <none> alertmanager-main-2                  2/2    Running  0          17h  10.244.3.30    hp-51  <none>          <none>
grafana-57bfdd47f8-sxxln              1/1    Running  0          17h  10.244.2.34    hp-50  <none>          <none>
kube-state-metrics-59c47cfcfb-nfc8c  4/4    Running  0          14h  10.244.4.28    hp-52  <none>          <none>
node-exporter-mn9xf                  2/2    Running  0          17h  192.168.30.55  hp-55  <none>          <none>
node-exporter-nqk7k                  2/2    Running  0          17h  192.168.30.51  hp-51  <none>          <none>
node-exporter-pxkgf                  2/2    Running  0          17h  192.168.30.54  hp-54  <none>          <none>
node-exporter-xv9nh                  2/2    Running  0          17h  192.168.30.50  hp-50  <none>          <none>
node-exporter-zwpw6                  2/2    Running  0          17h  192.168.30.52  hp-52  <none>          <none> prometheus-adapter-668748ddbd-7w2j7  1/1    Running  0          17h  10.244.1.28    hp-55  <none>          <none> prometheus-k8s-0                      3/3    Running  1          17h  10.244.2.35    hp-50  <none>          <none>
prometheus-k8s-1                      3/3    Running  6          17h  10.244.3.31    hp-51  <none>          <none>
prometheus-operator-55b978b89-8jz2l  1/1    Running  0          17h  10.244.4.25    hp-52  <none>          <none>
step6.开始部署pushgateway
在你的manifest⽬录下,创建这三个yaml⽂件。
cat > prometheus-pushgatewayServiceMonitor.yaml <<EOF apiVersion: s/v1
kind: ServiceMonitor
metadata:
labels:
prometheus: k8s
name: prometheus-pushgateway
namespace: monitoring
spec:
endpoints:
- honorLabels: true
port: http
jobLabel: k8s-app
selector:
matchLabels:
app: prometheus-pushgateway
EOF
cat > prometheus-pushgatewayService.yaml <<EOF apiVersion: v1
kind: Service
metadata:
labels:
app: prometheus-pushgateway
name: prometheus-pushgateway
namespace: monitoring
spec:
type: NodePort
ports:
- name: http
port: 9091
nodePort: 30008
targetPort: metrics
selector:
app: prometheus-pushgateway
#  type: ClusterIP
EOF
cat >prometheus-pushgatewayDeployment.yaml <<EOF apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: prometheus-pushgateway
name: prometheus-pushgateway
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-pushgateway
template:
metadata:
labels:
app: prometheus-pushgateway
spec:
containers:
- image: prom/pushgateway:v0.8.0
livenessProbe:
httpGet:
path: /#/status
port: 9091
initialDelaySeconds: 10
timeoutSeconds: 10
name: prometheus-pushgateway
ports:
- containerPort: 9091
name: metrics
readinessProbe:
httpGet:
path: /#/status
port: 9091
initialDelaySeconds: 10
timeoutSeconds: 10
resources:
limits:
cpu: 50m
memory: 100Mi
requests:
cpu: 50m
memory: 100Mi
EOF
然后使⽤
kubectl apply -f .

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。