当前位置:   article > 正文

Metrics API not available_error: metrics api not available

error: metrics api not available

root@master:~# kubectl top pod
error: Metrics API not available

kubernetes-sigs/metrics-server:适用于 Kubernetes 内置自动缩放管道的可扩展且高效的容器资源指标来源。 (github.com)

wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

vim components.yaml

修改为国内镜像,添加不认证CA证书- --kubelet-insecure-tls

- --kubelet-insecure-tls

 image: registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server:v0.6.2

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. labels:
  5. k8s-app: metrics-server
  6. name: metrics-server
  7. namespace: kube-system
  8. ---
  9. apiVersion: rbac.authorization.k8s.io/v1
  10. kind: ClusterRole
  11. metadata:
  12. labels:
  13. k8s-app: metrics-server
  14. rbac.authorization.k8s.io/aggregate-to-admin: "true"
  15. rbac.authorization.k8s.io/aggregate-to-edit: "true"
  16. rbac.authorization.k8s.io/aggregate-to-view: "true"
  17. name: system:aggregated-metrics-reader
  18. rules:
  19. - apiGroups:
  20. - metrics.k8s.io
  21. resources:
  22. - pods
  23. - nodes
  24. verbs:
  25. - get
  26. - list
  27. - watch
  28. ---
  29. apiVersion: rbac.authorization.k8s.io/v1
  30. kind: ClusterRole
  31. metadata:
  32. labels:
  33. k8s-app: metrics-server
  34. name: system:metrics-server
  35. rules:
  36. - apiGroups:
  37. - ""
  38. resources:
  39. - nodes/metrics
  40. verbs:
  41. - get
  42. - apiGroups:
  43. - ""
  44. resources:
  45. - pods
  46. - nodes
  47. verbs:
  48. - get
  49. - list
  50. - watch
  51. ---
  52. apiVersion: rbac.authorization.k8s.io/v1
  53. kind: RoleBinding
  54. metadata:
  55. labels:
  56. k8s-app: metrics-server
  57. name: metrics-server-auth-reader
  58. namespace: kube-system
  59. roleRef:
  60. apiGroup: rbac.authorization.k8s.io
  61. kind: Role
  62. name: extension-apiserver-authentication-reader
  63. subjects:
  64. - kind: ServiceAccount
  65. name: metrics-server
  66. namespace: kube-system
  67. ---
  68. apiVersion: rbac.authorization.k8s.io/v1
  69. kind: ClusterRoleBinding
  70. metadata:
  71. labels:
  72. k8s-app: metrics-server
  73. name: metrics-server:system:auth-delegator
  74. roleRef:
  75. apiGroup: rbac.authorization.k8s.io
  76. kind: ClusterRole
  77. name: system:auth-delegator
  78. subjects:
  79. - kind: ServiceAccount
  80. name: metrics-server
  81. namespace: kube-system
  82. ---
  83. apiVersion: v1
  84. kind: Service
  85. metadata:
  86. labels:
  87. k8s-app: metrics-server
  88. name: metrics-server
  89. namespace: kube-system
  90. spec:
  91. ports:
  92. - name: https
  93. port: 443
  94. protocol: TCP
  95. targetPort: https
  96. selector:
  97. k8s-app: metrics-server
  98. ---
  99. apiVersion: apps/v1
  100. kind: Deployment
  101. metadata:
  102. labels:
  103. k8s-app: metrics-server
  104. name: metrics-server
  105. namespace: kube-system
  106. spec:
  107. selector:
  108. matchLabels:
  109. k8s-app: metrics-server
  110. strategy:
  111. rollingUpdate:
  112. maxUnavailable: 0
  113. template:
  114. metadata:
  115. labels:
  116. k8s-app: metrics-server
  117. spec:
  118. containers:
  119. - args:
  120. - --cert-dir=/tmp
  121. - --secure-port=4443
  122. - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
  123. - --kubelet-use-node-status-port
  124. - --metric-resolution=15s
  125. - --kubelet-insecure-tls
  126. image: registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server:v0.6.2
  127. imagePullPolicy: IfNotPresent
  128. livenessProbe:
  129. failureThreshold: 3
  130. httpGet:
  131. path: /livez
  132. port: https
  133. scheme: HTTPS
  134. periodSeconds: 10
  135. name: metrics-server
  136. ports:
  137. - containerPort: 4443
  138. name: https
  139. protocol: TCP
  140. readinessProbe:
  141. failureThreshold: 3
  142. httpGet:
  143. path: /readyz
  144. port: https
  145. scheme: HTTPS
  146. initialDelaySeconds: 20
  147. periodSeconds: 10
  148. resources:
  149. requests:
  150. cpu: 100m
  151. memory: 200Mi
  152. securityContext:
  153. allowPrivilegeEscalation: false
  154. readOnlyRootFilesystem: true
  155. runAsNonRoot: true
  156. runAsUser: 1000
  157. volumeMounts:
  158. - mountPath: /tmp
  159. name: tmp-dir
  160. nodeSelector:
  161. kubernetes.io/os: linux
  162. priorityClassName: system-cluster-critical
  163. serviceAccountName: metrics-server
  164. volumes:
  165. - emptyDir: {}
  166. name: tmp-dir
  167. ---
  168. apiVersion: apiregistration.k8s.io/v1
  169. kind: APIService
  170. metadata:
  171. labels:
  172. k8s-app: metrics-server
  173. name: v1beta1.metrics.k8s.io
  174. spec:
  175. group: metrics.k8s.io
  176. groupPriorityMinimum: 100
  177. insecureSkipTLSVerify: true
  178. service:
  179. name: metrics-server
  180. namespace: kube-system
  181. version: v1beta1
  182. versionPriority: 100

第二种原因可能 metrics api不能用

查看:如果有数据说明正常

kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods
Error from server (NotFound): the serve

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/536351
推荐阅读
相关标签
  

闽ICP备14008679号