Version: v1.0

Dry-Run / Live-Diff

KubeVela 支持两种方式调试 application:dry-run 和 live-diff。

Dry-Run Application

Dry-run 将帮助我们了解哪些资源将被处理并部署到 Kubernetes 集群。另外,该命令支持模拟运行与KubeVela的控制器相同的逻辑并在本地输出结果。

比如,我们 dry-run 下面 application:

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

当前示例中,application vela-app 依赖 KubeVela 内置的 component(webservice) 和 trait(ingress)。我们也可以通过参数 -d 或者 --definitions 指定本地 definition 文件。

参数 -d 或者 --definitions 允许用户从本地文件导入指定的 definitions 以供 application 使用。 参数 dry-run 会将优先使用用户指定的 capabilities 。

Live-Diff Application

Live-diff 将帮助我们预览本次升级 application 会有哪些变更,同时不会对现有集群产生影响。 本功能对于生产环境变更非常有用,同时还能保证升级可控。

本功能会在线上正在运行的版本与本地待升级版本之间生成差异信息。 最终差异结果将展示 application 以及子资源(比如 components 以及 traits)的变更信息(added/modified/removed/no_change)。

假设我们在 dry-run 环节已经部署 application 。 随后,我们列出上面 application 的 revisions 信息。

  1. $ kubectl get apprev -l app.oam.dev/name=vela-app
  2. NAME AGE
  3. vela-app-v1 50s

假设我们将更新该 application :

  1. # new-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: 8080 # change port
  13. cpu: 0.5 # add requests cpu units
  14. - name: my-task # add a component
  15. type: task
  16. properties:
  17. image: busybox
  18. cmd: ["sleep", "1000"]
  19. traits:
  20. - type: ingress
  21. properties:
  22. domain: testsvc.example.com
  23. http:
  24. "/": 8080 # change port

执行 live-diff :

  1. kubectl vela live-diff -f new-app.yaml -r vela-app-v1

参数 -r 或者 --revision 用于指定正在运行中的 ApplicationRevision 名称,该版本将用于与更新版本进行比较。

参数 -c or --context 用于指定显示变更上下文行数,超出上线行数的未变更行将被省略。该功能对于如下场景非常有用:差异结果包含很多未更改的内容,而我们只想关注已更改的内容。

diff

  1. ---
  2. # Application (vela-app) has been modified(*)
  3. ---
  4. apiVersion: core.oam.dev/v1beta1
  5. kind: Application
  6. metadata:
  7. creationTimestamp: null
  8. name: vela-app
  9. namespace: default
  10. spec:
  11. components:
  12. - name: express-server
  13. properties:
  14. + cpu: 0.5
  15. image: crccheck/hello-world
  16. - port: 8000
  17. + port: 8080
  18. + type: webservice
  19. + - name: my-task
  20. + properties:
  21. + cmd:
  22. + - sleep
  23. + - "1000"
  24. + image: busybox
  25. traits:
  26. - properties:
  27. domain: testsvc.example.com
  28. http:
  29. - /: 8000
  30. + /: 8080
  31. type: ingress
  32. - type: webservice
  33. + type: task
  34. status:
  35. batchRollingState: ""
  36. currentBatch: 0
  37. rollingState: ""
  38. upgradedReadyReplicas: 0
  39. upgradedReplicas: 0
  40. ---
  41. ## Component (express-server) has been modified(*)
  42. ---
  43. apiVersion: core.oam.dev/v1alpha2
  44. kind: Component
  45. metadata:
  46. creationTimestamp: null
  47. labels:
  48. app.oam.dev/name: vela-app
  49. name: express-server
  50. spec:
  51. workload:
  52. apiVersion: apps/v1
  53. kind: Deployment
  54. metadata:
  55. labels:
  56. app.oam.dev/appRevision: ""
  57. app.oam.dev/component: express-server
  58. app.oam.dev/name: vela-app
  59. workload.oam.dev/type: webservice
  60. spec:
  61. selector:
  62. matchLabels:
  63. app.oam.dev/component: express-server
  64. template:
  65. metadata:
  66. labels:
  67. app.oam.dev/component: express-server
  68. spec:
  69. containers:
  70. - image: crccheck/hello-world
  71. name: express-server
  72. ports:
  73. - - containerPort: 8000
  74. + - containerPort: 8080
  75. status:
  76. observedGeneration: 0
  77. ---
  78. ### Component (express-server) / Trait (ingress/service) has been removed(-)
  79. ---
  80. - apiVersion: v1
  81. - kind: Service
  82. - metadata:
  83. - labels:
  84. - app.oam.dev/appRevision: ""
  85. - app.oam.dev/component: express-server
  86. - app.oam.dev/name: vela-app
  87. - trait.oam.dev/resource: service
  88. - trait.oam.dev/type: ingress
  89. - name: express-server
  90. - spec:
  91. - ports:
  92. - - port: 8000
  93. - targetPort: 8000
  94. - selector:
  95. - app.oam.dev/component: express-server
  96. ---
  97. ### Component (express-server) / Trait (ingress/ingress) has been removed(-)
  98. ---
  99. - apiVersion: networking.k8s.io/v1beta1
  100. - kind: Ingress
  101. - metadata:
  102. - labels:
  103. - app.oam.dev/appRevision: ""
  104. - app.oam.dev/component: express-server
  105. - app.oam.dev/name: vela-app
  106. - trait.oam.dev/resource: ingress
  107. - trait.oam.dev/type: ingress
  108. - name: express-server
  109. - spec:
  110. - rules:
  111. - - host: testsvc.example.com
  112. - http:
  113. - paths:
  114. - - backend:
  115. - serviceName: express-server
  116. - servicePort: 8000
  117. - path: /
  118. ---
  119. ## Component (my-task) has been added(+)
  120. ---
  121. + apiVersion: core.oam.dev/v1alpha2
  122. + kind: Component
  123. + metadata:
  124. + creationTimestamp: null
  125. + labels:
  126. + app.oam.dev/name: vela-app
  127. + name: my-task
  128. + spec:
  129. + workload:
  130. + apiVersion: batch/v1
  131. + kind: Job
  132. + metadata:
  133. + labels:
  134. + app.oam.dev/appRevision: ""
  135. + app.oam.dev/component: my-task
  136. + app.oam.dev/name: vela-app
  137. + workload.oam.dev/type: task
  138. + spec:
  139. + completions: 1
  140. + parallelism: 1
  141. + template:
  142. + spec:
  143. + containers:
  144. + - command:
  145. + - sleep
  146. + - "1000"
  147. + image: busybox
  148. + name: my-task
  149. + restartPolicy: Never
  150. + status:
  151. + observedGeneration: 0
  152. ---
  153. ### Component (my-task) / Trait (ingress/service) has been added(+)
  154. ---
  155. + apiVersion: v1
  156. + kind: Service
  157. + metadata:
  158. + labels:
  159. + app.oam.dev/appRevision: ""
  160. + app.oam.dev/component: my-task
  161. + app.oam.dev/name: vela-app
  162. + trait.oam.dev/resource: service
  163. + trait.oam.dev/type: ingress
  164. + name: my-task
  165. + spec:
  166. + ports:
  167. + - port: 8080
  168. + targetPort: 8080
  169. + selector:
  170. + app.oam.dev/component: my-task
  171. ---
  172. ### Component (my-task) / Trait (ingress/ingress) has been added(+)
  173. ---
  174. + apiVersion: networking.k8s.io/v1beta1
  175. + kind: Ingress
  176. + metadata:
  177. + labels:
  178. + app.oam.dev/appRevision: ""
  179. + app.oam.dev/component: my-task
  180. + app.oam.dev/name: vela-app
  181. + trait.oam.dev/resource: ingress
  182. + trait.oam.dev/type: ingress
  183. + name: my-task
  184. + spec:
  185. + rules:
  186. + - host: testsvc.example.com
  187. + http:
  188. + paths:
  189. + - backend:
  190. + serviceName: my-task
  191. + servicePort: 8080
  192. + path: /