Version: v1.2
内置工作流步骤
本文档将详细介绍 KubeVela 内置的各个工作流步骤。你可以通过自由的组合它们来设计完整的交付工作流。
apply-application
简介
部署当前 Application 中的所有组件和运维特征。
参数
无需指定参数,主要用于应用部署前后增加自定义步骤。
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: first-vela-workflownamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000traits:- type: ingressproperties:domain: testsvc.example.comhttp:/: 8000workflow:steps:- name: express-servertype: apply-application
depends-on-app
简介
等待指定的 Application 完成。
depends-on-app 会根据 properties 中的 name 及 namespace,去查询集群中是否存在对应的应用。
如果应用存在,则当该应用的状态可用时,才会进行下一个步骤; 若该应用不存在,则会去查询同名的 configMap,从中读取出应用的配置并部署到集群中。
若应用不存在,则需要形如下的 configMap:
name与namespace和properties中声明的保持一致,在data中,以name为 key,实际的 value 为需要部署的 KubeVela Application yaml。
apiVersion: v1kind: ConfigMapmetadata:name: myappnamespace: vela-systemdata:myapp: ...
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| name | string | 需要等待的 Application 名称 |
| namespace | string | 需要等待的 Application 所在的命名空间 |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: first-vela-workflownamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000traits:- type: ingressproperties:domain: testsvc.example.comhttp:/: 8000workflow:steps:- name: express-servertype: depends-on-appproperties:name: another-appnamespace: default
deploy2env
简介
将 Application 在不同的环境和策略中部署。
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| policy | string | 需要关联的策略名 |
| env | string | 需要关联的环境名 |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: multi-env-demonamespace: defaultspec:components:- name: nginx-servertype: webserviceproperties:image: nginx:1.21port: 80policies:- name: envtype: env-bindingproperties:created: falseenvs:- name: testpatch:components:- name: nginx-servertype: webserviceproperties:image: nginx:1.20port: 80placement:namespaceSelector:name: test- name: prodpatch:components:- name: nginx-servertype: webserviceproperties:image: nginx:1.20port: 80placement:namespaceSelector:name: prodworkflow:steps:- name: deploy-test-servertype: deploy2envproperties:policy: envenv: test- name: deploy-prod-servertype: deploy2envproperties:policy: envenv: prod
notification
简介
向指定的 Webhook 发送信息,支持邮件、钉钉、Slack 和飞书。
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| Object | 可选值,如果需要发送邮件,则需填写其 from、to 以及 content | |
| email.from.address | String | 必填值,发送的邮件地址 |
| email.from.alias | String | 可选值,发送的邮件别名 |
| email.from.password | ValueOrSecret | 必填值,发送的邮件密码,可以选择直接在 value 填写或从 secretRef 中获取 |
| email.from.host | String | 必填值,邮件的 Host |
| email.from.port | Int | 可选值,邮件发送的端口号,默认为 587 |
| email.to | []String | 必填值,邮件发送的地址列表 |
| email.content.subject | String | 必填值,邮件的标题 |
| email.content.body | String | 必填值,邮件的内容 |
| slack | Object | 可选值,如果需要发送 Slack 信息,则需填写其 url 及 message |
| slack.url | ValueOrSecret | 必填值,Slack 的 Webhook 地址,可以选择直接在 value 填写或从 secretRef 中获取 |
| slack.message | Object | 必填值,需要发送的 Slack 信息,请符合 Slack 信息规范 |
| dingding | Object | 可选值,如果需要发送钉钉信息,则需填写其 url 及 message |
| dingding.url | ValueOrSecret | 必填值,钉钉的 Webhook 地址,可以选择直接在 value 填写或从 secretRef 中获取 |
| dingding.message | Object | 必填值,需要发送的钉钉信息,请符合 钉钉信息规范 |
| lark | Object | 可选值,如果需要发送飞书信息,则需填写其 url 及 message |
| lark.url | ValueOrSecret | 必填值,飞书的 Webhook 地址,可以选择直接在 value 填写或从 secretRef 中获取 |
| lark.message | Object | 必填值,需要发送的飞书信息,请符合 飞书信息规范 |
ValueOrSecret 的格式为:
| 参数名 | 类型 | 说明 |
|---|---|---|
| value | String | 可选值,直接填写值 |
| secretRef.name | String | 可选值,从 secret 中获取值,secret 的名称 |
| secretRef.key | String | 可选值,从 secret 中获取值,secret 的 key |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: first-vela-workflownamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000traits:- type: ingressproperties:domain: testsvc.example.comhttp:/: 8000workflow:steps:- name: dingtalk-messagetype: notificationproperties:dingding:# 钉钉 Webhook 地址,请查看:https://developers.dingtalk.com/document/robots/custom-robot-accessurl:value: <your dingtalk url>message:msgtype: texttext:context: 开始运行工作流- name: applicationtype: apply-application- name: slack-messagetype: notificationproperties:slack:# Slack Webhook 地址,请查看:https://api.slack.com/messaging/webhooksurl:secretRef:name: <the secret name that stores your slack url>key: <the secret key that stores your slack url>message:text: 工作流运行完成
apply-object
简介
部署 Kubernetes 原生资源,该功能在 KubeVela v1.1.4 及以上版本可使用。
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| value | object | 必填值,Kubernetes 原生资源字段 |
| cluster | object | 可选值,需要部署的集群名称。如果不指定,则为当前集群。在使用该字段前,请确保你已经使用 vela cluster join 纳管了你的集群 |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: server-with-pvcnamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000volumes:- name: "my-pvc"type: "pvc"mountPath: "/test"claimName: "myclaim"workflow:steps:- name: apply-pvctype: apply-objectproperties:# Kubernetes 原生字段value:apiVersion: v1kind: PersistentVolumeClaimmetadata:name: myclaimnamespace: defaultspec:accessModes:- ReadWriteOnceresources:requests:storage: 8GistorageClassName: standard# 需要部署的集群名称,如果不指定,则默认为当前集群cluster: <your cluster name>- name: apply-servertype: apply-componentproperties:component: express-server
read-object
简介
读取 Kubernetes 原生资源,该功能在 KubeVela v1.1.6 及以上版本可使用。
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| apiVersion | String | 必填值,资源的 apiVersion |
| kind | String | 必填值,资源的 kind |
| name | String | 必填值,资源的 name |
| namespace | String | 选填值,资源的 namespace,默认为 default |
| cluster | String | 选填值,资源的集群名,默认为当前集群,在使用该字段前,请确保你已经使用 vela cluster join 纳管了你的集群 |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: read-objectnamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000workflow:steps:- name: read-objecttype: read-objectoutputs:- name: cpuvalueFrom: output.value.data["cpu"]- name: memoryvalueFrom: output.value.data["memory"]properties:apiVersion: v1kind: ConfigMapname: my-cm-namecluster: <your cluster name>- name: applytype: apply-componentinputs:- from: cpuparameterKey: cpu- from: memoryparameterKey: memoryproperties:component: express-server
export2config
简介
导出数据到 ConfigMap,该功能在 KubeVela v1.1.6 及以上版本可使用。
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| configName | String | 必填值,ConfigMap 的名称 |
| namespace | String | 选填值,ConfigMap 的 namespace,默认为 context.namespace |
| data | Map | 必填值,需要导出到 ConfigMap 中的数据 |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: export-confignamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000workflow:steps:- name: apply-servertype: apply-componentoutputs:- name: statusvalueFrom: output.status.conditions[0].messageproperties:component: express-server- name: export-configtype: export-configinputs:- from: statusparameterKey: data.serverstatusproperties:configName: my-configmapdata:testkey: testvalue
export2secret
简介
导出数据到 Secret,该功能在 KubeVela v1.1.6 及以上版本可使用。
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| secretName | String | 必填值,Secret 的名称 |
| namespace | String | 选填值,Secret 的 namespace,默认为 context.namespace |
| data | Map | 必填值,需要导出到 Secret 中的数据 |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: export-secretnamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000workflow:steps:- name: apply-servertype: apply-componentoutputs:- name: statusvalueFrom: output.status.conditions[0].messageproperties:component: express-server- name: export-secrettype: export-secretinputs:- from: statusparameterKey: data.serverstatusproperties:secretName: my-secretdata:testkey: testvalue
suspend
简介
暂停当前工作流,可以通过 vela workflow resume appname 继续已暂停的工作流。
有关于
vela workflow命令的介绍,可以详见 vela cli。
参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| - | - | - |
示例
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: first-vela-workflownamespace: defaultspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000traits:- type: ingressproperties:domain: testsvc.example.comhttp:/: 8000workflow:steps:- name: slack-messagetype: webhook-notificationproperties:slack:# Slack Webhook 地址,请查看:https://api.slack.com/messaging/webhooksurl: xxxmessage:text: 准备开始部署应用,请管理员审批并继续工作流- name: manual-approvaltype: suspend- name: express-servertype: apply-application