Version: v1.1

本地试运行

如果你是一个 DevOps 用户或者运维管理员,并且对 Kubernetes 有所了解,为了保证一个应用部署计划在 Kubernetes 运行时集群的表现符合期望,在开发调试阶段,你也可以通过下面的试运行功能提前确认这个部署计划背后的逻辑是否正确。

KubeVela 提供了本地试运行(Dry-run)的功能,来满足你的这个需求。

如何使用

我们将以一个应用部署计划的示例,来进行讲解。

首先编写如下的 YAML 文件:

  1. # app.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: vela-app
  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

可以看到,我们的期望是交付一个 Web Service 的组件,使用来自 crccheck/hello-world 的镜像,并最终提供一个可供对外访问的网关,地址域名为 testsvc.example.com,端口号 8000。

然后打开本地试运行模式,使用如下命令:

  1. vela dry-run -f app.yaml
  1. ---
  2. # Application(vela-app) -- Comopnent(express-server)
  3. ---
  4. apiVersion: apps/v1
  5. kind: Deployment
  6. metadata:
  7. labels:
  8. app.oam.dev/appRevision: ""
  9. app.oam.dev/component: express-server
  10. app.oam.dev/name: vela-app
  11. workload.oam.dev/type: webservice
  12. spec:
  13. selector:
  14. matchLabels:
  15. app.oam.dev/component: express-server
  16. template:
  17. metadata:
  18. labels:
  19. app.oam.dev/component: express-server
  20. spec:
  21. containers:
  22. - image: crccheck/hello-world
  23. name: express-server
  24. ports:
  25. - containerPort: 8000
  26. ---
  27. apiVersion: v1
  28. kind: Service
  29. metadata:
  30. labels:
  31. app.oam.dev/appRevision: ""
  32. app.oam.dev/component: express-server
  33. app.oam.dev/name: vela-app
  34. trait.oam.dev/resource: service
  35. trait.oam.dev/type: ingress
  36. name: express-server
  37. spec:
  38. ports:
  39. - port: 8000
  40. targetPort: 8000
  41. selector:
  42. app.oam.dev/component: express-server
  43. ---
  44. apiVersion: networking.k8s.io/v1beta1
  45. kind: Ingress
  46. metadata:
  47. labels:
  48. app.oam.dev/appRevision: ""
  49. app.oam.dev/component: express-server
  50. app.oam.dev/name: vela-app
  51. trait.oam.dev/resource: ingress
  52. trait.oam.dev/type: ingress
  53. name: express-server
  54. spec:
  55. rules:
  56. - host: testsvc.example.com
  57. http:
  58. paths:
  59. - backend:
  60. serviceName: express-server
  61. servicePort: 8000
  62. path: /
  63. ---

查看本地试运行模式给出的信息,我们可以进行确认:

  1. Kubernetes 集群内部 Service 和我们期望的 kind: Deployment 部署,在相关的镜像地址、域名端口上,是否能匹配。
  2. 最终对外的 Ingress 网关,与 Kubernetes 集群内部的 Service,在相关的镜像地址、域名端口上,是否能匹配。

在完成上述信息确认之后,我们就能进行后续的开发调试步骤了。

最后,你还可以通过 vela dry-run -h 来查看更多可用的本地试运行模式:

  1. Dry Run an application, and output the K8s resources as result to stdout, only CUE template supported for now
  2. Usage:
  3. vela dry-run
  4. Examples:
  5. vela dry-run
  6. Flags:
  7. -d, --definition string specify a definition file or directory, it will only be used in dry-run rather than applied to K8s cluster
  8. -f, --file string application file name (default "./app.yaml")
  9. -h, --help help for dry-run
  10. Global Flags:
  11. -e, --env string specify environment name for application