概述


结合大家CICD的应用场景,本篇Blog旨在介绍如何通过Rancher的webhook微服务来实现Service/Host的弹性伸缩。


流程介绍


  • Service Scale

    • 创建example服务对象。

    • 创建service scale webhook对象。

    • 第三方触发webhook,完成service弹性伸缩。

  • Host Sacle

    • 通过阿里云machine driver创建实例对象,打上scale-up标签。

    • 创建host scale webhook对象。

    • 第三方触发webhook,完成host弹性伸缩。


webhook介绍


Rancher webhook的服务流程大致如下:


  1. Webhook Driver(WD)初始化。

  2. Router Handler(RH)初始化。

  3. 接收请求URL和Method,匹配调用RH.Execute或其他方法,RH.Execute解析请求数据得到WD_Id,进而执行WD.Execute,最后返回并response。


如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第1张图片


环境准备


Platform


  • Mac,Windows,Linux,Docker Cloud,AWS,Azure均可部署。


如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第2张图片


  • 本次准备的平台是Ubuntu发行版(14.04),为了兼容docker,选择linux发行版的时候内核需控制在3.10以上。


Docker


  • 根据用户选择的平台安装docker引擎,安装指导可参考https://docs.docker.com官方文档,搭配Rancher使用,docker引擎版本最优选择1.12.6或者1.13.1。

  • 本次准备的docker引擎版本是1.12.6。


Rancher


如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第3张图片


实践步骤


Service Scale


创建example service

curl -u "xx:xx" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"description": "example service for scaling",
"name": "webapp",
"system": false,
"dockerCompose": "version: '2'\nservices:\n  NGX:\n    p_w_picpath: nginx:alpine\n    stdin_open: true\n    tty: true\n    cpuset: \"0\"\n    ports:\n    - 8787:80/tcp\n    cpu_shares: 1024\n    labels:\n      io.rancher.container.pull_p_w_picpath: always\n      servicename: nginx",
"rancherCompose": "version: '2'\nservices:\n  NGX:\n    scale: 1\n    start_on_create: true",
"binding": null,
"startOnCreate": true
}' 'http://a.b.c.d:8080/v2-beta/projects/1a5/stacks'


wKioL1ndd7zBZgDqAADEe3AIHdY194.png


创建webhook


如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第4张图片


Trigger webhook


wKioL1ndd-jBP2dCAADACu7qgpo392.png

如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第5张图片

如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第6张图片


Host Scale


创建example host


如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第7张图片

如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第8张图片


创建webhook


图11


Trigger webhook


如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第9张图片

如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第10张图片

如何通过Rancher webhook微服务实现Service/Host的弹性伸缩_第11张图片


原文来源:Rancher Labs