版本:v1.3

内置运维特征类型

本文档将展示所有内置运维特征的参数列表。

gateway 运维特征通过一个可用的域名在公网暴露一个组件的服务。

  • 所有组件类型
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
http定义一组网关路径到 Pod 服务端口的映射关系map[string]inttrue
class所使用的 kubernetes ingress classstringtruenginx
classInSpec在 kubernetes ingress 的 ‘.spec.ingressClassName’ 定义 ingress class 而不是在 ‘kubernetes.io/ingress.class’ 注解中定义boolfalsefalse
domain暴露服务所绑定的域名stringtrue
  1. # vela-app.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: first-vela-app
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: oamdev/hello-world
  12. port: 8000
  13. traits:
  14. - type: gateway
  15. properties:
  16. domain: testsvc.example.com
  17. http:
  18. "/": 8000

scaler 为组件配置副本数。

  • webservice
  • worker
  • task
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
replicas工作负载的 Pod 个数inttrue1
  1. # sample.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: website
  6. spec:
  7. components:
  8. - name: frontend # This is the component I want to deploy
  9. type: webservice
  10. properties:
  11. image: nginx
  12. traits:
  13. - type: scaler # Set the replica to the specified value
  14. properties:
  15. replicas: 5

autoscaler 运维特征用于配置自动扩缩容,背后基于 Kubernetes 的 HPA 实现。

注:这个运维特征默认在 VelaUX 处隐藏,你可以在 CLI 侧使用。

  • 所有基于 deployments.apps 类型的组件
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
min能够将工作负载缩容到的最小副本个数inttrue1
max能够将工作负载扩容到的最大副本个数inttrue10
cpuUtil每个容器的平均 CPU 利用率 例如, 50 意味者 CPU 利用率为 50%inttrue50
  1. # sample.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: website
  6. spec:
  7. components:
  8. - name: frontend # This is the component I want to deploy
  9. type: webservice
  10. properties:
  11. image: nginx
  12. traits:
  13. - type: cpuscaler # Automatically scale the component by CPU usage after deployed
  14. properties:
  15. min: 1
  16. max: 10
  17. cpuPercent: 60

我们使用运维特征里的 storage 来管理存储。

storage 可以帮助我们创建并管理 pvcemptyDirsecretconfigMap 等类型的存储。对于 secretconfigMap 类的存储,还支持绑定到 env 当中。

