Version: v1.2

内置工作流步骤

本文档将详细介绍 KubeVela 内置的各个工作流步骤。你可以通过自由的组合它们来设计完整的交付工作流。

apply-application

简介

部署当前 Application 中的所有组件和运维特征。

参数

无需指定参数,主要用于应用部署前后增加自定义步骤。

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: first-vela-workflow
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. traits:
  14. - type: ingress
  15. properties:
  16. domain: testsvc.example.com
  17. http:
  18. /: 8000
  19. workflow:
  20. steps:
  21. - name: express-server
  22. type: apply-application

depends-on-app

简介

等待指定的 Application 完成。

depends-on-app 会根据 properties 中的 namenamespace,去查询集群中是否存在对应的应用。

如果应用存在,则当该应用的状态可用时,才会进行下一个步骤; 若该应用不存在,则会去查询同名的 configMap,从中读取出应用的配置并部署到集群中。

若应用不存在,则需要形如下的 configMap:namenamespaceproperties 中声明的保持一致,在 data 中,以 name 为 key,实际的 value 为需要部署的 KubeVela Application yaml。

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: myapp
  5. namespace: vela-system
  6. data:
  7. myapp: ...

参数

参数名类型说明
namestring需要等待的 Application 名称
namespacestring需要等待的 Application 所在的命名空间

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: first-vela-workflow
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. traits:
  14. - type: ingress
  15. properties:
  16. domain: testsvc.example.com
  17. http:
  18. /: 8000
  19. workflow:
  20. steps:
  21. - name: express-server
  22. type: depends-on-app
  23. properties:
  24. name: another-app
  25. namespace: default

deploy2env

简介

将 Application 在不同的环境和策略中部署。

参数

参数名类型说明
policystring需要关联的策略名
envstring需要关联的环境名

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: multi-env-demo
  5. namespace: default
  6. spec:
  7. components:
  8. - name: nginx-server
  9. type: webservice
  10. properties:
  11. image: nginx:1.21
  12. port: 80
  13. policies:
  14. - name: env
  15. type: env-binding
  16. properties:
  17. created: false
  18. envs:
  19. - name: test
  20. patch:
  21. components:
  22. - name: nginx-server
  23. type: webservice
  24. properties:
  25. image: nginx:1.20
  26. port: 80
  27. placement:
  28. namespaceSelector:
  29. name: test
  30. - name: prod
  31. patch:
  32. components:
  33. - name: nginx-server
  34. type: webservice
  35. properties:
  36. image: nginx:1.20
  37. port: 80
  38. placement:
  39. namespaceSelector:
  40. name: prod
  41. workflow:
  42. steps:
  43. - name: deploy-test-server
  44. type: deploy2env
  45. properties:
  46. policy: env
  47. env: test
  48. - name: deploy-prod-server
  49. type: deploy2env
  50. properties:
  51. policy: env
  52. env: prod

notification

简介

向指定的 Webhook 发送信息,支持邮件、钉钉、Slack 和飞书。

参数

参数名类型说明
emailObject可选值,如果需要发送邮件,则需填写其 from、to 以及 content
email.from.addressString必填值,发送的邮件地址
email.from.aliasString可选值,发送的邮件别名
email.from.passwordValueOrSecret必填值,发送的邮件密码,可以选择直接在 value 填写或从 secretRef 中获取
email.from.hostString必填值,邮件的 Host
email.from.portInt可选值,邮件发送的端口号,默认为 587
email.to[]String必填值,邮件发送的地址列表
email.content.subjectString必填值,邮件的标题
email.content.bodyString必填值,邮件的内容
slackObject可选值,如果需要发送 Slack 信息,则需填写其 url 及 message
slack.urlValueOrSecret必填值,Slack 的 Webhook 地址,可以选择直接在 value 填写或从 secretRef 中获取
slack.messageObject必填值,需要发送的 Slack 信息,请符合 Slack 信息规范
dingdingObject可选值,如果需要发送钉钉信息,则需填写其 url 及 message
dingding.urlValueOrSecret必填值,钉钉的 Webhook 地址,可以选择直接在 value 填写或从 secretRef 中获取
dingding.messageObject必填值,需要发送的钉钉信息,请符合 钉钉信息规范
larkObject可选值,如果需要发送飞书信息,则需填写其 url 及 message
lark.urlValueOrSecret必填值,飞书的 Webhook 地址,可以选择直接在 value 填写或从 secretRef 中获取
lark.messageObject必填值,需要发送的飞书信息,请符合 飞书信息规范

ValueOrSecret 的格式为:

参数名类型说明
valueString可选值,直接填写值
secretRef.nameString可选值,从 secret 中获取值,secret 的名称
secretRef.keyString可选值,从 secret 中获取值,secret 的 key

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: first-vela-workflow
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. traits:
  14. - type: ingress
  15. properties:
  16. domain: testsvc.example.com
  17. http:
  18. /: 8000
  19. workflow:
  20. steps:
  21. - name: dingtalk-message
  22. type: notification
  23. properties:
  24. dingding:
  25. # 钉钉 Webhook 地址,请查看:https://developers.dingtalk.com/document/robots/custom-robot-access
  26. url:
  27. value: <your dingtalk url>
  28. message:
  29. msgtype: text
  30. text:
  31. context: 开始运行工作流
  32. - name: application
  33. type: apply-application
  34. - name: slack-message
  35. type: notification
  36. properties:
  37. slack:
  38. # Slack Webhook 地址,请查看:https://api.slack.com/messaging/webhooks
  39. url:
  40. secretRef:
  41. name: <the secret name that stores your slack url>
  42. key: <the secret key that stores your slack url>
  43. message:
  44. text: 工作流运行完成

