prometheus|云原生|kubernetes内部安装prometheus

news2025/2/27 22:53:33

架构说明:

prometheus是云原生系统内的事实上的监控标准,而kubernetes集群内部自然还是需要就地取材的部署prometheus服务了

那么,prometheus-server部署的方式其实是非常多的,比如,kubesphere集成方式,helm包方式,yaml文件清单方式,all in one 方式,在本例中,选择使用yaml文件清单方式

部署前需要考虑一个问题,那就是prometheus-server的时序数据库的数据存储问题,在本例中使用的是本地目录挂载方式,也就是host本地挂载,挂载目录  /data

kubernetes集群的版本如下(1.23.16版本,3master,1个工作节点,部署方式为kubekey):

[root@node4 yaml]# k get no -owide
NAME    STATUS   ROLES                  AGE   VERSION    INTERNAL-IP      EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION           CONTAINER-RUNTIME
node1   Ready    control-plane,master   10d   v1.23.16   192.168.123.11   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.8
node2   Ready    control-plane,master   10d   v1.23.16   192.168.123.12   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.8
node3   Ready    control-plane,master   10d   v1.23.16   192.168.123.13   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.8
node4   Ready    worker                 10d   v1.23.16   192.168.123.14   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.8

prometheus-server的版本为(v2.2.1):

[root@node4 yaml]# k get deployments.apps -n monitor-sa -owide
NAME                READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES                   SELECTOR
prometheus-server   2/2     2            2           9d    prometheus   prom/prometheus:v2.2.1   app=prometheus,component=server

grafana的版本为(rpm 方式安装的9.4.3):

[root@node4 yaml]# rpm -qa |grep grafana
grafana-enterprise-9.4.3-1.x86_64

node-exporter的版本为(v0.16,damonsets控制器):

[root@node4 yaml]# k get ds -n monitor-sa -owide
NAME            DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE   CONTAINERS      IMAGES                       SELECTOR
node-exporter   4         4         4       4            4           <none>          10d   node-exporter   prom/node-exporter:v0.16.0   name=node-exporter

部署成功的pod状态如下:

[root@node4 yaml]# k get po -n monitor-sa 
NAME                                READY   STATUS    RESTARTS      AGE
node-exporter-6ttbl                 1/1     Running   1 (77m ago)   10d
node-exporter-7ls5t                 1/1     Running   1 (76m ago)   10d
node-exporter-r287q                 1/1     Running   3 (77m ago)   10d
node-exporter-z85dm                 1/1     Running   1 (77m ago)   10d
prometheus-server-fb59774d6-bgmn7   1/1     Running   0             62m
prometheus-server-fb59774d6-wrq27   1/1     Running   0             62m

下面就如何在kubernetes内   部署一个prometheus做一个介绍

一,

node-exporter的部署

这里需要说明一下,node-exporter是做数据收集工作的,因此,如何收集数据,哪些数据需要收集,哪些数据需要舍弃这些是应该考虑的,虽然exporter只是收集数据,数据并不主动推送到prometheus,而是由prometheus自己来抓取,因此,无需配置存储,但如果node-exporter什么数据都收集,那毫无疑问的,对prometheus会是一种负担。

本例中相关配置是(表示磁盘挂载点的信息不收集):       

- --collector.filesystem.ignored-mount-points
        - '"^/(sys|proc|dev|host|etc)($|/)"'

prometheus的优化部分,根据以下内容配置

--collector.arp 启用 arp 收集器(默认值:启用)。

--collector.bcache 启用 bcache 收集器(默认值:启用)。

--collector.bonding 启用绑定收集器(默认值:启用)。

--collector.btrfs 启用 btrfs 收集器(默认值:启用)。

--collector.buddyinfo 启用 buddyinfo 收集器(默认值:禁用)。

--collector.conntrack 启用 conntrack 收集器(默认值:启用)。

--collector.cpu 启用 CPU 收集器(默认值:启用)。

--collector.cpufreq 启用 cpufreq 收集器(默认值:启用)。

--collector.diskstats 启用 diskstats 收集器(默认值:启用)。

--collector.drbd 启用 drbd 收集器(默认值:禁用)。

--collector.edac 启用 edac 收集器(默认值:启用)。

--collector.entropy 启用熵收集器(默认值:启用)。

--collector.ethtool 启用 ethtool 收集器(默认值:禁用)。

--collector.fiberchannel 启用光纤通道收集器(默认值:启用)。

