Easypack: Ansible方式部署工具中增加Metrics Server支持

在这里插入图片描述
在Easypack中提供了多套Kubernetes快速部署的工具,基于Bash脚本和Ansible的,Ansible的方式也有基于K3S和普通的Kubernetes的两种。这篇文章介绍一下普通Kubernetes版本下的Ansible部署工具中如何增加Metrics Server的支持。

事前准备

本文使用Kubernetes 1.17.2,可参看下文进行快速环境搭建:

[root@host131 ansible]# kubectl get node -o wide
NAME              STATUS   ROLES    AGE     VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME
192.168.163.131   Ready    <none>   3m49s   v1.17.2   192.168.163.131   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://19.3.5
[root@host131 ansible]# 
  • 事前环境确认: service、pod与deployment
[root@host131 ansible]# kubectl get service -A |grep metrics
[root@host131 ansible]# kubectl get pod -A |grep metrics
[root@host131 ansible]# kubectl get deployment -A |grep metrics
[root@host131 ansible]#
  • 事前环境确认: kubectl top命令
[root@host131 ansible]# kubectl top pod
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
[root@host131 ansible]# kubectl top node
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
[root@host131 ansible]# 

Metrics Server安装

安装Metrics Server

执行如下命令即可完成Metrics Server的安装

[root@host131 ansible]# ansible-playbook metrics/tests/test.yml 

PLAY [localhost] *********************************************************************************************************************************

TASK [metrics : create dirs for metrics] *********************************************************************************************************
changed: [localhost] => (item=/etc/k8s/metrics)

TASK [metrics : copy metrics yaml file] **********************************************************************************************************
changed: [localhost] => (item=aggregated-metrics-reader.yaml)
changed: [localhost] => (item=auth-delegator.yaml)
changed: [localhost] => (item=auth-reader.yaml)
changed: [localhost] => (item=metrics-apiservice.yaml)
changed: [localhost] => (item=metrics-server-service.yaml)
changed: [localhost] => (item=resource-reader.yaml)

TASK [metrics : create metrics server deployment yaml file] **************************************************************************************
changed: [localhost]

TASK [metrics : load metrics server image] *******************************************************************************************************
changed: [localhost]

TASK [metrics : create metrics service] **********************************************************************************************************
changed: [localhost]

TASK [metrics : confirm metrics service state] ***************************************************************************************************
changed: [localhost]

PLAY RECAP ***************************************************************************************************************************************
localhost                  : ok=6    changed=6    unreachable=0    failed=0   

[root@host131 ansible]# 

结果确认

使用kubectl命令可以确认到,pod、deployment以及service全部生成并正常运行

[root@host131 ansible]# kubectl get service -A |grep metrics
kube-system   metrics-server   ClusterIP   10.254.47.213   <none>        443/TCP         2m36s
[root@host131 ansible]# kubectl get pod -A |grep metrics
kube-system   metrics-server-5cc8d5c4df-qcpg6   1/1     Running   0          2m43s
[root@host131 ansible]# kubectl get deployment -A |grep metrics
kube-system   metrics-server   1/1     1            1           2m56s
[root@host131 ansible]# 
  • 确认kubectl top命令
[root@host131 ansible]# kubectl top node
NAME              CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
192.168.163.131   100m         10%    2588Mi          67%       
[root@host131 ansible]# 
[root@host131 ansible]# kubectl top pod metrics-server-5cc8d5c4df-qcpg6  -n kube-system
NAME                              CPU(cores)   MEMORY(bytes)   
metrics-server-5cc8d5c4df-qcpg6   1m           11Mi            
[root@host131 ansible]# 

Ansible脚本

github地址:https://github.com/liumiaocn/easypack/tree/master/k8s/ansible

  • 各组件版本
组件 版本 更新时间 获取地址
cfssl 1.2 2016/3/30 https://pkg.cfssl.org/
flannel 0.11.0 2019/1/29 https://github.com/coreos/flannel
pause 3.1 - gcr.io/google_containers/pause-amd64:3.1
kubernetes 1.17.2 2020/1/21 https://dl.k8s.io
etcd 3.3.18 2019/11/27 https://github.com/etcd-io/etcd/releases
docker 19.03.5 2019/11/14 https://download.docker.com/
cni 0.8.5 2020/1/22 https://github.com/containernetworking/plugins/releases
coredns 1.6.7 2020/1/28 coredns/coredns:1.6.7
dashboard 1.10.1 - k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
prometheus 2.15.1 2019/12/25 prom/prometheus:v2.15.1
metrics server 0.3.6 2019/10/15 k8s.gcr.io/metrics-server-amd64 :v0.3.6
发布了1058 篇原创文章 · 获赞 1292 · 访问量 399万+

猜你喜欢

转载自blog.csdn.net/liumiaocn/article/details/104142067
今日推荐