Deis workflow

[danger] Deis Workflow不再维护

Deis Workflow v2.18将是最后一个发行版本,后续不再维护和更新。 推荐使用 Helm 来管理Kubernetes应用。

Deis workflow是基于Kubernetes的PaaS管理平台,进一步简化了应用的打包、部署和服务发现。

Deis workflow - 图1

Deis架构

Deis workflow - 图2

Deis workflow - 图3

Deis workflow - 图4

Deis安装部署

首先需要部署一套kubernetes(比如minikube,GKE等,记得启用KUBE_ENABLE_CLUSTER_DNS=true),并配置好本机的kubectl客户端,然后运行以下脚本安装deis:

  1. # install deis v2 (workflow)
  2. curl -sSL http://deis.io/deis-cli/install-v2.sh | bash
  3. mv deis /usr/local/bin/
  4. # install helm
  5. wget https://storage.googleapis.com/kubernetes-helm/helm-v2.2.1-linux-amd64.tar.gz
  6. tar zxvf helm-v2.2.1-linux-amd64.tar.gz
  7. mv linux-amd64/helm /usr/local/bin/
  8. rm -rf linux-amd64 helm-v2.2.1-linux-amd64.tar.gz
  9. helm init
  10. # deploy helm components
  11. helm repo add deis https://charts.deis.com/workflow
  12. helm install deis/workflow --namespace deis
  13. kubectl --namespace=deis get pods

Deis基本使用

注册用户并登录

  1. deis register deis-controller.deis.svc.cluster.local
  2. deis login deis-controller.deis.svc.cluster.local
  3. deis perms:create newuser --admin

部署应用

注意,deis的大部分操作命令都需要在应用的目录中(即下面的example-dockerfile-http)。

  1. git clone https://github.com/deis/example-dockerfile-http.git
  2. cd example-dockerfile-http
  3. docker build -t deis/example-dockerfile-http .
  4. docker push deis/example-dockerfile-http
  5. # create app
  6. deis create example-dockerfile-http --no-remote
  7. # deploy app
  8. deis pull deis/example-dockerfile-http:latest
  9. # query application status
  10. deis info

扩展应用

  1. $ deis scale cmd=3
  2. $ deis ps
  3. === example-dockerfile-http Processes
  4. --- cmd:
  5. example-dockerfile-http-cmd-4246296512-08124 up (v2)
  6. example-dockerfile-http-cmd-4246296512-40lfv up (v2)
  7. example-dockerfile-http-cmd-4246296512-fx3w3 up (v2)

也可以配置自动扩展

  1. deis autoscale:set example-dockerfile-http --min=3 --max=8 --cpu-percent=75

这样,就可以通过Kubernetes的DNS来访问应用了(配置了外网负载均衡后,还可以通过负载均衡来访问服务):

  1. $ curl example-dockerfile-http.example-dockerfile-http.svc.cluster.local
  2. Powered by Deis

域名和路由

  1. # 注意设置CNMAE记录到原来的地址
  2. deis domains:add hello.bacongobbler.com
  3. dig hello.deisapp.com
  4. deis routing:enable

这实际上是在deis-router的nginx配置中增加了 virtual hosts :

  1. server {
  2. listen 8080;
  3. server_name ~^example-dockerfile-http\.(?<domain>.+)$;
  4. server_name_in_redirect off;
  5. port_in_redirect off;
  6. set $app_name "example-dockerfile-http";
  7. vhost_traffic_status_filter_by_set_key example-dockerfile-http application::*;
  8. location / {
  9. proxy_buffering off;
  10. proxy_set_header Host $host;
  11. proxy_set_header X-Forwarded-For $remote_addr;
  12. proxy_set_header X-Forwarded-Proto $access_scheme;
  13. proxy_set_header X-Forwarded-Port $forwarded_port;
  14. proxy_redirect off;
  15. proxy_connect_timeout 30s;
  16. proxy_send_timeout 1300s;
  17. proxy_read_timeout 1300s;
  18. proxy_http_version 1.1;
  19. proxy_set_header Upgrade $http_upgrade;
  20. proxy_set_header Connection $connection_upgrade;
  21. proxy_pass http://10.0.0.224:80;
  22. }
  23. }
  24. server {
  25. listen 8080;
  26. server_name hello.bacongobbler.com;
  27. server_name_in_redirect off;
  28. port_in_redirect off;
  29. set $app_name "example-dockerfile-http";
  30. vhost_traffic_status_filter_by_set_key example-dockerfile-http application::*;
  31. location / {
  32. proxy_buffering off;
  33. proxy_set_header Host $host;
  34. proxy_set_header X-Forwarded-For $remote_addr;
  35. proxy_set_header X-Forwarded-Proto $access_scheme;
  36. proxy_set_header X-Forwarded-Port $forwarded_port;
  37. proxy_redirect off;
  38. proxy_connect_timeout 30s;
  39. proxy_send_timeout 1300s;
  40. proxy_read_timeout 1300s;
  41. proxy_http_version 1.1;
  42. proxy_set_header Upgrade $http_upgrade;
  43. proxy_set_header Connection $connection_upgrade;
  44. proxy_pass http://10.0.0.224:80;
  45. }
  46. }

参考文档