--collector.filefd 启用 filefd 收集器(默认值:启用)。

--collector.filesystem 启用文件系统收集器(默认值:启用)。

--collector.hwmon 启用 hwmon 收集器(默认值:启用)。

--collector.infiniband 启用 infiniband 收集器(默认值:启用)。

--collector.interrupts 启用中断收集器(默认值:禁用)。

--collector.ipvs 启用 ipvs 收集器(默认值:启用)。

--collector.ksmd 启用 ksmd 收集器(默认值:禁用)。

--collector.loadavg 启用 loadavg 收集器(默认值:启用)。

--collector.logind 启用登录收集器(默认值:禁用)。

--collector.mdadm 启用 mdadm 收集器(默认值:启用)。

--collector.meminfo 启用 meminfo 收集器(默认值:启用)。

--collector.meminfo_numa 启用 meminfo_numa 收集器(默认值:禁用)。

--collector.mountstats 启用 mountstats 收集器(默认值:禁用)。

--collector.netclass 启用网络类收集器(默认:启用)。

--collector.netdev 启用 netdev 收集器(默认值:启用)。

--collector.netstat 启用 netstat 收集器(默认值:启用)。

--collector.network_route 启用 network_route 收集器(默认值:禁用)。

--collector.nfs 启用 nfs 收集器(默认值:启用)。 --collector.nfsd 启用 nfsd 收集器(默认值:启用)。

--collector.ntp 启用 ntp 收集器(默认值:禁用)。 --collector.nvme 启用 nvme 收集器(默认值:启用)。

--collector.perf 启用性能收集器(默认值:禁用)。 --collector.powersupplyclass 启用 powersupplyclass 收集器(默认值:启用)。

--collector.pressure 启用压力收集器(默认值:启用)。 --collector.processes 启用进程收集器(默认值:禁用)。

--collector.qdisc 启用 qdisc 收集器(默认值:禁用)。 --collector.rapl 启用 rapl 收集器(默认值:启用)。

--collector.runit 启用 runit 收集器(默认值:禁用)。 --collector.schedstat 启用 schedstat 收集器(默认值:启用)。

--collector.sockstat 启用 sockstat 收集器(默认值:启用)。 --collector.softnet 启用软网络收集器(默认值:启用)。

--collector.stat 启用统计收集器(默认值:启用)。 --collector.supervisord 启用 supervisord 收集器(默认值:禁用)。

--collector.systemd 启用 systemd 收集器(默认值:禁用)。 --collector.tapestats 启用tapestats 收集器(默认值:启用)。

--collector.tcpstat 启用 tcpstat 收集器(默认值:禁用)。 --collector.textfile 启用文本文件收集器(默认值:启用)。

--collector.thermal_zone 启用热区收集器(默认值:启用)。 --collector.time 启用时间收集器(默认:启用)。

--collector.timex 启用 timex 收集器(默认值:启用)。 --collector.udp_queues 启用 udp_queues 收集器(默认值:启用)。

--collector.uname 启用 uname 收集器(默认值:启用)。 --collector.vmstat 启用 vmstat 收集器(默认值:启用)。

--collector.wifi 启用 wifi 收集器(默认值:禁用)。 --collector.xfs 启用 xfs 收集器(默认值:启用)。

--collector.zfs 启用 zfs 收集器(默认值:启用)。 --collector.zoneinfo 启用 zoneinfo 收集器(默认值:禁用)。

Example:

--collector.filesystem.mount-points-exclude=^/(dev|proc|sys|var/lib/docker/.+|var/lib/kubelet/.+)($|/)

List:

CollectorScopeInclude FlagExclude Flag
arpdevice--collector.arp.device-include--collector.arp.device-exclude
cpubugs--collector.cpu.info.bugs-includeN/A
cpuflags--collector.cpu.info.flags-includeN/A
diskstatsdevice--collector.diskstats.device-include--collector.diskstats.device-exclude
ethtooldevice--collector.ethtool.device-include--collector.ethtool.device-exclude
ethtoolmetrics--collector.ethtool.metrics-includeN/A
filesystemfs-typesN/A--collector.filesystem.fs-types-exclude
filesystemmount-pointsN/A--collector.filesystem.mount-points-exclude
hwmonchip--collector.hwmon.chip-include--collector.hwmon.chip-exclude
netdevdevice--collector.netdev.device-include--collector.netdev.device-exclude
qdiskdevice--collector.qdisk.device-include--collector.qdisk.device-exclude
sysctlall--collector.sysctl.includeN/A
systemdunit--collector.systemd.unit-include--collector.systemd.unit-exclude

