在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 Ready3m49s v1.17.2 192.168.163.131CentOS 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.213443/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
- 各组件版本