首页 > 其他分享 >kubernetes1.18.2安装kube-prometheus

kubernetes1.18.2安装kube-prometheus

时间:2023-12-18 10:02:21浏览次数:44  
标签:Jan created -- kubernetes1.18 yaml prometheus kube root

注:使用kube-prometheus安装非常方便,前面的prometheus+grafana+metrics-server都不用安装,已经集成在里面。

1、clone github地址

git clone https://github.com/coreos/kube-prometheus.git
cd kube-prometheus

2、查看manifest路径下所有的yaml文件

[root@master1 manifests]# ll
total 1724
-rw-r--r-- 1 root root     782 Jan 13 07:49 alertmanager-alertmanager.yaml
-rw-r--r-- 1 root root    1169 Jan 13 07:49 alertmanager-secret.yaml
-rw-r--r-- 1 root root     301 Jan 13 07:49 alertmanager-serviceAccount.yaml
-rw-r--r-- 1 root root     540 Jan 13 07:49 alertmanager-serviceMonitor.yaml
-rw-r--r-- 1 root root     632 Jan 13 08:33 alertmanager-service.yaml
-rw-r--r-- 1 root root     278 Jan 13 07:49 blackbox-exporter-clusterRoleBinding.yaml
-rw-r--r-- 1 root root     287 Jan 13 07:49 blackbox-exporter-clusterRole.yaml
-rw-r--r-- 1 root root    1392 Jan 13 07:49 blackbox-exporter-configuration.yaml
-rw-r--r-- 1 root root    2994 Jan 13 07:49 blackbox-exporter-deployment.yaml
-rw-r--r-- 1 root root      96 Jan 13 07:49 blackbox-exporter-serviceAccount.yaml
-rw-r--r-- 1 root root     680 Jan 13 07:49 blackbox-exporter-serviceMonitor.yaml
-rw-r--r-- 1 root root     540 Jan 13 07:49 blackbox-exporter-service.yaml
-rw-r--r-- 1 root root     550 Jan 13 07:49 grafana-dashboardDatasources.yaml
-rw-r--r-- 1 root root 1403543 Jan 13 07:49 grafana-dashboardDefinitions.yaml
-rw-r--r-- 1 root root     454 Jan 13 07:49 grafana-dashboardSources.yaml
-rw-r--r-- 1 root root    7722 Jan 13 07:49 grafana-deployment.yaml
-rw-r--r-- 1 root root      86 Jan 13 07:49 grafana-serviceAccount.yaml
-rw-r--r-- 1 root root     379 Jan 13 07:49 grafana-serviceMonitor.yaml
-rw-r--r-- 1 root root     273 Jan 13 08:34 grafana-service.yaml
-rw-r--r-- 1 root root     464 Jan 13 07:49 kube-state-metrics-clusterRoleBinding.yaml
-rw-r--r-- 1 root root    1739 Jan 13 07:49 kube-state-metrics-clusterRole.yaml
-rw-r--r-- 1 root root    2803 Jan 13 07:49 kube-state-metrics-deployment.yaml
-rw-r--r-- 1 root root     280 Jan 13 07:49 kube-state-metrics-serviceAccount.yaml
-rw-r--r-- 1 root root    1011 Jan 13 07:49 kube-state-metrics-serviceMonitor.yaml
-rw-r--r-- 1 root root     580 Jan 13 07:49 kube-state-metrics-service.yaml
-rw-r--r-- 1 root root     444 Jan 13 07:49 node-exporter-clusterRoleBinding.yaml
-rw-r--r-- 1 root root     461 Jan 13 07:49 node-exporter-clusterRole.yaml
-rw-r--r-- 1 root root    2907 Jan 13 07:49 node-exporter-daemonset.yaml
-rw-r--r-- 1 root root     270 Jan 13 07:49 node-exporter-serviceAccount.yaml
-rw-r--r-- 1 root root     850 Jan 13 07:49 node-exporter-serviceMonitor.yaml
-rw-r--r-- 1 root root     492 Jan 13 07:49 node-exporter-service.yaml
-rw-r--r-- 1 root root     482 Jan 13 07:49 prometheus-adapter-apiService.yaml
-rw-r--r-- 1 root root     576 Jan 13 07:49 prometheus-adapter-clusterRoleAggregatedMetricsReader.yaml
-rw-r--r-- 1 root root     494 Jan 13 07:49 prometheus-adapter-clusterRoleBindingDelegator.yaml
-rw-r--r-- 1 root root     471 Jan 13 07:49 prometheus-adapter-clusterRoleBinding.yaml
-rw-r--r-- 1 root root     378 Jan 13 07:49 prometheus-adapter-clusterRoleServerResources.yaml
-rw-r--r-- 1 root root     409 Jan 13 07:49 prometheus-adapter-clusterRole.yaml
-rw-r--r-- 1 root root    1568 Jan 13 07:49 prometheus-adapter-configMap.yaml
-rw-r--r-- 1 root root    1804 Jan 13 07:49 prometheus-adapter-deployment.yaml
-rw-r--r-- 1 root root     515 Jan 13 07:49 prometheus-adapter-roleBindingAuthReader.yaml
-rw-r--r-- 1 root root     287 Jan 13 07:49 prometheus-adapter-serviceAccount.yaml
-rw-r--r-- 1 root root     677 Jan 13 07:49 prometheus-adapter-serviceMonitor.yaml
-rw-r--r-- 1 root root     501 Jan 13 07:49 prometheus-adapter-service.yaml
-rw-r--r-- 1 root root     447 Jan 13 07:49 prometheus-clusterRoleBinding.yaml
-rw-r--r-- 1 root root     394 Jan 13 07:49 prometheus-clusterRole.yaml
-rw-r--r-- 1 root root     621 Jan 13 07:49 prometheus-operator-serviceMonitor.yaml
-rw-r--r-- 1 root root    1153 Jan 13 07:49 prometheus-prometheus.yaml
-rw-r--r-- 1 root root     471 Jan 13 07:49 prometheus-roleBindingConfig.yaml
-rw-r--r-- 1 root root    1547 Jan 13 07:49 prometheus-roleBindingSpecificNamespaces.yaml
-rw-r--r-- 1 root root     366 Jan 13 07:49 prometheus-roleConfig.yaml
-rw-r--r-- 1 root root    1705 Jan 13 07:49 prometheus-roleSpecificNamespaces.yaml
-rw-r--r-- 1 root root   99658 Jan 13 07:49 prometheus-rules.yaml
-rw-r--r-- 1 root root     271 Jan 13 07:49 prometheus-serviceAccount.yaml
-rw-r--r-- 1 root root    6836 Jan 13 07:49 prometheus-serviceMonitorApiserver.yaml
-rw-r--r-- 1 root root     440 Jan 13 07:49 prometheus-serviceMonitorCoreDNS.yaml
-rw-r--r-- 1 root root    6355 Jan 13 07:49 prometheus-serviceMonitorKubeControllerManager.yaml
-rw-r--r-- 1 root root    7141 Jan 13 07:49 prometheus-serviceMonitorKubelet.yaml
-rw-r--r-- 1 root root     530 Jan 13 07:49 prometheus-serviceMonitorKubeScheduler.yaml
-rw-r--r-- 1 root root     527 Jan 13 07:49 prometheus-serviceMonitor.yaml
-rw-r--r-- 1 root root     613 Jan 13 08:32 prometheus-service.yaml
drwxr-xr-x 2 root root    4096 Jan 13 07:49 setup