Enabled by default

NameDescriptionOS
arpExposes ARP statistics from /proc/net/arp.Linux
bcacheExposes bcache statistics from /sys/fs/bcache/.Linux
bondingExposes the number of configured and active slaves of Linux bonding interfaces.Linux
btrfsExposes btrfs statisticsLinux
boottimeExposes system boot time derived from the kern.boottime sysctl.Darwin, Dragonfly, FreeBSD, NetBSD, OpenBSD, Solaris
conntrackShows conntrack statistics (does nothing if no /proc/sys/net/netfilter/ present).Linux
cpuExposes CPU statisticsDarwin, Dragonfly, FreeBSD, Linux, Solaris, OpenBSD
cpufreqExposes CPU frequency statisticsLinux, Solaris
diskstatsExposes disk I/O statistics.Darwin, Linux, OpenBSD
dmiExpose Desktop Management Interface (DMI) info from /sys/class/dmi/id/Linux
edacExposes error detection and correction statistics.Linux
entropyExposes available entropy.Linux
execExposes execution statistics.Dragonfly, FreeBSD
fibrechannelExposes fibre channel information and statistics from /sys/class/fc_host/.Linux
filefdExposes file descriptor statistics from /proc/sys/fs/file-nr.Linux
filesystemExposes filesystem statistics, such as disk space used.Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
hwmonExpose hardware monitoring and sensor data from /sys/class/hwmon/.Linux
infinibandExposes network statistics specific to InfiniBand and Intel OmniPath configurations.Linux
ipvsExposes IPVS status from /proc/net/ip_vs and stats from /proc/net/ip_vs_stats.Linux
loadavgExposes load average.Darwin, Dragonfly, FreeBSD, Linux, NetBSD, OpenBSD, Solaris
mdadmExposes statistics about devices in /proc/mdstat (does nothing if no /proc/mdstat present).Linux
meminfoExposes memory statistics.Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
netclassExposes network interface info from /sys/class/net/Linux
netdevExposes network interface statistics such as bytes transferred.Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
netisrExposes netisr statisticsFreeBSD
netstatExposes network statistics from /proc/net/netstat. This is the same information as netstat -s.Linux
nfsExposes NFS client statistics from /proc/net/rpc/nfs. This is the same information as nfsstat -c.Linux
nfsdExposes NFS kernel server statistics from /proc/net/rpc/nfsd. This is the same information as nfsstat -s.Linux
nvmeExposes NVMe info from /sys/class/nvme/Linux
osExpose OS release info from /etc/os-release or /usr/lib/os-releaseany
powersupplyclassExposes Power Supply statistics from /sys/class/power_supplyLinux
pressureExposes pressure stall statistics from /proc/pressure/.Linux (kernel 4.20+ and/or CONFIG_PSI)
raplExposes various statistics from /sys/class/powercap.Linux
schedstatExposes task scheduler statistics from /proc/schedstat.Linux
selinuxExposes SELinux statistics.Linux
sockstatExposes various statistics from /proc/net/sockstat.Linux
softnetExposes statistics from /proc/net/softnet_stat.Linux
statExposes various statistics from /proc/stat. This includes boot time, forks and interrupts.Linux
tapestatsExposes statistics from /sys/class/scsi_tape.Linux
textfileExposes statistics read from local disk. The --collector.textfile.directory flag must be set.any
thermalExposes thermal statistics like pmset -g therm.Darwin
thermal_zoneExposes thermal zone & cooling device statistics from /sys/class/thermal.Linux
timeExposes the current system time.any
timexExposes selected adjtimex(2) system call stats.Linux
udp_queuesExposes UDP total lengths of the rx_queue and tx_queue from /proc/net/udp and /proc/net/udp6.Linux
unameExposes system information as provided by the uname system call.Darwin, FreeBSD, Linux, OpenBSD
vmstatExposes statistics from /proc/vmstat.Linux
xfsExposes XFS runtime statistics.Linux (kernel 4.4+)
zfsExposes ZFS performance statistics.FreeBSD, Linux, Solaris

node-exporter的部署文件: 

cat >node-export.yaml <<EOF
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-exporter
  namespace: monitor-sa
  labels:
    name: node-exporter
