K8S學習之基礎三十六:node-exporter部署

Prometheus v2.2.1

? 編寫yaml文件,包含創建ns、configmap、deployment、service

# 創建monitoring空間
vi prometheus-ns.yaml 
apiVersion: v1
kind: Namespace
metadata:name: monitoring# 創建SA并綁定權限
kubectl create serviceaccount monitor -n monitoring?
kubectl create clusterrolebinding monitor-clusterrolebinding -n monitoring --clusterrole=cluster-admin  --serviceaccount=monitoring:monitor
kubectl?create?clusterrolebinding?monitor-clusterrolebinding-1 ?-n?monitoring?--clusterrole=cluster-admin???--user=system:serviceaccount:monitor:monitoring# 創建cm、deployment、svc
apiVersion: v1
kind: ConfigMap
metadata:labels:app: prometheusname: prometheus-confignamespace: monitoring
data:prometheus.yml: |global:scrape_interval: 15sscrape_timeout: 10sevaluation_interval: 1mscrape_configs:- job_name: 'kubernetes-node'kubernetes_sd_configs:- role: noderelabel_configs:- source_labels: [__address__]regex: '(.*):10250'replacement: '${1}:9100'target_label: __address__action: replace- action: labelmapregex: __meta_kubernetes_node_label_(.+)- job_name: 'kubernetes-node-cadvisor'kubernetes_sd_configs:- role:  nodescheme: httpstls_config:ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crtbearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/tokenrelabel_configs:- action: labelmapregex: __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: endpointsscheme: httpstls_config:ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crtbearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/tokenrelabel_configs:- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_po
rt_name]action: keepregex: default;kubernetes;https- job_name: 'kubernetes-service-endpoints'kubernetes_sd_configs:- role: endpointsrelabel_configs:- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]action: keepregex: true- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]action: replacetarget_label: __scheme__regex: (https?)- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]action: replacetarget_label: __metrics_path__regex: (.+)- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]action: replacetarget_label: __address__regex: ([^:]+)(?::\d+)?;(\d+)replacement: $1:$2- action: labelmapregex: __meta_kubernetes_service_label_(.+)- source_labels: [__meta_kubernetes_namespace]action: replacetarget_label: kubernetes_namespace- source_labels: [__meta_kubernetes_service_name]action: replacetarget_label: kubernetes_name 
---
apiVersion: apps/v1
kind: Deployment
metadata:name: prometheus-servernamespace: monitoringlabels:app: prometheus
spec:replicas: 1selector:matchLabels:app: prometheuscomponent: server#matchExpressions:#- {key: app, operator: In, values: [prometheus]}[root@mast01 prometheus]# kubectl get pod -n monitoring
NAME                         READY   STATUS    RESTARTS   AGE
prometheus-dfdfb9d79-h4tk4   1/1     Running   0          22h
[root@mast01 prometheus]# kubectl get svc -n monitoring
NAME         TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
prometheus   NodePort   10.109.44.37   <none>        9090:30090/TCP   22h
[root@mast01 prometheus]# curl 10.109.44.37:9090
<a href="/graph">Found</a>.[root@mast01 prometheus]# kubectl get ep -n monitoring
NAME         ENDPOINTS            AGE
prometheus   10.244.140.67:9090   22h
[root@mast01 prometheus]# curl 172.16.80.131:30090
<a href="/graph">Found</a>.

瀏覽器訪問 172.16.80.131:30090

node-exporter組件安裝和配置

? node-exporter可以采集機器(物理機、虛擬機、云主機等)的監控指標數據,能夠采集到的指標包括CPU, 內存,磁盤,網絡,文件數等信息。

