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

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

                ]
            }
        }
    ]
}

}

​
- 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
  • 当您使用basic-auth时,建议使用Https,否则您的用户名和密码可能会被窃听

[按需]卸载consul
helm del --purge registry
kubectl delete pvc -l app=consul
kubectl delete svc -l consul=true

查看服务是否被注册

登录到consul的ui,https://yourdomain/ui/dc1/services

可以看到我们的服务已经被注册到了consul中

以下事项需要您注意:

  • 如果您的服务没有被正确注册,请检查registry-consul-sync-catalog-*的日志,另外如果您的服务本身存在问题(例如:服务本身不能正确反代到pod)服务也不能被注册
  • 您需要为pod创建service, consul才能发现. 也就是说consul发现的资源对象时svc,并非pod
服务注册时的一些规范
  • 从上图可以看出,我们的服务名称很长.这将影响我们使用网关进行路由的体验(有关网关的设计会在后面章节提及),您可以更改此设置.请更改您的service的亲和属性:"consul.hashicorp.com/service-name": "yourservicename"
  • 为方便辨识服务,可以为服务打上标签.方便检索
  • 有些服务不应该被注册,例如网关服务(因为网关作为外部流量的入口,应该由它路由到具体的服务).您可以更改亲和属性:"consul.hashicorp.com/service-sync": "false"
 "annotations": {
      "consul.hashicorp.com/service-name": "terminal",
      "consul.hashicorp.com/service-tags": "honeysuckle,terminalserver"
    }

最后的效果应该类型这样:


引用链接

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

posted @ 2019-08-25 11:02  XIAOBING-TANG  阅读(3839)  评论(0编辑  收藏  举报