spec:
  selector:
    matchLabels:
     name: node-exporter
  template:
    metadata:
      labels:
        name: node-exporter
    spec:
      hostPID: true
      hostIPC: true
      hostNetwork: true
      containers:
      - name: node-exporter
        image: prom/node-exporter:v0.16.0
        ports:
        - containerPort: 9100
        resources:
          requests:
            cpu: 0.15
        securityContext:
          privileged: true
        args:
        - --path.procfs
        - /host/proc
        - --path.sysfs
        - /host/sys
        - --collector.filesystem.ignored-mount-points
        - '"^/(sys|proc|dev|host|etc)($|/)"'
        volumeMounts:
        - name: dev
          mountPath: /host/dev
        - name: proc
          mountPath: /host/proc
        - name: sys
          mountPath: /host/sys
        - name: rootfs
          mountPath: /rootfs
      tolerations:
      - key: "node-role.kubernetes.io/master"
        operator: "Exists"
        effect: "NoSchedule"
      volumes:
        - name: proc
          hostPath:
            path: /proc
        - name: dev
          hostPath:
            path: /dev
        - name: sys
          hostPath:
            path: /sys
        - name: rootfs
          hostPath:
            path: /
EOF

二,

kube-state-metrics收集器的部署

kube-state-metrics是kubernetes内部专门收集pod,deployment,ds,sts等等资源的状态的收集器,该收集器收集到的数据由prometheus-server 服务自己主动来抓取

例如,我们查询该服务的日志可以看到,有一些资源它没有收集到,原因是sa权限不足,但这些无需担心,和node-exporter一样,某些数据我们是并不需要收集的:

E1202 13:10:33.591335       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1.Secret: secrets is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "secrets" in API group "" at the cluster scope
E1202 13:10:33.592118       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1beta1.MutatingWebhookConfiguration: mutatingwebhookconfigurations.admissionregistration.k8s.io is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "mutatingwebhookconfigurations" in API group "admissionregistration.k8s.io" at the cluster scope
E1202 13:10:33.593079       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1.Namespace: networkpolicies.networking.k8s.io is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "networkpolicies" in API group "networking.k8s.io" at the cluster scope
E1202 13:10:33.597030       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1.ReplicaSet: replicasets.apps is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "replicasets" in API group "apps" at the cluster scope
E1202 13:10:33.599890       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1beta1.ValidatingWebhookConfiguration: validatingwebhookconfigurations.admissionregistration.k8s.io is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "validatingwebhookconfigurations" in API group "admissionregistration.k8s.io" at the cluster scope
E1202 13:10:34.580372       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1.StorageClass: storageclasses.storage.k8s.io is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "storageclasses" in API group "storage.k8s.io" at the cluster scope
E1202 13:10:34.580373       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1.ConfigMap: configmaps is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "configmaps" in API group "" at the cluster scope
E1202 13:10:34.586583       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1beta1.PodDisruptionBudget: poddisruptionbudgets.policy is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "poddisruptionbudgets" in API group "policy" at the cluster scope
E1202 13:10:34.586669       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1.Deployment: deployments.apps is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "deployments" in API group "apps" at the cluster scope
E1202 13:10:34.587055       1 reflector.go:156] pkg/mod/k8s.io/client-go@v0.0.0-20191109102209-3c0d1af94be5/tools/cache/reflector.go:108: Failed to list *v1beta1.VolumeAttachment: volumeattachments.storage.k8s.io is forbidden: User "system:serviceaccount:kube-system:kube-state-metrics" cannot list resource "volumeattachments" in API group "storage.k8s.io" at the cluster scope

kube-state-metrics的RBAC:

这里上面的缺的收集cm的权限我已经补上了

cat> kube-state-metrics-rbac.yaml <<EOF
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kube-state-metrics
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: kube-state-metrics
rules:
- apiGroups: [""]
  resources: ["nodes", "pods", "services", "resourcequotas", "replicationcontrollers", "limitranges", "persistentvolumeclaims", "persistentvolumes", "namespaces", "endpoints"]
  verbs: ["list", "watch"]
- apiGroups: ["extensions"]
  resources: ["daemonsets", "deployments", "replicasets"]
  verbs: ["list", "watch"]
- apiGroups: ["apps"]
  resources: ["statefulsets","daemonsets","replicasets","deployments"]
  verbs: ["list", "watch"]