3、修改promethes,alertmanager,grafana的service类型为NodePort类型

[root@master1 manifests]# cat prometheus-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: prometheus
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: kube-prometheus
    app.kubernetes.io/version: 2.24.0
    prometheus: k8s
  name: prometheus-k8s
  namespace: monitoring
spec:
  type: NodePort # 新增
  ports:
  - name: web
    port: 9090
    targetPort: web
    nodePort: 30090 # 新增
  selector:
    app: prometheus
    app.kubernetes.io/component: prometheus
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: kube-prometheus
    prometheus: k8s
  sessionAffinity: ClientIP
[root@master1 manifests]# cat alertmanager-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    alertmanager: main
    app.kubernetes.io/component: alert-router
    app.kubernetes.io/name: alertmanager
    app.kubernetes.io/part-of: kube-prometheus
    app.kubernetes.io/version: 0.21.0
  name: alertmanager-main
  namespace: monitoring
spec:
  type: NodePort # 新增
  ports:
  - name: web
    port: 9093
    targetPort: web
    nodePort: 30093 # 新增
  selector:
    alertmanager: main
    app: alertmanager
    app.kubernetes.io/component: alert-router
    app.kubernetes.io/name: alertmanager
    app.kubernetes.io/part-of: kube-prometheus
  sessionAffinity: ClientIP
