温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何安装kubectl top 插件

发布时间:2020-06-10 13:01:26 来源:亿速云 阅读:577 作者:元一 栏目:系统运维

简介

kubectl是一个工具,类似于etcdctl一样,不是必须安装的工具。各节点和管理节点的通讯都是通过api-server进行的。api-server可以部署在任意的节点上,kube-proxy也是一样的,都是独立的组件。

kubectl top 可以很方便地查看node、pod的实时资源使用情况:如CPU、内存。

实现原理

kubectl top 、 k8s dashboard 以及 HPA 等调度组件使用的数据是一样,数据链路如下:

如何安装kubectl top 插件
使用 heapster 时:apiserver 会直接将metric请求通过 proxy 的方式转发给集群内的 hepaster 服务。
如何安装kubectl top 插件
而使用 metrics-server 时:apiserver是通过/apis/metrics.k8s.io/的地址访问metric
如何安装kubectl top 插件

这里可以对比下kubect get pod时的日志:

如何安装kubectl top 插件

1.下载yaml 文件

wget http://pencil-file.oss-cn-hangzhou.aliyuncs.com/blog/auth-delegator.yaml
wget http://pencil-file.oss-cn-hangzhou.aliyuncs.com/blog/metrics-server-service.yaml
wget http://pencil-file.oss-cn-hangzhou.aliyuncs.com/blog/auth-reader.yaml
wget http://pencil-file.oss-cn-hangzhou.aliyuncs.com/blog/metrics-apiservice.yaml
wget http://pencil-file.oss-cn-hangzhou.aliyuncs.com/blog/metrics-server-deployment.yaml
wget http://pencil-file.oss-cn-hangzhou.aliyuncs.com/blog/aggregated-metrics-reader.yaml
wget http://pencil-file.oss-cn-hangzhou.aliyuncs.com/blog/resource-reader.yaml

2. 修改metrics-server-deployment.yaml文件

核心配置:

 containers:
      - name: metrics-server
        image: k8s.gcr.io/metrics-server-amd64:v0.3.2
        imagePullPolicy: IfNotPresent
        #修改为本地有镜像优先使用
        command:
        - /metrics-server
        - --metric-resolution=30s
        - --kubelet-insecure-tls
        - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
        #容器的预设值 脚本
        volumeMounts:
        - name: tmp-dir
          mountPath: /tmp

3.拉取镜像

docker pull k8s.gcr.io/metrics-server-amd64
由于该镜像在国外所以可能使用其他途径 代理上网或者本地导入
代理上网法

mkdir -p /etc/systemd/system/docker.service.d
#创建放代理的文件夹,默认没有
echo '[Service]
Environment="HTTP_PROXY=192.168.0.26:8118" "HTTPS_PROXY=192.168.0.26:8118"' >/etc/systemd/system/docker.service.d/http-proxy.conf
#创建代理的配置件,前提得有能访问到国外镜像服务器的代理服务器
systemctl daemon-reload
systemctl restart docker
#重启docker

以上脚本运行一下 就能pull 到国外镜像了

本地导出导入法
先到拉取完毕的主机上导出
docker save -o metrics-server-amd64:v0.3.2.tar k8s.gcr.io/metrics-server-amd64:v0.3.2
#.tar 为完成的打包文件,后面的是需要导出的镜像名需要带版本名,镜像名用docker images 查看
导入
docker load <metrics-server-amd64\:v0.3.2.tar

4.应用
kubectl apply -f ./
#应用下载的所有yaml文件
kubectl get pod -n kube-system
#查看一下pod 是否正常
如何安装kubectl top 插件

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI