Skip to main content
Version: 预览版

内置运维特征类型

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

gateway#

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

作用的 Component 类型#

  • 所有组件类型

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
http定义一组网关路径到 Pod 服务端口的映射关系map[string]inttrue
class所使用的 kubernetes ingress classstringtruenginx
classInSpec在 kubernetes ingress 的 '.spec.ingressClassName' 定义 ingress class 而不是在 'kubernetes.io/ingress.class' 注解中定义boolfalsefalse
domain暴露服务所绑定的域名stringtrue

样例#

# vela-app.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: first-vela-app
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
port: 8000
traits:
- type: gateway
properties:
domain: testsvc.example.com
http:
"/": 8000

Scaler#

scaler 为组件配置副本数。

作用的 Component 类型#

  • webservice
  • worker
  • task

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
replicas工作负载的 Pod 个数inttrue1

样例#

# sample.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: website
spec:
components:
- name: frontend # This is the component I want to deploy
type: webservice
properties:
image: nginx
traits:
- type: scaler # Set the replica to the specified value
properties:
replicas: 5

AutoScaler#

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

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

作用的 Component 类型#

  • 所有基于 deployments.apps 类型的组件

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
min能够将工作负载缩容到的最小副本个数inttrue1
max能够将工作负载扩容到的最大副本个数inttrue10
cpuUtil每个容器的平均 CPU 利用率 例如, 50 意味者 CPU 利用率为 50%inttrue50

样例#

# sample.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: website
spec:
components:
- name: frontend # This is the component I want to deploy
type: webservice
properties:
image: nginx
traits:
- type: cpuscaler # Automatically scale the component by CPU usage after deployed
properties:
min: 1
max: 10
cpuPercent: 60

Storage#

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

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

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

作用的 Component 类型#

  • 所有基于 deployments.apps 类型的组件

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
volumeModestringtrueFilesystem
mountPathstringtrue
mountOnlybooltruefalse
accessModes[...]true
volumeNamestringfalse
storageClassNamestringfalse
resourcesresourcesfalse
dataSourceRefdataSourceReffalse
dataSourcedataSourcefalse
selectorselectorfalse

emptyDir#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
mediumstringtrueempty
mountPathstringtrue

secret#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
defaultModeinttrue420
items[]itemsfalse
mountPathstringtrue
mountToEnvmountToEnvfalse
mountOnlybooltruefalse
datamap[string]{nullboolstring
stringDatamap[string]{nullboolstring
readOnlybooltruefalse

configMap#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
defaultModeinttrue420
items[]itemsfalse
mountPathstringtrue
mountToEnvmountToEnvfalse
mountOnlybooltruefalse
datamap[string]{nullboolstring
readOnlybooltruefalse

样例#

# sample.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: storage-app
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
traits:
- type: storage
properties:
# PVC type storage
pvc:
- name: test1
mountPath: /test/mount/pvc
# EmptyDir type storage
emptyDir:
- name: test1
mountPath: /test/mount/emptydir
# ConfigMap type storage
configMap:
- name: test1
mountPath: /test/mount/cm
# Mount ConfigMap to Env
mountToEnv:
envName: TEST_ENV
configMapKey: key1
data:
key1: value1
key2: value2
# Secret type storage
secret:
- name: test1
mountPath: /test/mount/secret
# Mount Secret to Env
mountToEnv:
envName: TEST_SECRET
secretKey: key1
data:
key1: dmFsdWUx
key2: dmFsdWUy

Labels#

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

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

作用的 Component 类型#

  • 所有组件类型

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
-map[string]stringtrue

样例#

# myapp.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: myapp
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
port: 8000
traits:
- type: labels
properties:
"release": "stable"

Annotations#

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

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

作用的 Component 类型#

  • 所有组件类型

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
-map[string]stringtrue

样例#

# myapp.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: myapp
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
port: 8000
traits:
- type: annotations
properties:
"description": "web application"

kustomize-patch#

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

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

作用的 Component 类型#

  • kustomize

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patches在目标上进行 StrategicMerge 或者 JSON6902 patch 的列表[]patchestrue

patches#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchInline yaml 格式的 patchstringtrue
targetpatch 需要作用在的目标targettrue
target#
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringfalse
groupstringfalse
versionstringfalse
kindstringfalse
namespacestringfalse
annotationSelectorstringfalse
labelSelectorstringfalse

样例#

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bucket-app
spec:
components:
- name: bucket-comp
type: kustomize
# ... omitted for brevity
traits:
- type: kustomize-patch
properties:
patches:
- patch: |-
apiVersion: v1
kind: Pod
metadata:
name: not-used
labels:
app.kubernetes.io/part-of: test-app
target:
labelSelector: "app=podinfo"

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

kustomize-json-patch#

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

作用的 Component 类型#

  • kustomize

参数说明#

Properties#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchesJsonJSON6902 patch 的列表[]patchesJsontrue

patchesJson#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchpatchtrue
targettargettrue
target#
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringfalse
groupstringfalse
versionstringfalse
kindstringfalse
namespacestringfalse
annotationSelectorstringfalse
labelSelectorstringfalse
patch#
NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
pathstringtrue
opstringtrue
valuestringfalse

样例#

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bucket-app
spec:
components:
- name: bucket-comp
type: kustomize
# ... omitted for brevity
traits:
- type: kustomize-json-patch
properties:
patchesJson:
- target:
version: v1
kind: Deployment
name: podinfo
patch:
- op: add
path: /metadata/annotations/key
value: value

kustomize-strategy-merge#

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

作用的 Component 类型#

  • kustomize

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
patchesStrategicMergepatchesStrategicMerge 列表[]patchesStrategicMergetrue

patchesStrategicMerge#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
map[string]{nullboolstring

样例#

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bucket-app
spec:
components:
- name: bucket-comp
type: kustomize
# ... omitted for brevity
traits:
- type: kustomize-strategy-merge
properties:
patchesStrategicMerge:
- apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
spec:
template:
spec:
serviceAccount: custom-service-account

service-binding#

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

作用的 Component 类型#

  • webservice
  • worker
  • task
  • cron-task

参数说明#

NameDescriptionTypeRequiredDefault
envMappings主键和 secret 名称的键值对map[string][KeySecret](#keysecret)true

KeySecret#

NameDescriptionTypeRequiredDefault
key主键名称stringfalse
secretsecret 名称stringtrue

样例#

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: init-secret-with-http
namespace: default
spec:
components:
- name: my-server
type: webservice
properties:
image: oamdev/hello-world
port: 8000
traits:
- type: service-binding
properties:
envMappings:
MY_ENV:
secret: secret1
MY_ENV2:
secret: secret2
key: test

sidecar#

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

作用的 Component 类型#

  • webservice
  • worker
  • task
  • cron-task

参数说明#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
name容器名称stringtrue
cmd容器的执行命令[]stringfalse
image容器镜像stringtrue
volumes挂载卷[]volumesfalse

volumes#

NAMEDESCRIPTIONTYPEREQUIREDDEFAULT
namestringtrue
pathstringtrue

样例#

# app.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: vela-app-with-sidecar
spec:
components:
- name: log-gen-worker
type: worker
properties:
image: busybox
cmd:
- /bin/sh
- -c
- >
i=0;
while true;
do
echo "$i: $(date)" >> /var/log/date.log;
i=$((i+1));
sleep 1;
done
volumes:
- name: varlog
mountPath: /var/log
type: emptyDir
traits:
- type: sidecar
properties:
name: count-log
image: busybox
cmd: [ /bin/sh, -c, 'tail -n+1 -f /var/log/date.log']
volumes:
- name: varlog
path: /var/log
Last updated on by wyike