文件配置
简介
1.VKubefile.yaml 是一个用于配置容器部署的 YAML 格式配置文件。它提供了简单直观的方式来定义镜像构建,容器部署和运行参数。 2.~/.vkube/config.yaml是记录登陆信息的,其中需要注意的是,配置DokerhubToken或GHCRToken的值时,其权限需要write&&read。否则,push镜像会失败。
基础配置
Kind: vkube # 必填,目前仅支持 vkube
vkubeToken: "your-token" # 必填,认证令牌,在vkube网页端生成的token,用于部署某个vkube服务
imageRegistry: "docker" # 必填,镜像仓库类型,目前支持 "docker" 或 "ghcr"。这里确定后,推送镜像时只能推送到这个镜像仓库。
容器配置
在 containers 字段下可以配置一个或多个容器:
containers:
- imageName: nginx
tag: ""
deploy: # 必填,部署相关配置
containerName: "app1" # 容器名称,必须是小写。字母、数字,可包含连字符
resourceUnit: 1 # 资源单元数,必须大于等于1的整数
ports: # 可选,端口映射配置
- containerPort: 8080 # 容器端口(1-65535)
hostPort: 8080 # 主机端口(1-65535)
rewrite: false # false or true
path: "/test" #(^\/[a-zA-Z0-9\/._-]\*$),通过path与url组合来访问container的服务
env: # 可选,环境变量配置
- name: "DB_HOST"
value: "localhost"
configurations: # 可选,配置文件映射
"./config/app.conf": "/etc/app/config.conf" # 本地路径: 容器内挂载路径
# 镜像配置(以下两种方式二选一)
# 方式1:使用镜像库已有镜像,只用一键部署功能
registryImagePath: "docker.io/nginx:latest" # 完整的镜像路径
# 方式2:本地构建镜像,然后一键构建并部署
build:
dockerfilePath: "./Dockerfile" #Dockerfile 路径
context: ""
配置说明
镜像配置
支持两种方式:
1.使用 registryImagePath 指定现有镜像
- 支持格式:
- docker.io/account/image-name:tag
- ghcr.io/account/image-name:tag
- image-name:tag(Docker Hub)
- account/image-name:tag(Docker Hub)
2.本地构建镜像
- 需要指定 build的dockerfilePath
- 必须同时提供 imageName 和 tag(这个不写会默认为latest)
部署配置
- containerName:容器名称,必须符合 Kubernetes 命名规范
- resourceUnit:资源单元配置,整数值
- ports:端口映射,支持容器端口到主机端口的映射。ports作为一个数组,你可以写几组,但格式都应该如下。
#第一种
ports:
containerPort: 8080 # 容器端口(1-65535)
hostPort: 8080 # 主机端口(1-65535)
#第二种
ports:
containerPort: 8081
rewrite: false # false or true
path: "/test" # 符合正则表达式(^\/[a-zA-Z0-9\/._-]\*$)
# 第三种
ports:
containerPort: 81
hostPort: 8081
rewrite: false # false or true
path: "/test"
- env:环境变量配置
- configurations:配置文件映射,支持将本地配置文件挂载到容器内
SSH 配置
- 设置端口:将 containerPort 的值设为 22,hostPort 的值设为任意有效数值。
- 将 installSSH 的值设为 true,并配置 sshPubKeyPath。必须确保 dockerFilePath 是正确的。然后使用 vkube deploy -f ./xxxfile 命令部署服务。
- 若要连接 SSH,可使用命令 ssh -p xxxhostPort root@xxxServerIP
ssh的配置例子:
Kind: vkube
vkubeToken: "xxx"
imageRegistry: docker
containers:
- imageName: nginx
tag: ""
deploy:
containerName: nodewatcher
resourceUnit: 1
command: ["/kube/v-cloud-kube", "-file","/config/v-kube-service.yaml","-permission-list","/config/permission_list.yaml"]
ports:
- containerPort: 22
hostPort: 20001
env:
- name: ENV1
value: VALUE1
- name: ENV2
value: VALUE2
args:
- "config.file=/etc/loki/loki-config.yaml"
- "config.expand-env=true"
configurations:
/local-path1/config-name1: "/etc/nginx/conf.d/default.conf"
/local-path2/config-name2: "/etc/nginx/conf.d/default.conf"
persistStorage: "/test"
build:
installSSH: true
sshPubKeyPath: "~/.ssh/id_rsa.pub"
dockerfilePath: "./Dockerfile" # Dockerfile path
contextPath: "." # Optional, build context
buildArgs:
- name: GOLANG_VER
value: 1.22.3
- name: port
value: 3005
示例
需要本地build镜像
Kind: vkube
token: "your-token"
imageRegistry: "docker"
containers:
- deploy:
containerName: "web-app"
resourceUnit: 2
ports:
- containerPort: 80
hostPort: 8080
env:
- name: "ENV"
value: "production"
configurations:
"./nginx.conf": "/etc/nginx/nginx.conf"
persistStorage: "/data"
build:
dockerfilePath: "./Dockerfile"
contextPath: "."
buildArgs:
- name: VERSION
value: "1.0"
imageName: "web-app"
tag: "v1.0"
部署已存在在镜像库的镜像
Kind: vkube
token: "xxx"
imageRegistry: docker
containers:
- registryImagePath: ghcr.io/vcloud-systems/v-node-watcher:v2.0
deploy:
containerName: nodewatcher
resourceUnit: 4
command: ["/kube/v-cloud-kube", "-file","/config/v-kube-service.yaml","-permission-list","/config/permission_list.yaml"]
ports:
- containerPort: 980
hostPort: 20001
env:
- name: ENV1
value: VALUE1
- name: ENV2
value: VALUE2
args:
- "config.file=/etc/loki/loki-config.yaml"
- "config.expand-env=true"
configurations:
/local-path1/config-name1: "/etc/nginx/conf.d/default.conf"
/local-path2/config-name2: "/etc/nginx/conf.d/default.conf"
persistStorage: "/test"
混合形式(既有需要build的镜像也有已存在镜像库的镜像)
Kind: vkube
token: "xxx"
imageRegistry: docker
containers:
- registryImagePath: ghcr.io/you-github-username/imagename:tag
deploy:
containerName: nodewatcher
resourceUnit: 4
command: ["/kube/v-cloud-kube", "-file","/config/v-kube-service.yaml","-permission-list","/config/permission_list.yaml"]
ports:
- containerPort: 980
hostPort: 20001
env:
- name: ENV1
value: VALUE1
- name: ENV2
value: VALUE2
args:
- "config.file=/etc/loki/loki-config.yaml"
- "config.expand-env=true"
configurations:
/local-path1/config-name1: "/etc/nginx/conf.d/default.conf"
/local-path2/config-name2: "/etc/nginx/conf.d/default.conf"
persistStorage: "/test"
- imageName: nginx
tag: ""
deploy:
containerName: nodewatcher
resourceUnit: 1
command: ["/kube/v-cloud-kube", "-file","/config/v-kube-service.yaml","-permission-list","/config/permission_list.yaml"]
ports:
- containerPort: 980
hostPort: 20001
env:
- name: ENV1
value: VALUE1
- name: ENV2
value: VALUE2
args:
- "config.file=/etc/loki/loki-config.yaml"
- "config.expand-env=true"
configurations:
/local-path1/config-name1: "/etc/nginx/conf.d/default.conf"
/local-path2/config-name2: "/etc/nginx/conf.d/default.conf"
persistStorage: "/test"
build:
dockerfilePath: "./build/docker/Dockerfile"
contextPath: ""
buildArgs:
- name: GOLANG_VER
value: 1.22.3
- name: port
value: 3005
注意事项
- registryImagePath 与 build 配置互斥,不能同时使用
- 使用 build 时必须提供 imageName 和 tag
- 端口范围必须在 1-65535 之间
- 配置文件路径必须使用有效的文件系统路径格式
← Introduction 用工作流持续部署 →