1.利用consul实现k8s服务自动发现

标题 :
1.利用consul实现k8s服务自动发现
目录 :
微服务架构设计
序号 :
1html

]
            }
        }
    ]
}

}
​ - consul自身支持ACL,但目前,Helm图表不支持其中一些功能,须要额外的手动配置, 有关详细信息可参阅:https://www.consul.io/docs/platform/k8s/helm.html - 咱们使用basic-auth做了受权,当用户访问consul-ui时须要提供用户名和密码 ​shell
yum -y install httpd
echo "$(htpasswd -nb -C 5 consul yourpassword)" >> auth
kubectl create secret generic basic-auth --from-file=auth
- <font color='red'>当您使用basic-auth时,建议使用Https,不然您的用户名和密码可能会被窃听</font> ​ ​ ##### [按需]卸载consulshell
helm del --purge registry
kubectl delete pvc -l app=consul
kubectl delete svc -l consul=true
​ ##### 查看服务是否被注册 登陆到consul的ui,https://yourdomain/ui/dc1/services ![](https://www.showdoc.cc/server/api/common/visitfile/sign/26402b4ae6e60fae2e0e8a15f3bbfa33?showdoc=.jpg) 能够看到咱们的服务已经被注册到了consul中 ​ 如下事项须要您注意: - <font color='red'>若是您的服务没有被正确注册,请检查registry-consul-sync-catalog-*的日志,另外若是您的服务自己存在问题(例如:服务自己不能正确反代到pod)服务也不能被注册</font> - 您须要为pod建立service, consul才能发现. 也就是说consul发现的资源对象时svc,并不是pod ​ ##### 服务注册时的一些规范 - 从上图能够看出,咱们的服务名称很长.这将影响咱们使用网关进行路由的体验(有关网关的设计会在后面章节说起),您能够更改此设置.请更改您的service的亲和属性:"consul.hashicorp.com/service-name": "yourservicename" - 为方便辨识服务,能够为服务打上标签.方便检索 - 有些服务不该该被注册,例如网关服务(由于网关做为外部流量的入口,应该由它路由到具体的服务).您能够更改亲和属性:"consul.hashicorp.com/service-sync": "false"shell
"annotations": {
"consul.hashicorp.com/service-name": "terminal",
"consul.hashicorp.com/service-tags": "honeysuckle,terminalserver"
}
```
最后的效果应该类型这样:


git

引用连接

https://github.com/helm/charts/tree/master/stable/consul
https://www.sunnyos.com/article-show-85.htmlgithub

相关文章
相关标签/搜索