[root@master1 manifests]# cat grafana-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  type: NodePort # 新增
  ports:
  - name: http
    port: 3000
    targetPort: http
    nodePort: 32000 # 新增
  selector:
    app: grafana
  type: NodePort

4、安装setup路径下的所有yaml文件

[root@master1 setup]# kubectl apply -f .
namespace/monitoring created
customresourcedefinition.apiextensions.k8s.io/alertmanagerconfigs.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/probes.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/thanosrulers.monitoring.coreos.com created
clusterrole.rbac.authorization.k8s.io/prometheus-operator created
clusterrolebinding.rbac.authorization.k8s.io/prometheus-operator created
deployment.apps/prometheus-operator created
service/prometheus-operator created
serviceaccount/prometheus-operator created

5、查看状态

[root@master1 setup]# kubectl get po -n monitoring
NAME                                   READY   STATUS    RESTARTS   AGE
prometheus-operator-78d4d97f4d-8pdh6   2/2     Running   0          17s

6、安装manifests路径下所有文件

[root@master1 manifests]# kubectl apply -f .
alertmanager.monitoring.coreos.com/main created
secret/alertmanager-main created
service/alertmanager-main created
serviceaccount/alertmanager-main created
servicemonitor.monitoring.coreos.com/alertmanager created
clusterrole.rbac.authorization.k8s.io/blackbox-exporter created
clusterrolebinding.rbac.authorization.k8s.io/blackbox-exporter created
configmap/blackbox-exporter-configuration created
deployment.apps/blackbox-exporter created
service/blackbox-exporter created
serviceaccount/blackbox-exporter created
servicemonitor.monitoring.coreos.com/blackbox-exporter created
secret/grafana-datasources created
configmap/grafana-dashboard-apiserver created
configmap/grafana-dashboard-cluster-total created
configmap/grafana-dashboard-controller-manager created
configmap/grafana-dashboard-k8s-resources-cluster created
configmap/grafana-dashboard-k8s-resources-namespace created
configmap/grafana-dashboard-k8s-resources-node created
configmap/grafana-dashboard-k8s-resources-pod created
configmap/grafana-dashboard-k8s-resources-workload created
configmap/grafana-dashboard-k8s-resources-workloads-namespace created
configmap/grafana-dashboard-kubelet created
configmap/grafana-dashboard-namespace-by-pod created
configmap/grafana-dashboard-namespace-by-workload created
configmap/grafana-dashboard-node-cluster-rsrc-use created
configmap/grafana-dashboard-node-rsrc-use created
configmap/grafana-dashboard-nodes created
configmap/grafana-dashboard-persistentvolumesusage created
configmap/grafana-dashboard-pod-total created
configmap/grafana-dashboard-prometheus-remote-write created
configmap/grafana-dashboard-prometheus created
configmap/grafana-dashboard-proxy created
configmap/grafana-dashboard-scheduler created
configmap/grafana-dashboard-statefulset created
configmap/grafana-dashboard-workload-total created
configmap/grafana-dashboards created
deployment.apps/grafana created
service/grafana created
serviceaccount/grafana created
servicemonitor.monitoring.coreos.com/grafana created
clusterrole.rbac.authorization.k8s.io/kube-state-metrics created
clusterrolebinding.rbac.authorization.k8s.io/kube-state-metrics created
deployment.apps/kube-state-metrics created
service/kube-state-metrics created
serviceaccount/kube-state-metrics created
servicemonitor.monitoring.coreos.com/kube-state-metrics created
clusterrole.rbac.authorization.k8s.io/node-exporter created
clusterrolebinding.rbac.authorization.k8s.io/node-exporter created
daemonset.apps/node-exporter created
service/node-exporter created
serviceaccount/node-exporter created
servicemonitor.monitoring.coreos.com/node-exporter created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
clusterrole.rbac.authorization.k8s.io/prometheus-adapter created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/prometheus-adapter created
clusterrolebinding.rbac.authorization.k8s.io/resource-metrics:system:auth-delegator created
clusterrole.rbac.authorization.k8s.io/resource-metrics-server-resources created
configmap/adapter-config created
deployment.apps/prometheus-adapter created
rolebinding.rbac.authorization.k8s.io/resource-metrics-auth-reader created
service/prometheus-adapter created
serviceaccount/prometheus-adapter created
servicemonitor.monitoring.coreos.com/prometheus-adapter created
clusterrole.rbac.authorization.k8s.io/prometheus-k8s created
clusterrolebinding.rbac.authorization.k8s.io/prometheus-k8s created
servicemonitor.monitoring.coreos.com/prometheus-operator created
prometheus.monitoring.coreos.com/k8s created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s-config created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s created
rolebinding.rbac.authorization.k8s.io/prometheus-k8s created
role.rbac.authorization.k8s.io/prometheus-k8s-config created
role.rbac.authorization.k8s.io/prometheus-k8s created
role.rbac.authorization.k8s.io/prometheus-k8s created
role.rbac.authorization.k8s.io/prometheus-k8s created
prometheusrule.monitoring.coreos.com/prometheus-k8s-rules created
service/prometheus-k8s created
serviceaccount/prometheus-k8s created
servicemonitor.monitoring.coreos.com/prometheus created
servicemonitor.monitoring.coreos.com/kube-apiserver created
servicemonitor.monitoring.coreos.com/coredns created
servicemonitor.monitoring.coreos.com/kube-controller-manager created
servicemonitor.monitoring.coreos.com/kube-scheduler created
servicemonitor.monitoring.coreos.com/kubelet created

