k8s || 安装metrics server
Metrics Server 是 Kubernetes 内置自动缩放管道的可扩展、高效的容器资源指标来源。Metrics Server 从 Kubelets 收集资源指标,并通过 Metrics API 在 Kubernetes apiserver 中公开它们,以供 Horizontal Pod Autoscaler 和Vertical Pod Autoscaler 使用。Metrics API
Metrics Server介绍
Metrics Server 是 Kubernetes 内置自动缩放管道的可扩展、高效的容器资源指标来源。
Metrics Server 从 Kubelets 收集资源指标,并通过 Metrics API 在 Kubernetes apiserver 中公开它们,以供 Horizontal Pod Autoscaler 和Vertical Pod Autoscaler 使用。Metrics API 也可以通过访问 kubectl top,从而更容易调试自动缩放管道。
Metrics Server 不适用于非自动缩放目的。例如,不要使用它来将指标转发给监控解决方案,或作为监控解决方案指标的来源。在这种情况下,请直接从 Kubelet/metrics/resource 端点收集指标。
特点
1、适用于大多数集群的单一部署
2、快速自动缩放,每 15 秒收集一次指标
3、资源效率,集群中每个节点使用 1mili 的 CPU 核心和 2MB 的内存
4、可扩展支持多达 5000 个节点集群
安装Metrics Server
第1步:下载components.yaml配置文件
wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
第2步:修改components.yaml配置文件
替换image
image: registry.aliyuncs.com/google_containers/metrics-server:v0.6.0
imagePullPolicy: IfNotPresent
args:
// 新增下面两行参数
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname
[root@k8smaster ~]# cat components.yaml
spec:
containers:
- args:
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname
- --cert-dir=/tmp
- --secure-port=4443
- --kubelet-use-node-status-port
- --metric-resolution=15s
image: registry.aliyuncs.com/google_containers/metrics-server:v0.6.0
imagePullPolicy: IfNotPresent
第3步:执行安装命令
[root@k8smaster ~]# kubectl apply -f components.yaml
serviceaccount/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
service/metrics-server created
deployment.apps/metrics-server created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
第四步:查看效果
[root@k8smaster ~]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-6949477b58-xf6vq 1/1 Running 2 46h
calico-node-7vvr5 1/1 Running 6 3d20h
calico-node-fqg8x 1/1 Running 5 3d20h
calico-node-rs6vw 1/1 Running 6 3d20h
coredns-7f89b7bc75-dvvsj 1/1 Running 2 46h
coredns-7f89b7bc75-ltqz7 1/1 Running 2 46h
etcd-k8smaster 1/1 Running 5 3d20h
kube-apiserver-k8smaster 1/1 Running 5 3d20h
kube-controller-manager-k8smaster 1/1 Running 7 3d20h
kube-proxy-6cm8k 1/1 Running 6 3d20h
kube-proxy-pm2q4 1/1 Running 5 3d20h
kube-proxy-sqwvp 1/1 Running 6 3d20h
kube-scheduler-k8smaster 1/1 Running 7 3d20h
metrics-server-7ff74c445c-8d7tw 1/1 Running 0 37s
能够使用下面的命令查看到pod的效果,说明metrics server已经安装成功
[root@k8smaster ~]# kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8smaster 195m 9% 1224Mi 71%
k8snode1 90m 4% 560Mi 32%
k8snode2 106m 5% 581Mi 33%
把.kube拷贝到node节点,node节点也可以使用命令行工具kubectl
[root@k8snode1 ~]# kubectl top node
The connection to the server localhost:8080 was refused - did you specify the right host or port?
您在 /var/spool/mail/root 中有新邮件
[root@k8smaster ~]# scp -r .kube k8snode1:/root/.kube
[root@k8snode1 ~]# kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8smaster 203m 10% 1174Mi 68%
k8snode1 81m 4% 588Mi 34%
k8snode2 86m 4% 613Mi 35%
[root@k8snode2 ~]# kubectl top node
The connection to the server localhost:8080 was refused - did you specify the right host or port?
您在 /var/spool/mail/root 中有新邮件
[root@k8smaster ~]# scp -r .kube k8snode2:/root/.kube
[root@k8snode2 ~]# kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8smaster 182m 9% 1181Mi 68%
k8snode1 88m 4% 590Mi 34%
k8snode2 85m 4% 614Mi 35%
更多推荐
所有评论(0)