一旦工作,那就要努力的干,聪明的干,快速的干——用省下来的时间干自己喜欢干的事情。!

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

linux lampnick 373℃ 0评论

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.325762       1 serving.go:312] Generated self-signed cert (apiserver.local.config/certificates/apiserver.crt, apiserver.local.config/certificates/apiserver.key)
I0514 03:15:04.924172       1 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)

找了很久的资料也没解决,后来看一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
    NAME      CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
    master    252m         6%     978Mi           12%       
    worker1   49m          1%     1442Mi          54%       
    worker2   47m          1%     1380Mi          51%       
    worker3   46m          1%     1232Mi          46% 

转载请注明:lampNick » k8s 1.14部署metrics server显示running但是报ServiceUnavailable错误

喜欢 (13)or分享 (0)
头像
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址