對(duì)比
node-exporter用于采集服務(wù)器層面的運(yùn)行指標(biāo),包括機(jī)器的loadavg、filesystem、meminfo等基礎(chǔ)監(jiān)控,類似于傳統(tǒng)主機(jī)監(jiān)控維度的zabbix-agent。 metric-server/heapster是從api-server中獲取CPU、內(nèi)存使用率這種監(jiān)控指標(biāo),并把他們發(fā)送給存儲(chǔ)后端,如InfluxDB或云廠商,他當(dāng)前的核心作用是:為HPA等組件提供決策指標(biāo)支持。 kube-state-metrics關(guān)注于獲取Kubernetes各種資源的最新狀態(tài),如Deployment或者DaemonSet。 例如:-
我調(diào)度了多少個(gè)Replicas?現(xiàn)在可用的有幾個(gè)?
-
多少個(gè)Pod是running/stopped/terminated狀態(tài)?
-
Pod重啟了多少次?
-
我有多少job在運(yùn)行中?
-
metric-server僅僅是獲取、格式化現(xiàn)有數(shù)據(jù),寫(xiě)入特定的存儲(chǔ),實(shí)質(zhì)上是一個(gè)監(jiān)控系統(tǒng)。
-
kube-state-metrics是將Kubernetes的運(yùn)行狀況在內(nèi)存中做了個(gè)快照,并且獲取新的指標(biāo),但他沒(méi)有能力導(dǎo)出這些指標(biāo)。
部署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文件為如下內(nèi)容:#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#修改鏡像為剛剛拉取下來(lái)的鏡像 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是否出現(xiàn)在Kubernetes集群的API群組列表中:#kubectlapi-versions|grepmetrics metrics.k8s.io/v1beta1
使用
kubectl top命令可顯示節(jié)點(diǎn)和Pod對(duì)象的資源使用信息,它依賴于集群中的資源指標(biāo)API來(lái)收集各項(xiàng)指標(biāo)數(shù)據(jù)。它包含有Node和Pod兩個(gè)子命令,可分別顯示Node對(duì)象和Pod對(duì)象的相關(guān)資源占用率。 列出Node資源占用率命令的語(yǔ)法格式為“kubectl top node [-l label | NAME]”,例如下面顯示所有節(jié)點(diǎn)的資源占用狀況的結(jié)果中顯示了各節(jié)點(diǎn)累計(jì)CPU資源占用時(shí)長(zhǎng)及百分比,以及內(nèi)容空間占用量及占用比例。必要時(shí),也可以在命令直接給出要查看的特定節(jié)點(diǎn)的標(biāo)識(shí),以及使用標(biāo)簽選擇器進(jìn)行節(jié)點(diǎn)過(guò)濾。[root@mastermetric]#kubectltopnodes NAMECPU(cores)CPU%MEMORY(bytes)MEMORY% master282m14%1902Mi51% node-0270m3%1371Mi37% node-03121m1%892Mi11%
而名稱空間級(jí)別的Pod對(duì)象資源占用率的使用方法會(huì)略有不同,使用時(shí),一般應(yīng)該跟定名稱空間及使用標(biāo)簽選擇器過(guò)濾出目標(biāo)Pod對(duì)象。例如,下面顯示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命令為用戶提供簡(jiǎn)潔、快速獲取Node對(duì)象及Pod對(duì)象系統(tǒng)資源占用狀況的接口,是集群運(yùn)行和維護(hù)的常用命令之一。 原文鏈接:https://juejin.cn/post/6996862439560052773-
cpu
+關(guān)注
關(guān)注
68文章
10807瀏覽量
210852 -
服務(wù)器
+關(guān)注
關(guān)注
12文章
8963瀏覽量
85087 -
API
+關(guān)注
關(guān)注
2文章
1472瀏覽量
61750 -
機(jī)器
+關(guān)注
關(guān)注
0文章
777瀏覽量
40667
原文標(biāo)題:Kubernetes監(jiān)控指標(biāo)獲取方式對(duì)比
文章出處:【微信號(hào):magedu-Linux,微信公眾號(hào):馬哥Linux運(yùn)維】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論