Skip to content
配置文件

配置文件

np.yaml 配置参考

np.yaml 是服务配置的核心文件。放在项目根目录。

最小配置

name: my-app
binary: ./my-app

完整参考

# 服务名称(必需)
name: my-service

# 二进制路径或 Docker 镜像(必需)
binary: ./my-service
# 或使用 Docker:
# image: my-service:latest

# 健康检查端点(推荐)
health_check: /health

# 资源约束
resources:
  cpu: 100m      # CPU(毫核)
  memory: 128mb  # 内存

# 副本数
count: 3

# 环境变量
env:
  LOG_LEVEL: info
  DATABASE_URL: postgres://localhost/mydb

# 端口映射
ports:
  - 8080:80      # host:container

# 更新策略
update:
  type: rolling          # rolling | blue_green | canary
  max_parallel: 1        # 最大并行更新数
  health_check_grace: 30s
  health_check_timeout: 5s
  healthy_deadline: 120s

# 约束
constraints:
  - datacenter = dc1
  - arch = amd64

# 负载均衡
load_balancer:
  enabled: true
  domain: my-app.np.local
  tls: auto               # auto | custom | off

# 卷挂载
volumes:
  - name: data
    type: host
    source: /data/my-app
    destination: /app/data

# 日志
logging:
  level: info
  json: true              # JSON 格式日志

环境变量插值

env:
  DATABASE_URL: ${DATABASE_URL}
  VERSION: ${VERSION:-latest}

多服务文件

可以用 np deploy -f 指定不同配置文件:

np deploy -f frontend.yaml my-frontend
np deploy -f backend.yaml my-backend