coredns 代理consul 运行noamd 部署的应用
nomad 是一个方便的应用调度平台,consul 一个很不错的服务发现工具,coredns 很不错,
扩展性比较强的dns 服务器,集成起来可能做很强大的事情
我的运行环境是mac,实际情况按需部署即可
组件下载
- nomad 下载
https://www.nomadproject.io/docs/install/index.html
- consul 下载
因为以来consul 进行服务注册以及健康检查
https://www.consul.io/docs/install/index.html
- coredns
进行dns 重写以及代理
https://coredns.io/
环境运行
- 启动consul
单机,开发模式
consul agent --dev
效果
- 启动nomad
单机,开发模式
nomad agent --dev
效果
运行测试job
- 简单job
nomad init
内容如下:
job "example" {
datacenters = ["dc1"]
type = "service"
update {
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "3m"
progress_deadline = "10m"
auto_revert = false
canary = 0
}
migrate {
max_parallel = 1
health_check = "checks"
min_healthy_time = "10s"
healthy_deadline = "5m"
}
group "cache" {
count = 2
restart {
attempts = 2
interval = "30m"
delay = "15s"
mode = "fail"
}
ephemeral_disk {
size = 300
}
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
port_map {
db = 6379
}
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
network {
mbits = 10
port "db" {}
}
}
service {
name = "redis-cache"
tags = ["global", "cache"]
port = "db"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
}
}
- 运行job
nomad run example.nomad
效果
coredns 配置
- coredns file 配置
.:53 {
errors
log stdout
health
rewrite name redis.app.com graphql-website.service.consul
cache 30
proxy . 127.0.0.1:8600
}
- 启动dns
./coredns
dns 修改效果查看
- dig 查看
dig @127.0.0.1 redis.app.com
效果
说明
总的来说nomad 还是比较简单的,同时功能比较齐全,结合dns 的功能我们可以实现比较强大,便捷自助平台
备注: 可能出现本地dns 解析的问题,需要进行dns 刷新,主要是mac 系统,即使大家使用的一般都会是linux 或者windows(使用nslookup 工具没有问题)
参考资料
https://www.nomadproject.io/docs/job-specification/service.html
https://coredns.io/
https://www.consul.io/docs/index.html