OAM 应用定义:
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: first-vela-app
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
expose: true
traits:
- type: scaler
properties:
replicas: 1
policies:
- name: target-default
type: topology
properties:
# local 集群即 Kubevela 所在的集群
clusters: ["local"]
namespace: "default"
- name: target-prod
type: topology
properties:
clusters: ["local"]
# 此命名空间需要在应用部署前完成创建
namespace: "prod"
- name: deploy-ha
type: override
properties:
components:
- type: webservice
traits:
- type: scaler
properties:
replicas: 2
workflow:
steps:
- name: deploy2default
type: deploy
properties:
policies: ["target-default"]
- name: manual-approval
type: suspend
- name: deploy2prod
type: deploy
properties:
policies: ["target-prod", "deploy-ha"]
OAM 应用定义,它包括了一个无状态服务组件和运维特征,三个部署策略和工作流步骤。此应用描述的含义是将一个服务部署到两个目标命名空间,并且在第一个目标部署完成后等待人工审核后部署到第二个目标,且在第二个目标时部署2个实例。
components
: 定义应用的核心服务或组件。
name
: 组件名称 express-server
。type
: 声明组件类型为 webservice
(常用于无状态服务)。properties
: 描述服务的具体配置:
image
: 容器镜像为 oamdev/hello-world
。ports
: 暴露端口配置,指定服务监听 8000 端口,且通过 expose: true
表示将端口暴露。traits
: 为组件添加特性或增强功能:
scaler
: 调整组件的副本数。
replicas
: 设置为 1 副本。policies
: 定义部署策略。
target-default
: 定义应用的默认部署拓扑。
clusters
: 将应用部署到 local
集群(即 KubeVela 所在集群)。namespace
: 使用 default
命名空间。target-prod
: 定义应用的生产环境部署拓扑。
clusters
: 仍然使用 local
集群。namespace
: 使用 prod
命名空间(需预先创建)。deploy-ha
: 为高可用部署配置重写策略。
webservice
的组件,调整 scaler
特性:
replicas
: 副本数增加到 2。创建命名空间
# 此命令用于在管控集群创建命名空间
vela env init prod --namespace prod
使用文件部署
vela up -f <https://kubevela.net/example/applications/first-app.yaml>
查看状态
vela status first-vela-app