apply-object

简介

部署 Kubernetes 原生资源,该功能在 KubeVela v1.1.4 及以上版本可使用。

参数

参数名类型说明
valueobject必填值,Kubernetes 原生资源字段
clusterobject可选值,需要部署的集群名称。如果不指定,则为当前集群。在使用该字段前,请确保你已经使用 vela cluster join 纳管了你的集群

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: server-with-pvc
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. volumes:
  14. - name: "my-pvc"
  15. type: "pvc"
  16. mountPath: "/test"
  17. claimName: "myclaim"
  18. workflow:
  19. steps:
  20. - name: apply-pvc
  21. type: apply-object
  22. properties:
  23. # Kubernetes 原生字段
  24. value:
  25. apiVersion: v1
  26. kind: PersistentVolumeClaim
  27. metadata:
  28. name: myclaim
  29. namespace: default
  30. spec:
  31. accessModes:
  32. - ReadWriteOnce
  33. resources:
  34. requests:
  35. storage: 8Gi
  36. storageClassName: standard
  37. # 需要部署的集群名称,如果不指定,则默认为当前集群
  38. cluster: <your cluster name>
  39. - name: apply-server
  40. type: apply-component
  41. properties:
  42. component: express-server

read-object

简介

读取 Kubernetes 原生资源,该功能在 KubeVela v1.1.6 及以上版本可使用。

参数

参数名类型说明
apiVersionString必填值,资源的 apiVersion
kindString必填值,资源的 kind
nameString必填值,资源的 name
namespaceString选填值,资源的 namespace,默认为 default
clusterString选填值,资源的集群名,默认为当前集群,在使用该字段前,请确保你已经使用 vela cluster join 纳管了你的集群

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: read-object
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. workflow:
  14. steps:
  15. - name: read-object
  16. type: read-object
  17. outputs:
  18. - name: cpu
  19. valueFrom: output.value.data["cpu"]
  20. - name: memory
  21. valueFrom: output.value.data["memory"]
  22. properties:
  23. apiVersion: v1
  24. kind: ConfigMap
  25. name: my-cm-name
  26. cluster: <your cluster name>
  27. - name: apply
  28. type: apply-component
  29. inputs:
  30. - from: cpu
  31. parameterKey: cpu
  32. - from: memory
  33. parameterKey: memory
  34. properties:
  35. component: express-server

export2config

简介

导出数据到 ConfigMap,该功能在 KubeVela v1.1.6 及以上版本可使用。

参数

参数名类型说明
configNameString必填值,ConfigMap 的名称
namespaceString选填值,ConfigMap 的 namespace,默认为 context.namespace
dataMap必填值,需要导出到 ConfigMap 中的数据

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: export-config
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. workflow:
  14. steps:
  15. - name: apply-server
  16. type: apply-component
  17. outputs:
  18. - name: status
  19. valueFrom: output.status.conditions[0].message
  20. properties:
  21. component: express-server
  22. - name: export-config
  23. type: export-config
  24. inputs:
  25. - from: status
  26. parameterKey: data.serverstatus
  27. properties:
  28. configName: my-configmap
  29. data:
  30. testkey: testvalue

export2secret

简介

导出数据到 Secret,该功能在 KubeVela v1.1.6 及以上版本可使用。

参数

参数名类型说明
secretNameString必填值,Secret 的名称
namespaceString选填值,Secret 的 namespace,默认为 context.namespace
dataMap必填值,需要导出到 Secret 中的数据

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: export-secret
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. workflow:
  14. steps:
  15. - name: apply-server
  16. type: apply-component
  17. outputs:
  18. - name: status
  19. valueFrom: output.status.conditions[0].message
  20. properties:
  21. component: express-server
  22. - name: export-secret
  23. type: export-secret
  24. inputs:
  25. - from: status
  26. parameterKey: data.serverstatus
  27. properties:
  28. secretName: my-secret
  29. data:
  30. testkey: testvalue

suspend

简介

暂停当前工作流,可以通过 vela workflow resume appname 继续已暂停的工作流。

有关于 vela workflow 命令的介绍,可以详见 vela cli

参数

参数名类型说明
---

示例

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: first-vela-workflow
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. traits:
  14. - type: ingress
  15. properties:
  16. domain: testsvc.example.com
  17. http:
  18. /: 8000
  19. workflow:
  20. steps:
  21. - name: slack-message
  22. type: webhook-notification
  23. properties:
  24. slack:
  25. # Slack Webhook 地址,请查看:https://api.slack.com/messaging/webhooks
  26. url: xxx
  27. message:
  28. text: 准备开始部署应用,请管理员审批并继续工作流
  29. - name: manual-approval
  30. type: suspend
  31. - name: express-server
  32. type: apply-application