二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • 最佳实践

  • 迎刃而解

  • Nginx

  • Php

  • Zabbix

  • AWS

  • Prometheus

  • Grafana

  • Loki

  • CentOS

  • Supervisord

  • Systemd

  • Docker

  • Docker-Compose

  • Rancher

    • rancher-2-1-6的ha版本部署记录
    • rancher-2-1-6的ha版本部署记录
    • 关于rancher集群的高可用的实验
    • 关于rancher中部署应用的高可用的实验
    • 关于rancher-ha集群备份恢复试验
    • rancher-v2-2-2的HA部署文档
    • Rancher-2-2-2学习笔记-rancher-cli的使用
    • 基于Rancher-2-2-2的hpa实验
      • 1,部署。
      • 2,暴露服务。
      • 3,验证效果。
    • Rancher-2-2-2之Jenkins+rancher+harbor+Gitlab部署应用到生产
    • 使用docker快速部署rancher-2.8.5并投入生产实践
    • rancher如何重新注册托管集群
  • Ansible

  • OpenLdap

  • GitLab

  • GitHub

  • Etcd

  • Consul

  • RabbitMQ

  • Kafka

  • Mysql

  • MongoDB

  • OpenVPN

  • Kvm

  • VMware

  • 配置文件详解

  • Other

  • 运维观止
  • Rancher
二丫讲梵
2019-04-25
目录

基于Rancher-2-2-2的hpa实验

文章发布较早,内容可能过时,阅读注意甄别。

根据官方人员的说明,在目前最新的 2.2.2 版本中,还没有在 UI 界面当中支持 hpa 的功能(可能在下个版本中支持),所以做实验需要通过命令行来手动操作一下。

要知道,想要在 k8s 当中完成 hpa 的实验,需要metrics的支持,不过 rancher 部署完成之后,就已经集成了。

$ kubectl get pod -n kube-system |grep metrics
metrics-server-58bd5dd8d7-pr6nh             1/1     Running     0          6h50m
1
2

于是可以直接部署进行实验。

# 1,部署。

首先部署一个可供试验的服务。

kubectl run nginxtest --image=nginx:latest --requests=cpu=200m --expose --port=80
1

然后对如上服务添加 hpa 规则。

kubectl autoscale deployment nginxtest --cpu-percent=10 --min=1 --max=10
1
  • --cpu-percent:表示使用率达到上边设定的(200m)的百分之十。
  • --min:表示一分钟之内。
  • --max:表示最多增加到 10 个副本。

如上两条命令可以直接在 web 界面,找到集群,选择执行kubectl命令:

image

部署完成之后,可以看一看应用部署的情况。

image

# 2,暴露服务。

因为上边是手动创建的一个 deployment,外部无法访问,所以现在手动在集群的服务发现当中添加一下映射。

image

保存之后,就可以直接通过随机分配的端口进行访问了。

$ curl 192.168.111.3:30392
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 3,验证效果。

在服务器上执行如下命令创造一些访问:

while true; do curl -s http://192.168.111.3:30392; done
1

这个时候可以到 web 界面看看使用占比情况:

image

那么不用动,等待一会儿,k8s 就会自动给应用增加副本,从而让负载使用占比降下来,而后我在增加两台机器进行访问增压,那么负载再次增高,应该就会再一次增加副本,从而让负载保持在一个之前预期的一个范围当中。

过了一会儿看看果然如此:

image

可以清晰看到整个负载的动向,也可以看到副本从 1 个增加到了 2 个,再到 4 个,再到 7 个。

然后再去看看应用是否启动了多个副本以应对这种突然增高的负载:

image

可以看到,副本已经增加到了 7 个,那么这个功能的试验,到这里也就结束了,真的是非常犀利,非常方便,与此同时,也非常期待 rancher 的下一个版本能够快点到来,争取早点完美支持这种自动的动态调整副本功能。

微信 支付宝
#k8s#rancher
上次更新: 2024/07/04, 22:40:37
Rancher-2-2-2学习笔记-rancher-cli的使用
Rancher-2-2-2之Jenkins+rancher+harbor+Gitlab部署应用到生产

← Rancher-2-2-2学习笔记-rancher-cli的使用 Rancher-2-2-2之Jenkins+rancher+harbor+Gitlab部署应用到生产→

最近更新
01
学习周刊-总第213期-2025年第22周
05-29
02
学习周刊-总第212期-2025年第21周
05-22
03
从赵心童世锦赛夺冠聊聊我的斯诺克情缘
05-16
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式