# 上傳node-exporter.tar.gz到harbor
docker load -i node-exporter.tar.gz
docker tag prom/node-exporter:v0.16.0 172.16.80.140/node-exporter/node-exporter:v0.16.0
docker push 172.16.80.140/node-exporter/node-exporter:v0.16.0
# 創建daemon控制器的yaml
[root@mast01 prometheus]#  vi node-export.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:name: node-exporternamespace: monitoringlabels:name: node-exporter
spec:selector:matchLabels:name: node-exportertemplate:metadata:labels:name: node-exporterspec:hostPID: truehostIPC: truehostNetwork: truecontainers:- name: node-exporterimage: 172.16.80.140/node-exporter/node-exporter:v0.16.0imagePullPolicy: IfNotPresentports:- containerPort: 9100resources:requests:cpu: 0.15securityContext:privileged: trueargs:- --path.procfs- /host/proc- --path.sysfs- /host/sys- --collector.filesystem.ignored-mount-points- '"^/(sys|proc|dev|host|etc)($|/)"'volumeMounts:- name: devmountPath: /host/dev- name: procmountPath: /host/proc- name: sysmountPath: /host/sys- name: rootfsmountPath: /rootfstolerations:- key: "node-role.kubernetes.io/control-plane"operator: "Exists"effect: "NoSchedule"volumes:- name: prochostPath:path: /proc- name: devhostPath:path: /dev- name: syshostPath:path: /sys- name: rootfshostPath:path: /
# hostNetwork、hostIPC、hostPID都為True時,表示這個Pod里的所有容器,會直接使用宿主機的網絡,直接與宿主機進行IPC(進程間通信)通信,可以看到宿主機里正在運行的所有進程。加入了hostNetwork:true會直接將我們的宿主機的9100端口映射出來,從而不需要創建service 在我們的宿主機上就會有一個9100的端口

? 該yaml會在每個節點上部署一個node-exporter

[root@mast01 prometheus]# netstat -an | grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN
[root@mast01 prometheus]# kubectl get pods -n monitoring -owide
NAME                 READY STATUS  RESTARTS AGE IP            NODE   NOMINATED NODE   READINESS GATES
node-exporter-5ms5j  1/1   Running 0        7s  172.16.80.133 node02 <none>    <none>
node-exporter-dgg2z  1/1   Running 0        9s  172.16.80.131 mast01 <none>    <none>
node-exporter-k4mf5  1/1   Running 0        6s  172.16.80.132 node01 <none>    <none>

? 通過curl可獲取主機信息

[root@mast01 prometheus]# curl http://172.16.80.131:9100/metrics | more% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.00010856
go_gc_duration_seconds{quantile="0.25"} 0.00010856
go_gc_duration_seconds{quantile="0.5"} 0.000879866
go_gc_duration_seconds{quantile="0.75"} 0.000879866
go_gc_duration_seconds{quantile="1"} 0.000879866
go_gc_duration_seconds_sum 0.000988426
go_gc_duration_seconds_count 2
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 6
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.9.6"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 1.863448e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 5.928912e+06
......
curl http://172.16.80.131:9100/metrics | grep node_cpu_seconds   # 顯示cpu使用情況% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 91593  100 91593    0     0  6934k      0 --:--:-- # HELP node_cpu_seconds_total Seconds the cpus spent in each mode.
--:--# TYPE node_cpu_seconds_total counter     # counter類型,只增不減
:--node_cpu_seconds_total{cpu="0",mode="idle"} 74516.69-node_cpu_seconds_total{cpu="0",mode="iowait"} 13.52
-:node_cpu_seconds_total{cpu="0",mode="irq"} 0
--node_cpu_seconds_total{cpu="0",mode="nice"} 0.03
:-node_cpu_seconds_total{cpu="0",mode="softirq"} 76.96
- node_cpu_seconds_total{cpu="0",mode="steal"} 0
74node_cpu_seconds_total{cpu="0",mode="system"} 601.74
53node_cpu_seconds_total{cpu="0",mode="user"} 1234.91
knode_cpu_seconds_total{cpu="1",mode="idle"} 74511.08node_cpu_seconds_total{cpu="1",mode="iowait"} 24.89
node_cpu_seconds_total{cpu="1",mode="irq"} 0
node_cpu_seconds_total{cpu="1",mode="nice"} 0.18
node_cpu_seconds_total{cpu="1",mode="softirq"} 86.84
node_cpu_seconds_total{cpu="1",mode="steal"} 0
node_cpu_seconds_total{cpu="1",mode="system"} 598.25
node_cpu_seconds_total{cpu="1",mode="user"} 1217.33curl http://172.16.80.131:9100/metrics | grep node_load # 最近一分鐘內負載使用情況% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0# HELP node_load1 1m load average.
# TYPE node_load1 gauge   # gauge類型,可增可減
node_load1 0.27
# HELP node_load15 15m load average.
# TYPE node_load15 gauge
node_load15 0.42
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 0.43
100 91584  100 91584    0     0  8262k      0 --:--:-- --:--:-- --:--:-- 8943k

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/72683.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/72683.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/72683.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