7、查看状态

[root@master1 ~]# kubectl get pod -n monitoring
NAME                                   READY   STATUS    RESTARTS   AGE
alertmanager-main-0                    2/2     Running   0          7m13s
alertmanager-main-1                    2/2     Running   0          7m13s
alertmanager-main-2                    2/2     Running   0          7m13s
blackbox-exporter-6f998d5c46-8wd6h     3/3     Running   0          7m13s
grafana-9cf59f9dc-rkwpr                1/1     Running   0          7m11s
kube-state-metrics-598b6577d9-p2kzl    3/3     Running   0          7m12s
node-exporter-5jr9j                    2/2     Running   0          7m10s
node-exporter-9mqgz                    2/2     Running   0          7m10s
node-exporter-gx57w                    2/2     Running   0          7m10s
node-exporter-hv9l4                    2/2     Running   0          7m10s
prometheus-adapter-7586ffcbdb-dfw64    1/1     Running   0          7m8s
prometheus-k8s-0                       2/2     Running   1          7m7s
prometheus-k8s-1                       2/2     Running   1          7m7s
prometheus-operator-78d4d97f4d-8pdh6   2/2     Running   0          7m47s

8、访问prometheus,alert-manager,grafana

kubernetes1.18.2安装kube-prometheus_git

kubernetes1.18.2安装kube-prometheus_git_02

kubernetes1.18.2安装kube-prometheus_github_03

9、模板grafana有很多自带的可以随便选择一个就行

kubernetes1.18.2安装kube-prometheus_github_04

kubernetes1.18.2安装kube-prometheus_git_05

标签:Jan,created,--,kubernetes1.18,yaml,prometheus,kube,root
From: https://blog.51cto.com/u_14620403/8868246