如果你不希望自动创建这些资源,可以将 mountOnly 字段设置为 true。

  • 所有基于 deployments.apps 类型的组件
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
volumeModestringtrueFilesystem
mountPathstringtrue
mountOnlybooltruefalse
accessModes[…]true
volumeNamestringfalse
storageClassNamestringfalse
resourcesresourcesfalse
dataSourceRefdataSourceReffalse
dataSourcedataSourcefalse
selectorselectorfalse
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
mediumstringtrueempty
mountPathstringtrue
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
defaultModeinttrue420
items[]itemsfalse
mountPathstringtrue
mountToEnvmountToEnvfalse
mountOnlybooltruefalse
datamap[string]{nullboolstring
stringDatamap[string]{nullboolstring
readOnlybooltruefalse
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
defaultModeinttrue420
items[]itemsfalse
mountPathstringtrue
mountToEnvmountToEnvfalse
mountOnlybooltruefalse
datamap[string]{nullboolstring
readOnlybooltruefalse
  1. # sample.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: storage-app
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: oamdev/hello-world
  12. ports:
  13. - port: 8000
  14. traits:
  15. - type: storage
  16. properties:
  17. # PVC type storage
  18. pvc:
  19. - name: test1
  20. mountPath: /test/mount/pvc
  21. # EmptyDir type storage
  22. emptyDir:
  23. - name: test1
  24. mountPath: /test/mount/emptydir
  25. # ConfigMap type storage
  26. configMap:
  27. - name: test1
  28. mountPath: /test/mount/cm
  29. # Mount ConfigMap to Env
  30. mountToEnv:
  31. envName: TEST_ENV
  32. configMapKey: key1
  33. data:
  34. key1: value1
  35. key2: value2
  36. # Secret type storage
  37. secret:
  38. - name: test1
  39. mountPath: /test/mount/secret
  40. # Mount Secret to Env
  41. mountToEnv:
  42. envName: TEST_SECRET
  43. secretKey: key1
  44. data:
  45. key1: dmFsdWUx
  46. key2: dmFsdWUy

labels 运维特征可以用来为工作负载上的 Pod 打特殊的标签。

注:这个运维特征默认在 VelaUX 处隐藏,你可以在 CLI 侧使用。

  • 所有组件类型
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
-map[string]stringtrue
  1. # myapp.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: myapp
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: oamdev/hello-world
  12. port: 8000
  13. traits:
  14. - type: labels
  15. properties:
  16. "release": "stable"

annotations 运维特征允许用户在工作负载的 Pod 上加入注解。

注:这个运维特征默认在 VelaUX 处隐藏,你可以在 CLI 侧使用。

  • 所有组件类型
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
-map[string]stringtrue
  1. # myapp.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: myapp
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: oamdev/hello-world
  12. port: 8000
  13. traits:
  14. - type: annotations
  15. properties:
  16. "description": "web application"

kustomize-patch 支持以 inline YAML 字符串形式支持 strategy Merge 和 JSON6902 格式的 patch。

Note: To use kustomize trait, you must enable fluxcd addon first.

  • kustomize
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patches在目标上进行 StrategicMerge 或者 JSON6902 patch 的列表[]patchestrue
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchInline yaml 格式的 patchstringtrue
targetpatch 需要作用在的目标targettrue
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringfalse
groupstringfalse
versionstringfalse
kindstringfalse
namespacestringfalse
annotationSelectorstringfalse
labelSelectorstringfalse
  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: bucket-app
  5. spec:
  6. components:
  7. - name: bucket-comp
  8. type: kustomize
  9. # ... omitted for brevity
  10. traits:
  11. - type: kustomize-patch
  12. properties:
  13. patches:
  14. - patch: |-
  15. apiVersion: v1
  16. kind: Pod
  17. metadata:
  18. name: not-used
  19. labels:
  20. app.kubernetes.io/part-of: test-app
  21. target:
  22. labelSelector: "app=podinfo"

在这个例子中,kustomize-patch 会在所有标记了 app=podinfo 上的 Pod 上做 patch 。

支持以 JSON6902 格式对 kustomize 进行 patch。

  • kustomize

Properties

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchesJsonJSON6902 patch 的列表[]patchesJsontrue
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchpatchtrue
targettargettrue
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringfalse
groupstringfalse
versionstringfalse
kindstringfalse
namespacestringfalse
annotationSelectorstringfalse
labelSelectorstringfalse
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
pathstringtrue
opstringtrue
valuestringfalse
  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: bucket-app
  5. spec:
  6. components:
  7. - name: bucket-comp
  8. type: kustomize
  9. # ... omitted for brevity
  10. traits:
  11. - type: kustomize-json-patch
  12. properties:
  13. patchesJson:
  14. - target:
  15. version: v1
  16. kind: Deployment
  17. name: podinfo
  18. patch:
  19. - op: add
  20. path: /metadata/annotations/key
  21. value: value

支持以 YAML 格式对 kustomize 进行 patch。

  • kustomize
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchesStrategicMergepatchesStrategicMerge 列表[]patchesStrategicMergetrue
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
map[string]{nullboolstring
  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: bucket-app
  5. spec:
  6. components:
  7. - name: bucket-comp
  8. type: kustomize
  9. # ... omitted for brevity
  10. traits:
  11. - type: kustomize-strategy-merge
  12. properties:
  13. patchesStrategicMerge:
  14. - apiVersion: apps/v1
  15. kind: Deployment
  16. metadata:
  17. name: podinfo
  18. spec:
  19. template:
  20. spec:
  21. serviceAccount: custom-service-account

service-binding 运维特征会将一个 Kubernetes 的 secret 资源映射到容器中作为容器的环境变量。

  • webservice
  • worker
  • task
  • cron-task
NameDescriptionTypeRequiredDefault
envMappings主键和 secret 名称的键值对map[string]KeySecrettrue
NameDescriptionTypeRequiredDefault
key主键名称stringfalse
secretsecret 名称stringtrue
  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: init-secret-with-http
  5. namespace: default
  6. spec:
  7. components:
  8. - name: my-server
  9. type: webservice
  10. properties:
  11. image: oamdev/hello-world
  12. port: 8000
  13. traits:
  14. - type: service-binding
  15. properties:
  16. envMappings:
  17. MY_ENV:
  18. secret: secret1
  19. MY_ENV2:
  20. secret: secret2
  21. key: test

sidecar 能够为你的组件容器添加一个边车容器。

  • webservice
  • worker
  • task
  • cron-task
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
name容器名称stringtrue
cmd容器的执行命令[]stringfalse
image容器镜像stringtrue
volumes挂载卷[]volumesfalse
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
pathstringtrue
  1. # app.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: vela-app-with-sidecar
  6. spec:
  7. components:
  8. - name: log-gen-worker
  9. type: worker
  10. properties:
  11. image: busybox
  12. cmd:
  13. - /bin/sh
  14. - -c
  15. - >
  16. i=0;
  17. while true;
  18. do
  19. echo "$i: $(date)" >> /var/log/date.log;
  20. i=$((i+1));
  21. sleep 1;
  22. done
  23. volumes:
  24. - name: varlog
  25. mountPath: /var/log
  26. type: emptyDir
  27. traits:
  28. - type: sidecar
  29. properties:
  30. name: count-log
  31. image: busybox
  32. cmd: [ /bin/sh, -c, 'tail -n+1 -f /var/log/date.log']
  33. volumes:
  34. - name: varlog
  35. path: /var/log

Last updated on 2022年11月1日 by Tianxin Dong