Version: v1.2
本地试运行
如果你是一个 DevOps 用户或者运维管理员,并且对 Kubernetes 有所了解,为了保证一个应用部署计划在 Kubernetes 运行时集群的表现符合期望,在开发调试阶段,你也可以通过下面的试运行功能提前确认这个部署计划背后的逻辑是否正确。
KubeVela 提供了本地试运行(Dry-run)的功能,来满足你的这个需求。
如何使用
我们将以一个应用部署计划的示例,来进行讲解。
首先编写如下的 YAML 文件:
# app.yamlapiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: vela-appspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000traits:- type: ingressproperties:domain: testsvc.example.comhttp:"/": 8000
可以看到,我们的期望是交付一个 Web Service 的组件,使用来自 crccheck/hello-world 的镜像,并最终提供一个可供对外访问的网关,地址域名为 testsvc.example.com,端口号 8000。
然后打开本地试运行模式,使用如下命令:
vela dry-run -f app.yaml
---# Application(vela-app) -- Comopnent(express-server)---apiVersion: apps/v1kind: Deploymentmetadata:labels:app.oam.dev/appRevision: ""app.oam.dev/component: express-serverapp.oam.dev/name: vela-appworkload.oam.dev/type: webservicespec:selector:matchLabels:app.oam.dev/component: express-servertemplate:metadata:labels:app.oam.dev/component: express-serverspec:containers:- image: crccheck/hello-worldname: express-serverports:- containerPort: 8000---apiVersion: v1kind: Servicemetadata:labels:app.oam.dev/appRevision: ""app.oam.dev/component: express-serverapp.oam.dev/name: vela-apptrait.oam.dev/resource: servicetrait.oam.dev/type: ingressname: express-serverspec:ports:- port: 8000targetPort: 8000selector:app.oam.dev/component: express-server---apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:labels:app.oam.dev/appRevision: ""app.oam.dev/component: express-serverapp.oam.dev/name: vela-apptrait.oam.dev/resource: ingresstrait.oam.dev/type: ingressname: express-serverspec:rules:- host: testsvc.example.comhttp:paths:- backend:serviceName: express-serverservicePort: 8000path: /---
查看本地试运行模式给出的信息,我们可以进行确认:
- Kubernetes 集群内部 Service 和我们期望的
kind: Deployment部署,在相关的镜像地址、域名端口上,是否能匹配。 - 最终对外的 Ingress 网关,与 Kubernetes 集群内部的
Service,在相关的镜像地址、域名端口上,是否能匹配。
在完成上述信息确认之后,我们就能进行后续的开发调试步骤了。
最后,你还可以通过 vela dry-run -h 来查看更多可用的本地试运行模式:
Dry Run an application, and output the K8s resources as result to stdout, only CUE template supported for nowUsage:vela dry-runExamples:vela dry-runFlags:-d, --definition string specify a definition file or directory, it will only be used in dry-run rather than applied to K8s cluster-f, --file string application file name (default "./app.yaml")-h, --help help for dry-runGlobal Flags:-e, --env string specify environment name for application