相关文章

  • k8s集群安装KubeSphere3.0
    架构:前提条件:k8s集群版本必须是1.15.x,1.16.x,1.17.x,or1.18.x必须有默认的storageclass内存和cpu最低要求:CPU>1Core,Memory>2G安装并设置默认storageclass略过,可以看之前的我发过的博客1.安装yaml文件(先安装第一个,再安装第二个)kubectlapply-fhttps://github.com......
  • Kubernetes 网络之 DNS 介绍
    一、服务发现Pod提供的服务可以通过Service生成的ClusterIP(VIP)来访问。怎么知道某个应用的VIP呢?k8s主要有两种Service发现机制:环境变量和DNS。没有DNS服务的时候,k8s会采用环境变量的形式,但一旦有多个service,环境变量会变复杂,为解决该问题,我们使用DNS服务。环境变量在之......
  • K8s - 容器编排引擎Kubernetes
     什么是Kubernetes?背景Kubernetes是开源的容器集群管理项目,诞生于2014年,由Google公司发起前身Borg系统在Google内部应用了十几年,积累了大量来自生产环境的实践经验试图为基于容器的应用部署和管理打造一套强大并且易用的管理平台该项目基于Go语言实现介绍一个基于容......
  • kubescape的使用
    1.使用前言:Kubescape是一个开源的Kubernetes安全平台。它包括风险分析、安全合规性和错误配置扫描。它面向DevSecOps从业者或平台工程师,提供易于使用的CLI界面、灵活的输出格式和自动扫描功能。它为Kubernetes用户和管理员节省了宝贵的时间、精力和资源。(摘自官网)相关......
  • 使用 Prometheus 监控 Memcached 最佳实践
    监控Memcached监控Memcached的重要性无法忽视。通过监控Memcached,我们可以及时了解到系统中的缓存命中率、缓存使用量和缓存访问频率等关键指标,从而更好地优化系统性能。同时,监控Memcached还可以帮助我们发现潜在的性能问题和内存泄漏,及时采取措施进行修复,保障系统的稳定运行。在......
  • Kubernetes 调度场景实战指南
    Kubernetes调度是确保集群中的Pod在合适的节点上运行的关键组件。通过灵活配置调度策略,可以提高资源利用率、负载均衡和高可用性。在本文中,我们将深入研究一些实际的Kubernetes调度场景,并提供相应的配置示例和最佳实践。1.基础场景-NodeSelector场景描述:我们有一些节点标......
  • Kubernetes: client-go 源码剖析(二)
    上接Kubernetes:client-go源码剖析(一)2.3运行informer运行informer将Reflector,informer和indexer组件关联以实现informer流程图的流程。2.3.1ReflectorList&Watch运行informer:informer.Run(stopCh)//client-go/tools/cache/shared_informer.gofunc(s*s......
  • Kubernetes: client-go 源码剖析(一)
    0.前言在看kube-scheduler组件的过程中遇到了kube-scheduler对于client-go的调用,泛泛的理解调用过程总有种隔靴搔痒的感觉,于是调转头先把client-go理清楚在回来看kube-scheduler。为什么要看client-go,并且要深入到原理,源码层面去看。很简单,因为它很重要。重要在两方......
  • Kubernetes v1.29 新特性一览
    新特性一览大纲一、Core组件增强调度器增强在Kubernetesv1.29中,Core组件经历了一系列增强,其中一个重要的改进是调度器的增强。这些增强使得调度器能够更加智能和高效地管理容器的调度和分配。通过引入新的调度算法和策略,调度器能够更好地适应不同的资源需求和约束条件,提高集群的容......
  • prometheus监控k8s集群信息(通过kubelet)
    prometheus监控k8s集群信息(通过kubelet)一、创建prometheus访问k8s权限账户(在k8s集群中操作)。1、在k8s集群中创建服务账户vimprometheus-sa.yamlapiVersion:v1kind:ServiceAccountmetadata:name:prometheus-sanamespace:monitor 2、创建集群角色......