對比
node-exporter用于采集服務器層面的運行指標,包括機器的loadavg、filesystem、meminfo等基礎監控,類似于傳統主機監控維度的zabbix-agent。 metric-server/heapster是從api-server中獲取CPU、內存使用率這種監控指標,并把他們發送給存儲后端,如InfluxDB或云廠商,他當前的核心作用是:為HPA等組件提供決策指標支持。 kube-state-metrics關注于獲取Kubernetes各種資源的最新狀態,如Deployment或者DaemonSet。 例如:-
我調度了多少個Replicas?現在可用的有幾個?
-
多少個Pod是running/stopped/terminated狀態?
-
Pod重啟了多少次?
-
我有多少job在運行中?
-
metric-server僅僅是獲取、格式化現有數據,寫入特定的存儲,實質上是一個監控系統。
-
kube-state-metrics是將Kubernetes的運行狀況在內存中做了個快照,并且獲取新的指標,但他沒有能力導出這些指標。
部署metric-server
wgethttps://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.7/components.yaml
拉取metric-server的鏡像到本地:#dockerpullzhaoqinchang/metrics-server:0.3.7 0.3.7:Pullingfromzhaoqinchang/metrics-server 9ff2acc3204b:Pullcomplete 9d14b55ff9a0:Pullcomplete Digest:sha256:c0efe772bb9e5c289db6cc4bc2002c268507d0226f2a3815f7213e00261c38e9 Status:Downloadednewerimageforzhaoqinchang/metrics-server:0.3.7 docker.io/zhaoqinchang/metrics-server:0.3.7
修改components.yaml文件為如下內容:#catcomponents.yaml --- apiVersion:rbac.authorization.k8s.io/v1 kind:ClusterRole metadata: name:system:aggregated-metrics-reader labels: rbac.authorization.k8s.io/aggregate-to-view:"true" rbac.authorization.k8s.io/aggregate-to-edit:"true" rbac.authorization.k8s.io/aggregate-to-admin:"true" rules: -apiGroups:["metrics.k8s.io"] resources:["pods","nodes"] verbs:["get","list","watch"] --- apiVersion:rbac.authorization.k8s.io/v1 kind:ClusterRoleBinding metadata: name:metrics-serverauth-delegator roleRef: apiGroup:rbac.authorization.k8s.io kind:ClusterRole name:system:auth-delegator subjects: -kind:ServiceAccount name:metrics-server namespace:kube-system --- apiVersion:rbac.authorization.k8s.io/v1 kind:RoleBinding metadata: name:metrics-server-auth-reader namespace:kube-system roleRef: apiGroup:rbac.authorization.k8s.io kind:Role name:extension-apiserver-authentication-reader subjects: -kind:ServiceAccount name:metrics-server namespace:kube-system --- apiVersion:apiregistration.k8s.io/v1beta1 kind:APIService metadata: name:v1beta1.metrics.k8s.io spec: service: name:metrics-server namespace:kube-system group:metrics.k8s.io version:v1beta1 insecureSkipTLSVerify:true groupPriorityMinimum:100 versionPriority:100 --- apiVersion:v1 kind:ServiceAccount metadata: name:metrics-server namespace:kube-system --- apiVersion:apps/v1 kind:Deployment metadata: name:metrics-server namespace:kube-system labels: k8s-app:metrics-server spec: selector: matchLabels: k8s-app:metrics-server template: metadata: name:metrics-server labels: k8s-app:metrics-server spec: serviceAccountName:metrics-server volumes: #mountintmpsowecansafelyusefrom-scratchimagesand/orread-onlycontainers -name:tmp-dir emptyDir:{} containers: -name:metrics-server image:zhaoqinchang/metrics-server:0.3.7#修改鏡像為剛剛拉取下來的鏡像 imagePullPolicy:IfNotPresent args: ---cert-dir=/tmp ---secure-port=4443 command:#添加以下三行command命令 -/metrics-server ---kubelet-preferred-address-types=InternalIP ---kubelet-insecure-tls ports: -name:main-port containerPort:4443 protocol:TCP securityContext: readOnlyRootFilesystem:true runAsNonRoot:true runAsUser:1000 volumeMounts: -name:tmp-dir mountPath:/tmp nodeSelector: kubernetes.io/os:linux --- apiVersion:v1 kind:Service metadata: name:metrics-server namespace:kube-system labels: kubernetes.io/name:"Metrics-server" kubernetes.io/cluster-service:"true" spec: selector: k8s-app:metrics-server ports: -port:443 protocol:TCP targetPort:main-port --- apiVersion:rbac.authorization.k8s.io/v1 kind:ClusterRole metadata: name:system:metrics-server rules: -apiGroups: -"" resources: -pods -nodes -nodes/stats -namespaces -configmaps verbs: -get -list -watch --- apiVersion:rbac.authorization.k8s.io/v1 kind:ClusterRoleBinding metadata: name:system:metrics-server roleRef: apiGroup:rbac.authorization.k8s.io kind:ClusterRole name:system:metrics-server subjects: -kind:ServiceAccount name:metrics-server namespace:kube-system 部署metric-server:
#kubectlapply-fcomponents.yaml clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-readercreated clusterrolebinding.rbac.authorization.k8s.io/metrics-serverauth-delegatorcreated rolebinding.rbac.authorization.k8s.io/metrics-server-auth-readercreated apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.iocreated serviceaccount/metrics-servercreated deployment.apps/metrics-servercreated service/metrics-servercreated clusterrole.rbac.authorization.k8s.io/system:metrics-servercreated clusterrolebinding.rbac.authorization.k8s.io/system:metrics-servercreated
查看metric.k8s.io是否出現在Kubernetes集群的API群組列表中:#kubectlapi-versions|grepmetrics metrics.k8s.io/v1beta1
使用
kubectl top命令可顯示節點和Pod對象的資源使用信息,它依賴于集群中的資源指標API來收集各項指標數據。它包含有Node和Pod兩個子命令,可分別顯示Node對象和Pod對象的相關資源占用率。 列出Node資源占用率命令的語法格式為“kubectl top node [-l label | NAME]”,例如下面顯示所有節點的資源占用狀況的結果中顯示了各節點累計CPU資源占用時長及百分比,以及內容空間占用量及占用比例。必要時,也可以在命令直接給出要查看的特定節點的標識,以及使用標簽選擇器進行節點過濾。[root@mastermetric]#kubectltopnodes NAMECPU(cores)CPU%MEMORY(bytes)MEMORY% master282m14%1902Mi51% node-0270m3%1371Mi37% node-03121m1%892Mi11%
而名稱空間級別的Pod對象資源占用率的使用方法會略有不同,使用時,一般應該跟定名稱空間及使用標簽選擇器過濾出目標Pod對象。例如,下面顯示kube-system名稱空間下的Pod資源使用狀況:[root@mastermetric]#kubectltoppods-nkube-system NAMECPU(cores)MEMORY(bytes) etcd-master32m300Mi kube-apiserver-master86m342Mi kube-controller-manager-master30m48Mi kube-flannel-ds-l5ghn5m10Mi kube-flannel-ds-rqlm24m12Mi kube-flannel-ds-v92r94m14Mi kube-proxy-7vjcv18m15Mi kube-proxy-xrz8f13m21Mi kube-proxy-zpwn61m14Mi kube-scheduler-master7m17Mi metrics-server-5549c7694f-7vb662m14Mi
kubectl top命令為用戶提供簡潔、快速獲取Node對象及Pod對象系統資源占用狀況的接口,是集群運行和維護的常用命令之一。 原文鏈接:https://juejin.cn/post/6996862439560052773-
cpu
+關注
關注
68文章
10827瀏覽量
211179 -
服務器
+關注
關注
12文章
9028瀏覽量
85202 -
API
+關注
關注
2文章
1487瀏覽量
61827 -
機器
+關注
關注
0文章
779瀏覽量
40691
原文標題:Kubernetes監控指標獲取方式對比
文章出處:【微信號:magedu-Linux,微信公眾號:馬哥Linux運維】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論