如何經過Rancher webhook微服務實現Service/Host的彈性伸縮

概述

結合你們CICD的應用場景,本篇Blog旨在介紹如何經過Rancher的webhook微服務來實現Service/Host的彈性伸縮。linux

流程介紹

  • Service Scalenginx

    • 建立example服務對象。
    • 建立service scale webhook對象。
    • 第三方觸發webhook,完成service彈性伸縮。
  • Host Sacleweb

    • 經過阿里雲machine driver建立實例對象,打上scale-up標籤。
    • 建立host scale webhook對象。
    • 第三方觸發webhook,完成host彈性伸縮。

webhook介紹

Rancher webhook的服務流程大體以下:docker

  • Webhook Driver(WD)初始化。
  • Router Handler(RH)初始化。
  • 接收請求URL和Method,匹配調用RH.Execute或其餘方法,RH.Execute解析請求數據獲得WD_Id,進而執行WD.Execute,最後返回並response。

圖片描述

環境準備

Platform

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

圖片描述

  • 本次準備的平臺是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。json

Rancher

圖片描述

實踐步驟

Service Scale

建立example serviceapp

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'

圖片描述

建立webhookcurl

圖片描述

Trigger webhookwebapp

圖片描述
圖片描述
圖片描述

Host Scale

建立example hosttcp

圖片描述
圖片描述

建立webhook微服務

圖片描述

Trigger webhook

圖片描述
圖片描述
圖片描述

相關文章
相關標籤/搜索