為什么“連接斷開可能導致鎖未釋放”

目錄 兩種典型場景可能導致鎖未及時釋放1. **數據庫未及時檢測到連接斷開**2. **應用程序未正確處理事務** 為什么說“可能因連接斷開導致死鎖”&#xff1f;如何避免此類問題&#xff1f;總結 在大多數數據庫實現中&#xff0c;如果持有鎖的連接&#xff08;或會話&#xff09…

【實戰指南】基于DevExpress輕量化主題實現WPF應用性能升級

DevExpress WPF擁有120個控件和庫&#xff0c;將幫助您交付滿足甚至超出企業需求的高性能業務應用程序。通過DevExpress WPF能創建有著強大互動功能的XAML基礎應用程序&#xff0c;這些應用程序專注于當代客戶的需求和構建未來新一代支持觸摸的解決方案。 無論是Office辦公軟件…

【C++多線程】C++異步線程池提交任務的寫法和解釋

// 提交任務到線程池 template<class F, class... Args> auto ThreadPool::enqueue(F&& f, Args&&... args) -> std::future<typename std::result_of<F(Args...)>::type> {using return_type typename std::result_of<F(Args...)>…

CSS 屬性選擇器詳解

CSS 屬性選擇器詳解 引言 CSS(層疊樣式表)是網頁設計中的重要組成部分,它用于控制網頁元素的樣式和布局。屬性選擇器是CSS選擇器的一種,它允許開發者根據元素的特定屬性來選擇和樣式化元素。本文將詳細講解CSS屬性選擇器的概念、語法以及常用屬性選擇器的使用方法。 一、…

二維前綴矩陣

1.大衣的旅行 #include<bits/stdc.h> #define int long long using namespace std; int t; int n,m,k; bool check(int mid,vector<vector<int>>pre,vector<vector<int>>a) {for(int i1; i<n; i){for(int j1; j<m; j){//枚舉以老師房間為…

python-leetcode 56.電話號碼的字母組合

題目&#xff1a; 給定一個僅包含數字的2-9的字符串&#xff0c;返回所有它可能表示的字母組合&#xff0c;答案可以按任意順序返回 給出數字到字母的映射如下&#xff08;與電話按鍵相同&#xff09;&#xff0c;注意1不對應任何字母 方法一&#xff1a;深度優先搜索&#x…

keepalived應用

Keepalived 是一個基于 VRRP&#xff08;虛擬路由冗余協議&#xff09;實現的高可用解決方案&#xff0c;常用于構建高可用性的服務器集群&#xff0c;特別是在負載均衡場景中&#xff0c;可確保服務的不間斷運行。以下為你詳細介紹它&#xff1a; 0主要功能 高可用性&#x…

5.0 VisionPro調用USB相機的方法與步驟說明(一)

本文介紹如何在C#中調用visionPro以處理USB相機采集到的圖片。示例如下: 主要思路如下: 1. 使用AForge來打開以及采集usb相機照片。 usb相機處于一直運行狀態。每隔100ms采集一次照片。且觸發一次事件。 public void Start() { this.videoSourcePlayer.Stop(); …

論文閱讀:Deep Hybrid Camera Deblurring for Smartphone Cameras

今天介紹一篇 ACM SIGGRAPH 2024 的文章&#xff0c;關于手機影像中的去模糊的文章。 Deep Hybrid Camera Deblurring for Smartphone Cameras Abstract 手機攝像頭盡管取得了顯著的進步&#xff0c;但由于傳感器和鏡頭較為緊湊&#xff0c;在低光環境下的成像仍存在困難&am…

Linux中的基本指令(下)

目錄 mv指令 more指令 less指令 head指令 tail 指令 繼續理解文件 重定向和追加重定向操作 理解管道 find指令 whereis 指令 bc指令 uname ?r指令 grep 指令 關機 擴展命令 zip/unzip 指令 tar指令 關于rzsz 系統間的文件互傳 接上&#xff01; mv指令 m…

Unity大型游戲開發全流程指南