- apiGroups: ["batch"]
  resources: ["cronjobs", "jobs"]
  verbs: ["list", "watch"]
- apiGroups: ["autoscaling"]
  resources: ["horizontalpodautoscalers"]
  verbs: ["list", "watch"]
- apiGroups: [""]
  resources: ["configmaps","secrets"]
  verbs: ["list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kube-state-metrics
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kube-state-metrics
subjects:
- kind: ServiceAccount
  name: kube-state-metrics
  namespace: kube-system
EOF

 kube-state-metrics的svc:

这里有一个注解,prometheus.io/scrape: 'true'  表示允许prometheus收集数据

cat> kube-state-metrics-svc.yaml <<EOF
apiVersion: v1
kind: Service
metadata:
  annotations:
    prometheus.io/scrape: 'true'
  name: kube-state-metrics
  namespace: kube-system
  labels:
    app: kube-state-metrics
spec:
  ports:
  - name: kube-state-metrics
    port: 8080
    protocol: TCP
  selector:
    app: kube-state-metrics
EOF

kube-state-metrics的deployment:

cat >kube-state-metrics-deploy.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kube-state-metrics
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kube-state-metrics
  template:
    metadata:
      labels:
        app: kube-state-metrics
    spec:
      serviceAccountName: kube-state-metrics
      containers:
      - name: kube-state-metrics
#        image: gcr.io/google_containers/kube-state-metrics-amd64:v1.3.1
        image: quay.io/coreos/kube-state-metrics:v1.9.0
        ports:
        - containerPort: 8080
EOF

三,

prometheus-server的部署

1,

prometheus-svc

cat >prometheus-cfg.yaml <<EOF
---
kind: ConfigMap
apiVersion: v1
metadata:
  labels:
    app: prometheus
  name: prometheus-config
  namespace: monitor-sa
data:
  prometheus.yml: |
    global:
      scrape_interval: 15s
      scrape_timeout: 10s
      evaluation_interval: 1m
    scrape_configs:
    - job_name: 'kubernetes-node'
      kubernetes_sd_configs:
      - role: node
      relabel_configs:
      - source_labels: [__address__]
        regex: '(.*):10250'
        replacement: '${1}:9100'
        target_label: __address__
        action: replace
      - action: labelmap
        regex: __meta_kubernetes_node_label_(.+)
    - job_name: 'kubernetes-node-cadvisor'
      kubernetes_sd_configs:
      - role:  node
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - action: labelmap
        regex: __meta_kubernetes_node_label_(.+)
      - target_label: __address__
        replacement: kubernetes.default.svc:443
      - source_labels: [__meta_kubernetes_node_name]
        regex: (.+)
        target_label: __metrics_path__
        replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisor
    - job_name: 'kubernetes-apiserver'
      kubernetes_sd_configs:
      - role: endpoints
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
        action: keep
        regex: default;kubernetes;https
EOF

2,

prometheus-svc:

cat >prometheus-svc.yaml <<EOF
---
apiVersion: v1
kind: Service
metadata:
  name: prometheus
  namespace: monitor-sa
  labels:
    app: prometheus
spec:
  type: NodePort
  ports:
    - port: 9090
      targetPort: 9090
      protocol: TCP
  selector:
    app: prometheus
    component: server
EOF

3,

cat >prometheus-deploy.yaml <<EOF
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-server
  namespace: monitor-sa
  labels:
    app: prometheus
spec:
  replicas: 2
  selector:
    matchLabels:
      app: prometheus
      component: server
    #matchExpressions:
    #- {key: app, operator: In, values: [prometheus]}
    #- {key: component, operator: In, values: [server]}
  template:
    metadata:
      labels:
        app: prometheus
        component: server
      annotations:
        prometheus.io/scrape: 'false'
    spec:
      nodeName: node4
      serviceAccountName: monitor
      containers:
      - name: prometheus
        image: prom/prometheus:v2.2.1
        imagePullPolicy: IfNotPresent
        command:
          - prometheus
          - --config.file=/etc/prometheus/prometheus.yml
          - --storage.tsdb.path=/prometheus
          - --storage.tsdb.retention=720h
        ports:
        - containerPort: 9090
          protocol: TCP
        volumeMounts:
        - mountPath: /etc/prometheus/prometheus.yml
          name: prometheus-config
          subPath: prometheus.yml
        - mountPath: /prometheus/
          name: prometheus-storage-volume
      volumes:
        - name: prometheus-config
          configMap:
            name: prometheus-config
            items:
              - key: prometheus.yml
                path: prometheus.yml
                mode: 0644
        - name: prometheus-storage-volume
          hostPath:
           path: /data
           type: Directory
EOF

以上所有部署执行完毕后,查看prometheus-server的svc:

[root@node4 yaml]# k get svc -n monitor-sa 
NAME         TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
prometheus   NodePort   10.96.0.120   <none>        9090:32661/TCP   10d

根据该port,打开浏览器,进入prometheus的web界面:

至此,kubernetes集群内的prometheus-server服务就安装完毕了!!!!!! 

grafana默认安装就可以了,rpm方式安装,没什么好说的,主要是数据源设置如下:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1278316.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

STM32GPIO速度配置究竟改变了什么-笔记

STM32GPIO速度配置究竟改变了什么-笔记 摘要STM32引脚内部框图STM32时钟树端口寄存器I/O交流特性定义 摘要 一般有 Low、Medium、High&#xff0c;三种速度选择。速度配置变了硬件什么状态&#xff1f; 对 GPIO 的输入输出信号有什么影响&#xff1f; 编程时如何选取速度参数&…

【计算机网络】15、NAT、NAPT 网络地址转换、打洞

文章目录 一、概念二、分类&#xff08;主要是传统 NAT&#xff09;2.1 基本 NAT2.2 NAPT 三、访问NAT下的内网设备的方式3.1 多拨3.2 端口转发、DMZ3.3 UPnP IGD、NAT-PMP3.4 服务器中转&#xff1a;frp 内网穿透3.4.1 NAT 打洞3.4.2 NAT 类型与打洞成功率3.4.2.1 完全圆锥形 …

Redis--11--Redis事务的理解

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 Redis事务事务回滚机制Redis 事务是不支持回滚的&#xff0c;不像 MySQL 的事务一样&#xff0c;要么都执行要么都不执行&#xff1b; Redis的事务原理 Redis事务 …

深度学习手势识别算法实现 - opencv python 计算机竞赛

文章目录 1 前言2 项目背景3 任务描述4 环境搭配5 项目实现5.1 准备数据5.2 构建网络5.3 开始训练5.4 模型评估 6 识别效果7 最后 1 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; 深度学习手势识别算法实现 - opencv python 该项目较为新颖…

五款适用于 Mac 电脑操作的顶级Android 数据恢复工具

在本文中&#xff0c;我们将介绍五款适用于 Mac 电脑的最佳 Android 数据恢复工具。借助这些数据恢复软件工具&#xff0c;用户可以从运行 macOS 操作系统的台式机或笔记本电脑恢复 Android 设备中丢失或删除的数据。许多 Mac 用户更喜欢 iPhone 等 iOS 设备&#xff0c;但也有…

180天Java从小白到就业-Day03-03Java位运算符、赋值运算符、数据交换的三种方式

1. 位运算符 Q&#xff1a;为什么要学习位运算 A&#xff1a;由于其运算效率更高&#xff0c;在JDK源码&#xff08;例如ArrayList、HashMap&#xff09;中大量使用位运算&#xff0c;想要看懂JDK源码必须懂位预算&#xff0c;但是在公司开发业务系统时位运算使用并不多。 Q…

神经网络 模型表示2

神经网络 模型表示2 使用向量化的方法会使得计算更为简便。以上面的神经网络为例&#xff0c;试着计算第二层的值&#xff1a; 我们令 z ( 2 ) θ ( 1 ) x {{z}^{\left( 2 \right)}}{{\theta }^{\left( 1 \right)}}x z(2)θ(1)x&#xff0c;则 a ( 2 ) g ( z ( 2 ) ) {{a}…

基于SpringBoot学生宿舍管理系统的设计与开发

摘 要 互联网发展至今&#xff0c;无论是其理论还是技术都已经成熟&#xff0c;而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播&#xff0c;搭配信息管理工具可以很好地为人们提供服务。针对学生宿舍信息管理混乱&#xff0c;出错率高&#xff0c;信息安全性差…

spark的安装与使用:一键自动安装

使用shell脚本一键下载、安装、配置spark&#xff08;单机版&#xff09; 1. 把下面的脚本复制保存为/tmp/install_spark.sh文件 #!/bin/bash# sprak安装版本 sprak_version"2.4.0" # sprak安装目录 sprak_installDir"/opt/module" # hadoop安装路径&…

lv11 嵌入式开发 中断处理 15

前言&#xff1a;中断属于7种异常的1种&#xff0c;这节主要讲CPU接收到中断之后怎么处理&#xff0c;回顾之前的知识。 目录 1 异常 1.1 概念 1.2 异常处理机制 1.3 ARM异常源 1.4 异常模式 1.5 ARM异常响应 1.6 异常向量表 1.7 异常返回 ​编辑 1.8 IRQ异常举例 …

什么是DDoS攻击

DDoS攻击 1. 定义2. DDoS攻击类型2.1 网络层攻击2.2 传输层攻击2.3 应用层攻击 3.DDoS攻击态势特点 1. 定义 分布式拒绝服务&#xff08;DDoS&#xff09;攻击是一种常见的网络攻击形式。攻击者利用恶意程序对一个或多个目标发起攻击&#xff0c;企图通过大规模互联网流量耗尽…

java学习part29线程通信

139-多线程-线程间的通信机制与生产者消费者案例_哔哩哔哩_bilibili 1.等待唤醒 类似于golang的channel&#xff0c; 1.1用法 类似于go的wait()&#xff0c; 1.sleep和wait的一个重大区别是&#xff0c;sleep不会让线程失去同步监视器&#xff0c;而wait会释放 2.wait必须tr…

【深度学习】深度学习框架的环境配置

目录 1. 配置cuda环境 1.1. 安装cuda和cudnn 1.1.1. 显卡驱动配置 1.1.2. 下载安装cuda 1.1.3. 下载cudnn&#xff0c;将解压后文件复制到cuda目录下 1.2. 验证是否安装成功 2. 配置conda环境 2.1. 安装anaconda 2.2. conda换源 2.3. 创建conda环境 2.4. pip换源 3…

使用MD5当做文件的唯一标识,这样安全么?

使用MD5作为文件唯一标识符可靠么&#xff1f; 文章目录 使用MD5作为文件唯一标识符可靠么&#xff1f;什么是MD5&#xff1f;MD5的用途MD5作为文件唯一标识的优劣优势劣势 使用MD5作为文件唯一标识的建议其他文件标识算法结束语 什么是MD5&#xff1f; MD5&#xff08;Messag…

企业计算机服务器中了locked1勒索病毒怎么解锁,locked1勒索病毒数据恢复

随着网络技术在企业的不断应用&#xff0c;企业的生产运营效率得到了极大提升&#xff0c;越来越多的企业利用网络开展工作&#xff0c;这也导致了企业的受到的网络安全威胁也不断增加。在本月&#xff0c;云天数据恢复中心陆续接到很多企业的求助&#xff0c;企业的计算机服务…

无线物理层安全学习

文章目录 3.17到3.203.85到3.88 3.17到3.20 3.85到3.88

np.array无法直接用matplotlib画图,因为需要借用np.squeeze先转化

文章目录 前言一、使用步骤1.没使用np.squeeze转化2.使用np.squeeze转化 前言 实际工作中&#xff0c;时而难免会遇见np.array无法直接用matplotlib画图的情况&#xff0c;这个时候&#xff0c;是因为在画图之前少了一个步骤&#xff0c;需要先借用np.squeeze先转化 一、使用步…

Gateway网关--java

网关是建立于请求到服务之前的,可以用网关限制访问量,添加过滤等 创建网关模块,引入相关pome依赖 配置yml 具体相关的作用可以参考 Spring Cloud Gateway 这样就可以了 基础的网关配置,我们的实现效果 我们可以通过10010端口访问,通过转发到nacos,再找到相应的模块,实现…

JS逆向-mytoken之code参数

前言 本文是该专栏的第60篇,后面会持续分享python爬虫干货知识,记得关注。 本文以mytoken为例,通过js逆向获取其code参数的生成规律。具体的“逆向”思路逻辑,笔者将会详细介绍每个步骤,并且将在正文结合“完整代码”进行详细说明。 接下来,跟着笔者直接往下看正文详细…

P5 链表 尾部插入新节点(不是指定点)

目录 前言 01 链表数据插入之直接在链表尾插入&#xff08;不是指定点&#xff09; 02 尾插创建链表优化 示例代码 前言 &#x1f3ac; 个人主页&#xff1a;ChenPi &#x1f43b;推荐专栏1: 《C》✨✨✨ &#x1f525; 推荐专栏2: 《 Linux C应用编程&#xff08;概念…