溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何安裝kubectl top 插件

發(fā)布時(shí)間:2020-06-10 13:01:26 來源:億速云 閱讀:583 作者:元一 欄目:系統(tǒng)運(yùn)維

簡(jiǎn)介

kubectl是一個(gè)工具,類似于etcdctl一樣,不是必須安裝的工具。各節(jié)點(diǎn)和管理節(jié)點(diǎn)的通訊都是通過api-server進(jìn)行的。api-server可以部署在任意的節(jié)點(diǎn)上,kube-proxy也是一樣的,都是獨(dú)立的組件。

kubectl top 可以很方便地查看node、pod的實(shí)時(shí)資源使用情況:如CPU、內(nèi)存。

實(shí)現(xiàn)原理

kubectl top 、 k8s dashboard 以及 HPA 等調(diào)度組件使用的數(shù)據(jù)是一樣,數(shù)據(jù)鏈路如下:

如何安裝kubectl top 插件
使用 heapster 時(shí):apiserver 會(huì)直接將metric請(qǐng)求通過 proxy 的方式轉(zhuǎn)發(fā)給集群內(nèi)的 hepaster 服務(wù)。
如何安裝kubectl top 插件
而使用 metrics-server 時(shí):apiserver是通過/apis/metrics.k8s.io/的地址訪問metric
如何安裝kubectl top 插件

這里可以對(duì)比下kubect get pod時(shí)的日志:

如何安裝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
        #修改為本地有鏡像優(yōu)先使用
        command:
        - /metrics-server
        - --metric-resolution=30s
        - --kubelet-insecure-tls
        - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
        #容器的預(yù)設(shè)值 腳本
        volumeMounts:
        - name: tmp-dir
          mountPath: /tmp

3.拉取鏡像

docker pull k8s.gcr.io/metrics-server-amd64
由于該鏡像在國(guó)外所以可能使用其他途徑 代理上網(wǎng)或者本地導(dǎo)入
代理上網(wǎng)法

mkdir -p /etc/systemd/system/docker.service.d
#創(chuàng)建放代理的文件夾,默認(rèn)沒有
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
#創(chuàng)建代理的配置件,前提得有能訪問到國(guó)外鏡像服務(wù)器的代理服務(wù)器
systemctl daemon-reload
systemctl restart docker
#重啟docker

以上腳本運(yùn)行一下 就能pull 到國(guó)外鏡像了

本地導(dǎo)出導(dǎo)入法
先到拉取完畢的主機(jī)上導(dǎo)出
docker save -o metrics-server-amd64:v0.3.2.tar k8s.gcr.io/metrics-server-amd64:v0.3.2
#.tar 為完成的打包文件,后面的是需要導(dǎo)出的鏡像名需要帶版本名,鏡像名用docker images 查看
導(dǎo)入
docker load <metrics-server-amd64\:v0.3.2.tar

4.應(yīng)用
kubectl apply -f ./
#應(yīng)用下載的所有yaml文件
kubectl get pod -n kube-system
#查看一下pod 是否正常
如何安裝kubectl top 插件

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI