k8s 1.14部署metrics server显示running但是报ServiceUnavailable错误

k8s 1.14部署metrics server显示running但是报ServiceUnavailable错误

查看metrics server日志: [root@master metrics-server-latest]# kubectl logs -f metrics-server-v0.3.6-b59d6b7cb-9ftdf -nkube-system metrics-server I0514 03:15:00.3257621 serving.go:312] Generated self-signed cert (apiserver.local.config/certificates/apiserver.crt, apiserver.local.config/certificates/apiserver.key) I0514 03:15:04.9241721 secure_serving.go:116] Serving securely on [::]:443 从日志看没有任何异常,但是执行[root@master ~]# kubectl top nodes时报如下错误,获取不到指标数据 Error from server (ServiceUnavailable): the server is currently unable to handle the request (get pods.metrics.k8s.io)

【k8s 1.14部署metrics server显示running但是报ServiceUnavailable错误】找了很久的资料也没解决,后来看一github上一个大牛最终解决了。具体链接https://github.com/kubernetes-sigs/metrics-server/issues/157
整个过程的配置文件如下(注意带#的说明是修改的部分)
  • metrics-server-deployment.yaml(完整代码见文章末尾)
hostNetwork: true #增加 containers: - name: metrics-server image: k8s.gcr.io/metrics-server-amd64:v0.3.6 command: - /metrics-server - --metric-resolution=30s - --requestheader-allowed-names=aggregator#增加修改 # These are needed for GKE, which doesn't support secure communication yet. # Remove these lines for non-GKE clusters, and when GKE supports token-based auth. #- --kubelet-port=10255#注释 #- --deprecated-kubelet-completely-insecure=true#注释 - --kubelet-insecure-tls#增加 - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP ports: - containerPort: 443 name: https protocol: TCP - name: metrics-server-nanny image: k8s.gcr.io/addon-resizer:1.8.7 resources: limits: cpu: 100m memory: 300Mi requests: cpu: 5m memory: 50Mi env: - name: MY_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: MY_POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace volumeMounts: - name: metrics-server-config-volume mountPath: /etc/config command: - /pod_nanny - --config-dir=/etc/config #- --cpu={{ base_metrics_server_cpu }}#注释 - --cpu=80m#增加 - --extra-cpu=0.5m #- --storage=5Gi #- --memory={{ base_metrics_server_memory }}#注释 - --memory=100Mi#增加 #- --extra-memory={{ metrics_server_memory_per_node }}Mi#注释 - --extra-memory=100Mi#修改 - --threshold=5 - --deployment=metrics-server-v0.3.6 - --container=metrics-server - --poll-period=300000 - --estimator=exponential # Specifies the smallest cluster (defined in number of nodes) # resources will be scaled to. #- --minClusterSize=2#注释

  • resource-reader.yaml
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: system:metrics-server labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile rules: - apiGroups: - "" resources: - pods - nodes - nodes/stats#增加 - namespaces

  • 更新kubectl apply -f .后再次查看,正常了
[root@master manifests]# kubectl top nodes NAMECPU(cores)CPU%MEMORY(bytes)MEMORY% master252m6%978Mi12% worker149m1%1442Mi54% worker247m1%1380Mi51% worker346m1%1232Mi46%

  • metrics-server-deployment.yaml完整代码
apiVersion: v1 kind: ServiceAccount metadata: name: metrics-server namespace: kube-system labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile --- apiVersion: v1 kind: ConfigMap metadata: name: metrics-server-config namespace: kube-system labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: EnsureExists data: NannyConfiguration: |- apiVersion: nannyconfig/v1alpha1 kind: NannyConfiguration --- apiVersion: apps/v1 kind: Deployment metadata: name: metrics-server-v0.3.3 namespace: kube-system labels: k8s-app: metrics-server kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile version: v0.3.3 spec: selector: matchLabels: k8s-app: metrics-server version: v0.3.3 template: metadata: name: metrics-server labels: k8s-app: metrics-server version: v0.3.3 annotations: scheduler.alpha.kubernetes.io/critical-pod: '' seccomp.security.alpha.kubernetes.io/pod: 'docker/default' spec: priorityClassName: system-cluster-critical serviceAccountName: metrics-server containers: - name: metrics-server image: k8s.gcr.io/metrics-server-amd64:v0.3.3 command: - /metrics-server - --metric-resolution=30s # These are needed for GKE, which doesn't support secure communication yet. # Remove these lines for non-GKE clusters, and when GKE supports token-based auth. #- --kubelet-port=10255 #- --deprecated-kubelet-completely-insecure=true - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalIP #- --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP ports: - containerPort: 443 name: https protocol: TCP - name: metrics-server-nanny image: k8s.gcr.io/addon-resizer:1.8.5 resources: limits: cpu: 100m memory: 300Mi requests: cpu: 5m memory: 50Mi env: - name: MY_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: MY_POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace volumeMounts: - name: metrics-server-config-volume mountPath: /etc/config command: - /pod_nanny - --config-dir=/etc/config #- --cpu={{ base_metrics_server_cpu }} - --extra-cpu=0.5m #- --memory={{ base_metrics_server_memory }} #- --extra-memory={{ metrics_server_memory_per_node }}Mi - --threshold=5 - --deployment=metrics-server-v0.3.3 - --container=metrics-server - --poll-period=300000 - --estimator=exponential # Specifies the smallest cluster (defined in number of nodes) # resources will be scaled to. - --minClusterSize=2 volumes: - name: metrics-server-config-volume configMap: name: metrics-server-config tolerations: - key: "CriticalAddonsOnly" operator: "Exists"

个人博客地址:http://www.lampnick.com/php/921

    推荐阅读