环境准备
系统Centos 7.9
k8s集群:
版本:1.21.5
节点:
192.168.10.201 master
192.168.10.202 work
部署相关配置文件
kube-state-metrics-rbac.yaml
apiVersion:v1kind:ServiceAccountmetadata:name:kube-state-metricsnamespace:kube-systemlabels:kubernetes.io/cluster-service:"true"addonmanager.kubernetes.io/mode:Reconcile---apiVersion:rbac.authorization.k8s.io/v1kind:ClusterRolemetadata:name:kube-state-metricslabels:kubernetes.io/cluster-service:"true"addonmanager.kubernetes.io/mode:Reconcilerules:-apiGroups:[""]resources:-configmaps-secrets-nodes-pods-services-resourcequotas-replicationcontrollers-limitranges-persistentvolumeclaims-persistentvolumes-namespaces-endpointsverbs:["list","watch"]-apiGroups:["apps"]resources:-statefulsets-daemonsets-deployments-replicasetsverbs:["list","watch"]-apiGroups:["batch"]resources:-cronjobs-jobsverbs:["list","watch"]-apiGroups:["autoscaling"]resources:-horizontalpodautoscalersverbs:["list","watch"]-apiGroups:["networking.k8s.io","extensions"]resources:-ingressesverbs:["list","watch"]-apiGroups:["storage.k8s.io"]resources:-storageclassesverbs:["list","watch"]-apiGroups:["certificates.k8s.io"]resources:-certificatesigningrequestsverbs:["list","watch"]-apiGroups:["policy"]resources:-poddisruptionbudgetsverbs:["list","watch"]---apiVersion:rbac.authorization.k8s.io/v1kind:Rolemetadata:name:kube-state-metrics-resizernamespace:kube-systemlabels:kubernetes.io/cluster-service:"true"addonmanager.kubernetes.io/mode:Reconcilerules:-apiGroups:[""]resources:-podsverbs:["get"]-apiGroups:["extensions","apps"]resources:-deploymentsresourceNames:["kube-state-metrics"]verbs:["get","update"]---apiVersion:rbac.authorization.k8s.io/v1kind:ClusterRoleBindingmetadata:name:kube-state-metricslabels:kubernetes.io/cluster-service:"true"addonmanager.kubernetes.io/mode:ReconcileroleRef:apiGroup:rbac.authorization.k8s.iokind:ClusterRolename:kube-state-metricssubjects:-kind:ServiceAccountname:kube-state-metricsnamespace:kube-system---apiVersion:rbac.authorization.k8s.io/v1kind:RoleBindingmetadata:name:kube-state-metricsnamespace:kube-systemlabels:kubernetes.io/cluster-service:"true"addonmanager.kubernetes.io/mode:ReconcileroleRef:apiGroup:rbac.authorization.k8s.iokind:Rolename:kube-state-metrics-resizersubjects:-kind:ServiceAccountname:kube-state-metricsnamespace:kube-system
kube-state-metrics-deployment.yaml 配置
apiVersion apps/v1 kind Deployment metadata name kube-state-metrics namespace kube-system labels k8s-app kube-state-metrics kubernetes.io/cluster-service"true" addonmanager.kubernetes.io/mode Reconcile version v1.3.0 spec selector matchLabels k8s-app kube-state-metrics version v1.3.0 replicas1 template metadata labels k8s-app kube-state-metrics version v1.3.0 annotations scheduler.alpha.kubernetes.io/critical-pod'' spec priorityClassName system-cluster-critical serviceAccountName kube-state-metrics containersname kube-state-metrics image lizhenliang/kube-state-metrics v1.8.0 portsname http-metrics containerPort8080name telemetry containerPort8081 readinessProbe httpGet path /healthz port8080 initialDelaySeconds5 timeoutSeconds5name addon-resizer image lizhenliang/addon-resizer1.8.6 resources limits cpu 100m memory 30Mi requests cpu 100m memory 30Mi envname MY_POD_NAME valueFrom fieldRef fieldPath metadata.name name MY_POD_NAMESPACE valueFrom fieldRef fieldPath metadata.namespace volumeMountsname config-volume mountPath /etc/config command /pod_nanny --config-dir=/etc/config --container=kube-state-metrics --cpu=100m --extra-cpu=1m --memory=100Mi --extra-memory=2Mi --threshold=5 --deployment=kube-state-metrics volumesname config-volume configMap name kube-state-metrics-config ---apiVersion v1 kind ConfigMap metadata name kube-state-metrics-config namespace kube-system labels k8s-app kube-state-metrics kubernetes.io/cluster-service"true" addonmanager.kubernetes.io/mode Reconcile data NannyConfiguration - apiVersion nannyconfig/v1alpha1 kind NannyConfiguration
kube-state-metrics-service.yaml 配置
apiVersion v1 kind Service metadata name kube-state-metrics namespace kube-system labels kubernetes.io/cluster-service"true" addonmanager.kubernetes.io/mode Reconcile kubernetes.io/name"kube-state-metrics" annotations prometheus.io/scrape'true'spec portsname http-metrics port8080 targetPort http-metrics protocol TCP name telemetry port8081 targetPort telemetry protocol TCP selector k8s-app kube-state-metrics
创建 kube-state-metrics 服务
kubectlapply-f.
查看服务启动状态
打开prometheus控制台