一、開發流程與核心步驟 1. 項目規劃與設計階段 需求分析 明確游戲類型&#xff08;MMORPG/開放世界/競技等&#xff09;、核心玩法&#xff08;戰斗/建造/社交&#xff09;、目標平臺&#xff08;PC/移動/主機&#xff09;示例&#xff1a;MMORPG需規劃角色成長樹、副本Boss…

Unity WebGL IIS報錯無法使用

Unity WebGL IIS報錯無法使用 原因1&#xff1a;WebGL文件夾無訪問權限 右鍵WebGL文件夾-屬性 點擊安全-編輯-添加 輸入ever點擊確定-應用即可

【JDK17】開源應用服務器大比對

接著 next-public 源代碼分析&#xff0c;Java 應用服務器選用 jetty。但是之前普遍使用 Tomcat&#xff0c;那為什么要用 jetty 么&#xff0c;除了這兩個&#xff0c;Java 應用服務器開源現狀并不了解&#xff0c;故而又是一篇科普性的筆記&#xff0c;以下是 又小又快的 Jav…

docker-compose install nginx(解決fastgpt跨區域)

CORS前言 CORS(Cross-Origin Resource Sharing,跨源資源共享)是一種安全措施,它允許或拒絕來自不同源(協議、域名、端口任一不同即為不同源)的網頁訪問另一源中的資源。它的主要作用如下: 同源策略限制:Web 瀏覽器的同源策略限制了從一個源加載的文檔或腳本如何與另一…

算法刷題記錄——LeetCode篇(4) [第301~400題](持續更新)

(優先整理熱門100及面試150&#xff0c;不定期持續更新&#xff0c;歡迎關注) 322. 零錢兌換 給你一個整數數組 coins &#xff0c;表示不同面額的硬幣&#xff1b;以及一個整數 amount &#xff0c;表示總金額。 計算并返回可以湊成總金額所需的最少的硬幣個數。如果沒有任何…

vulnhub靶場之loly靶機

前言 挑戰攻克該靶機30分鐘 靶機&#xff1a;loly靶機&#xff0c;IP地址為192.168.10.11 攻擊&#xff1a;kali&#xff0c;IP地址為192.168.10.6 靶機和攻擊機都采用VMware虛擬機&#xff0c;都采用橋接網卡模式 文章涉及的靶機及工具&#xff0c;都可以自行訪問官網或者項…

Deepseek API+Python測試用例一鍵生成與導出-V1.0.2【實現需求文檔圖片識別與用例生成自動化】

在測試工作中&#xff0c;需求文檔中的圖片&#xff08;如界面設計圖、流程圖&#xff09;往往是測試用例生成的重要參考。然而&#xff0c;手動提取圖片并識別內容不僅耗時&#xff0c;還容易出錯。本文將通過一個自研小工具&#xff0c;結合 PaddleOCR 和大模型&#xff0c;自…

Excel(函數篇):COUNTIF與CONUTIFS函數、SUMIF與SUMIFS函數、ROUND函數、MATCH與INDEX函數、混合引用與條件格式

目錄 COUNTIF和COUNTIFS函數COUNTIF函數COUNTIFS函數SUMIF和SUMIFS函數SUMIF函數SUMIFS函數SUMIFS函數與控件實現動態年月匯總ROUND、ROUNDUP、ROUNDDOWN函數單元格混合引用條件格式與公式,標記整行數據MATCH和INDEX函數COUNTIF和COUNTIFS函數 COUNTIF函數 統計下“蘇州”出現…

上位機數據可視化:使用QtCharts繪制波形圖

工程配置 CMake文件 find_package(Qt5 COMPONENTS Charts REQUIRED)target_link_libraries(zhd-desktop PRIVATE Qt5::Charts)包含頭文件以及名稱空間&#xff08;這個很重要&#xff0c;沒有包含名稱空間編譯器會提示找不到相關的類型&#xff09; #include <QtCharts&g…

S32K144入門筆記(十三):LPIT的API函數解讀

目錄 1. SDK中的函數 2. API函數的釋義 2.1 獲取默認參數 2.2 初始化 2.3 啟動與停止 2.4 計數值的設置于讀取 2.5 中斷API 1. SDK中的函數 在使用SDK的非抽象驅動函數時&#xff0c;函數的定義與聲明在文件lpit_driver.c和lpit_driver.h中&#xff0c;一共有19個函數&a…