yaml:
https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/metrics-server
请注意:测试环境
需要修改的地方:
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.6
namespace: kube-system
labels:
k8s-app: metrics-server
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
version: v0.3.6
spec:
selector:
matchLabels:
k8s-app: metrics-server
version: v0.3.6
template:
metadata:
name: metrics-server
labels:
k8s-app: metrics-server
version: v0.3.6
annotations:
seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
spec:
priorityClassName: system-cluster-critical
serviceAccountName: metrics-server
nodeSelector:
kubernetes.io/os: linux
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server-amd64:v0.3.6
#修改镜像拉取方式
imagePullPolicy: IfNotPresent
command:
#加入下列2行代码,解释Flag --deprecated-kubelet-completely-insecure has been deprecated,
#This is rarely the right option, since it leaves kubelet communication completely
#insecure. If #you encounter auth errors, make sure you've enabled token webhook auth on
#the Kubelet, and if #you're in a test cluster with self-signed Kubelet certificates,
#consider using kubelet-insecure-#tls instead.:
- /metrics-server
- --metric-resolution=30s
- --kubelet-insecure-tls
# 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.
# 注释该行代码。10255端口已经默认废弃
#- --kubelet-port=10255
#注释该行代码
#- --deprecated-kubelet-completely-insecure=true
#- --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.11
imagePullPolicy: IfNotPresent
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=80m
- --extra-cpu=0.5m
- --memory=80Mi
- --extra-memory=80Mi
- --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={{ metrics_server_min_cluster_size }}
# Use kube-apiserver metrics to avoid periodically listing nodes.
- --use-metrics=true
volumes:
- name: metrics-server-config-volume
configMap:
name: metrics-server-config
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
遇到的问题(1):
```yaml
E0731 14:41:44.340879 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): Get http://192.168.8.10:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.10:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): Get http://192.168.8.12:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.12:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): Get http://192.168.8.11:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.11:10255: connect: connection refused]
E0731 14:42:14.328932 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): Get http://192.168.8.10:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.10:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): Get http://192.168.8.11:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.11:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): Get http://192.168.8.12:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.12:10255: connect: connection refused]
E0731 14:42:44.341216 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): Get http://192.168.8.12:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.12:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): Get http://192.168.8.10:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.10:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): Get http://192.168.8.11:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.11:10255: connect: connection refused]
E0731 14:43:14.327808 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): Get http://192.168.8.12:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.12:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): Get http://192.168.8.10:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.10:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): Get http://192.168.8.11:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.11:10255: connect: connection refused]
E0731 14:43:44.340386 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): Get http://192.168.8.12:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.12:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): Get http://192.168.8.11:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.11:10255: connect: connection refused, unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): Get http://192.168.8.10:10255/stats/summary?only_cpu_and_memory=true: dial tcp 192.168.8.10:10255: connect: connection refused]
解决办法: 注释以下条目
- –kubelet-port=10255
遇到的问题(2):
E0731 14:13:35.439656 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n", unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n", unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n"]
E0731 14:14:05.428724 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n", unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n", unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n"]
E0731 14:14:35.440679 1 manager.go:111] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:master3: unable to fetch metrics from Kubelet master3 (192.168.8.12): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n", unable to fully scrape metrics from source kubelet_summary:k8s-ha: unable to fetch metrics from Kubelet k8s-ha (192.168.8.10): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n", unable to fully scrape metrics from source kubelet_summary:master2: unable to fetch metrics from Kubelet master2 (192.168.8.11): request failed - "400 Bad Request", response: "Client sent an HTTP request to an HTTPS server.\n"]
解决办法:
注释:- --deprecated-kubelet-completely-insecure=true