job "vault" { datacenters = ["dc1"] type = "service" # 约束只在 warden、ch4、ash3c 节点上运行 constraint { attribute = "${node.unique.name}" operator = "regexp" value = "^(warden|ch4|ash3c)$" } group "vault" { count = 3 # 确保每个节点只运行一个实例 constraint { operator = "distinct_hosts" value = "true" } # 网络配置 network { port "http" { static = 8200 to = 8200 } } # 服务发现配置 - 包含版本信息 service { name = "vault" port = "http" # 添加版本标签以避免检查拒绝 tags = [ "vault", "secrets", "version:1.20.3" ] check { name = "vault-health" type = "http" path = "/v1/sys/health" interval = "10s" timeout = "3s" method = "GET" } # 健康检查配置 check { name = "vault-sealed-check" type = "script" command = "/bin/sh" args = ["-c", "vault status -format=json | jq -r '.sealed' | grep -q 'false'"] interval = "30s" timeout = "5s" task = "vault" } } # 任务配置 task "vault" { driver = "raw_exec" # 资源配置 resources { cpu = 500 memory = 1024 } # 环境变量 env { VAULT_ADDR = "http://127.0.0.1:8200" } # 模板配置 - Vault 配置文件 template { data = <