分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

如何通过Rancher webhook微服务实现Service/Host的弹性伸缩

发布时间:2023-09-06 01:16责任编辑:熊小新关键词:暂无标签

概述


结合大家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。


650) this.width=650;" src="https://s5.51cto.com/wyfs02/M02/A6/E4/wKioL1ndd16jVI9EAACIqVM_u9U844.png" title="图片1.png" alt="wKioL1ndd16jVI9EAACIqVM_u9U844.png" />


环境准备


Platform


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


650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/A6/E4/wKioL1ndd36w0-7xAAHmAIsmKp8867.png" title="图片2.png" alt="wKioL1ndd36w0-7xAAHmAIsmKp8867.png" />


  • 本次准备的平台是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


650) this.width=650;" src="https://s2.51cto.com/wyfs02/M00/A6/E4/wKioL1ndd5mCxmB5AAEqla1xTJw710.png" title="图片3.png" alt="wKioL1ndd5mCxmB5AAEqla1xTJw710.png" />


实践步骤


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    image: 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_image: 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‘


650) this.width=650;" src="https://s5.51cto.com/wyfs02/M02/A6/E4/wKioL1ndd7zBZgDqAADEe3AIHdY194.png" title="图片4.png" alt="wKioL1ndd7zBZgDqAADEe3AIHdY194.png" />


创建webhook


650) this.width=650;" src="https://s5.51cto.com/wyfs02/M01/08/32/wKiom1nd5tuhsio2AAEDL9OwhJQ891.png" title="图片5.png" alt="wKiom1nd5tuhsio2AAEDL9OwhJQ891.png" />


Trigger webhook


650) this.width=650;" src="https://s2.51cto.com/wyfs02/M02/A6/E4/wKioL1ndd-jBP2dCAADACu7qgpo392.png" style="float:none;" title="图片6.png" alt="wKioL1ndd-jBP2dCAADACu7qgpo392.png" />

650) this.width=650;" src="https://s5.51cto.com/wyfs02/M01/08/32/wKiom1nd5vexSQEoAAK3jFvSdSI086.png" style="float:none;" title="图片7.png" alt="wKiom1nd5vexSQEoAAK3jFvSdSI086.png" />

650) this.width=650;" src="https://s5.51cto.com/wyfs02/M01/A6/E4/wKioL1ndd-rAdChCAAC9jJVNgmQ657.png" style="float:none;" title="图片8.png" alt="wKioL1ndd-rAdChCAAC9jJVNgmQ657.png" />


Host Scale


创建example host


650) this.width=650;" src="https://s5.51cto.com/wyfs02/M02/A6/E4/wKioL1ndeAXy4efdAAKNp3wa8pE775.png" style="float:none;" title="图片9.png" alt="wKioL1ndeAXy4efdAAKNp3wa8pE775.png" />

650) this.width=650;" src="https://s1.51cto.com/wyfs02/M00/08/32/wKiom1nd5xTQpijqAADlLM3HWWU890.png" style="float:none;" title="图片10.png" alt="wKiom1nd5xTQpijqAADlLM3HWWU890.png" />


创建webhook


图11


Trigger webhook


650) this.width=650;" src="https://s1.51cto.com/wyfs02/M00/08/32/wKiom1nd5yzBuT49AAEp4fuo764247.png" style="float:none;" title="图片12.png" alt="wKiom1nd5yzBuT49AAEp4fuo764247.png" />

650) this.width=650;" src="https://s1.51cto.com/wyfs02/M00/A6/E4/wKioL1ndeB_BjvXCAAK2-EUgNiY833.png" style="float:none;" title="图片13.png" alt="wKioL1ndeB_BjvXCAAK2-EUgNiY833.png" />

650) this.width=650;" src="https://s1.51cto.com/wyfs02/M01/08/32/wKiom1nd5y6xoG7RAAFNhgc_hjM727.png" style="float:none;" title="图片14.png" alt="wKiom1nd5y6xoG7RAAFNhgc_hjM727.png" />


原文来源:Rancher Labs

本文出自 “12452495” 博客,请务必保留此出处http://12462495.blog.51cto.com/12452495/1971363

如何通过Rancher webhook微服务实现Service/Host的弹性伸缩

原文地址:http://12462495.blog.51cto.com/12452495/1971363

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved