Version: v1.0

检索 Applications

本章节我们将介绍如何检索 application 相关的资源。

获取 Application 列表

  1. $ kubectl get application
  2. NAME COMPONENT TYPE PHASE HEALTHY STATUS AGE
  3. app-basic app-basic webservice running true 12d
  4. website frontend webservice running true 4m54s

我们可以使用 application 缩写 kubectl get app

查看 Application 详情

  1. $ kubectl get app website -o yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. generation: 1
  6. name: website
  7. namespace: default
  8. spec:
  9. components:
  10. - name: frontend
  11. properties:
  12. image: nginx
  13. traits:
  14. - properties:
  15. cpuPercent: 60
  16. max: 10
  17. min: 1
  18. type: cpuscaler
  19. - properties:
  20. image: fluentd
  21. name: sidecar-test
  22. type: sidecar
  23. type: webservice
  24. - name: backend
  25. properties:
  26. cmd:
  27. - sleep
  28. - "1000"
  29. image: busybox
  30. type: worker
  31. status:
  32. ...
  33. latestRevision:
  34. name: website-v1
  35. revision: 1
  36. revisionHash: e9e062e2cddfe5fb
  37. services:
  38. - healthy: true
  39. name: frontend
  40. traits:
  41. - healthy: true
  42. type: cpuscaler
  43. - healthy: true
  44. type: sidecar
  45. - healthy: true
  46. name: backend
  47. status: running

以下是需要我们了解的一些重要信息:

  1. status.latestRevision 用于显示 application 当前运行的版本。
  2. status.services 用于显示 application 中 component 的健康状态。
  3. status.status 用于显示 application 的全局状态。

获取 Application 版本

KubeVela 会对 application 对每次 spec 变更生成新版本。

  1. $ kubectl get apprev -l app.oam.dev/name=website
  2. NAME AGE
  3. website-v1 35m

检索 Components

我们可以检索出当前 KubeVela 中支持的 ComponentDefinition 列表。

  1. kubectl get comp -n vela-system
  2. NAME WORKLOAD-KIND DESCRIPTION
  3. task Job Describes jobs that run code or a script to completion.
  4. webservice Deployment Describes long-running, scalable, containerized services that have a stable network endpoint to receive external network traffic from customers.
  5. worker Deployment Describes long-running, scalable, containerized services that running at backend. They do NOT have network endpoint to receive external network traffic.

正常情况下 ComponentDefinition 只能被同 namespace 下 application 引用,但是 vela-system namespace 下可以被所有 application 引用。

  1. $ kubectl vela show webservice
  2. # Properties
  3. +------------------+----------------------------------------------------------------------------------+-----------------------+----------+---------+
  4. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  5. +------------------+----------------------------------------------------------------------------------+-----------------------+----------+---------+
  6. | cmd | Commands to run in the container | []string | false | |
  7. | env | Define arguments by using environment variables | [[]env](#env) | false | |
  8. | addRevisionLabel | | bool | true | false |
  9. | image | Which image would you like to use for your service | string | true | |
  10. | port | Which port do you want customer traffic sent to | int | true | 80 |
  11. | cpu | Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core) | string | false | |
  12. | volumes | Declare volumes and volumeMounts | [[]volumes](#volumes) | false | |
  13. +------------------+----------------------------------------------------------------------------------+-----------------------+----------+---------+
  14. ##### volumes
  15. +-----------+---------------------------------------------------------------------+--------+----------+---------+
  16. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  17. +-----------+---------------------------------------------------------------------+--------+----------+---------+
  18. | name | | string | true | |
  19. | mountPath | | string | true | |
  20. | type | Specify volume type, options: "pvc","configMap","secret","emptyDir" | string | true | |
  21. +-----------+---------------------------------------------------------------------+--------+----------+---------+
  22. ## env
  23. +-----------+-----------------------------------------------------------+-------------------------+----------+---------+
  24. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  25. +-----------+-----------------------------------------------------------+-------------------------+----------+---------+
  26. | name | Environment variable name | string | true | |
  27. | value | The value of the environment variable | string | false | |
  28. | valueFrom | Specifies a source the value of this var should come from | [valueFrom](#valueFrom) | false | |
  29. +-----------+-----------------------------------------------------------+-------------------------+----------+---------+
  30. ### valueFrom
  31. +--------------+--------------------------------------------------+-------------------------------+----------+---------+
  32. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  33. +--------------+--------------------------------------------------+-------------------------------+----------+---------+
  34. | secretKeyRef | Selects a key of a secret in the pod's namespace | [secretKeyRef](#secretKeyRef) | true | |
  35. +--------------+--------------------------------------------------+-------------------------------+----------+---------+
  36. #### secretKeyRef
  37. +------+------------------------------------------------------------------+--------+----------+---------+
  38. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  39. +------+------------------------------------------------------------------+--------+----------+---------+
  40. | name | The name of the secret in the pod's namespace to select from | string | true | |
  41. | key | The key of the secret to select from. Must be a valid secret key | string | true | |
  42. +------+------------------------------------------------------------------+--------+----------+---------+

检索 Traits

我们可以检索出当前 KubeVela 中支持对 TraitDefinitions 。

  1. $ kubectl get trait -n vela-system
  2. NAME APPLIES-TO DESCRIPTION
  3. cpuscaler [webservice worker] configure k8s HPA with CPU metrics for Deployment
  4. ingress [webservice worker] Configures K8s ingress and service to enable web traffic for your service. Please use route trait in cap center for advanced usage.
  5. scaler [webservice worker] Configures replicas for your service.
  6. sidecar [webservice worker] inject a sidecar container into your app

正常情况下 TraitDefinition 只能被同 namespace 下的 application 引用,但是 vela-system namespace 下的可以被所有 application 引用。

我们可以用命令 kubectl vela show 查看指定 TraitDefinition 暴露的参数。

  1. $ kubectl vela show sidecar
  2. # Properties
  3. +---------+-----------------------------------------+----------+----------+---------+
  4. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  5. +---------+-----------------------------------------+----------+----------+---------+
  6. | name | Specify the name of sidecar container | string | true | |
  7. | image | Specify the image of sidecar container | string | true | |
  8. | command | Specify the commands run in the sidecar | []string | false | |
  9. +---------+-----------------------------------------+----------+----------+---------+