轻量级Kubernetes发行版k3s之部署metrics-server

安装

从官方仓库下载项目文件:

1
2
3
4
5
6
7
$ git clone https://github.com/kubernetes-incubator/metrics-server.git
$ cd metrics-server/deploy/1.8+
$ ls
aggregated-metrics-reader.yaml auth-reader.yaml metrics-server-deployment.yaml resource-reader.yaml
auth-delegator.yaml metrics-apiservice.yaml metrics-server-service.yaml

下载镜像

需要使用的镜像为 k8s.gcr.io/metrics-server-amd64:v0.3.4

通过如下的脚本来下载:

创建文件 $ vim pull_images.sh

1
2
3
4
5
6
7
#!/bin/bash
images=(metrics-server-amd64:v0.3.4)
for imageName in ${images[@]} ; do
docker pull gcr.azk8s.cn/google_containers/$imageName
docker tag gcr.azk8s.cn/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi gcr.azk8s.cn/google_containers/$imageName
done

执行 $ bash ./pull_images.sh

查看该镜像:

1
$ docker images


修改yaml文件

修改 metrics-server-deployment.yaml 将其中 Deployment 中镜像的 imagePullPolicy: Always 改成 imagePullPolicy: IfNotPresent ,以使用本地下载的镜像。

编辑文件 $ vim metrics-server-deployment.yaml

部署

安装
1
2
3
4
5
6
7
8
9
10
11
12
$ cd ../../
$ kubectl apply -f deploy/1.8+
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
serviceaccount/metrics-server created
deployment.extensions/metrics-server created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
查看容器运行状态
1
2
3
$ kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
metrics-server-5588fd886b-bcp7x 1/1 Running 0 44s

效果查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ kubectl top nodes -n kube-system
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k3s-agent 20m 2% 202Mi 20%
k3s-master 50m 5% 543Mi 54%
$ kubectl top pods -n kube-system
NAME CPU(cores) MEMORY(bytes)
coredns-b7464766c-dbl29 3m 22Mi
metrics-server-5588fd886b-bcp7x 1m 13Mi
svclb-traefik-rmwcp 0m 1Mi
svclb-traefik-t4gbn 0m 1Mi
tiller-deploy-749f694975-f9rft 1m 9Mi
traefik-5c79b789c5-8jsvg 3m 21Mi
# 查看所有Pods
$ kubectl top pods --all-namespaces

相关参考

未完待续。。。

坚持原创技术分享,您的支持将鼓励我继续创作!
如有疑问或需要技术讨论,请留言或发邮件到 service@itfanr.cc