使用HashiCorp Consul和AWS Cloud Map实现跨混合基础设施环境服务发现

NOV 29 2018 ANUBHAV MISHRA

Yesterday, AWS announced general availability of their new service discovery tool, AWS Cloud Map. AWS users will now have the capability to discover resources and services within AWS environments, conduct health checks, and integrate with other service mesh offerings, like HashiCorp Consul. HashiCorp, an Advanced tier member of the AWS Partner Network, worked closely with AWS engineers and is pleased to announce that HashiCorp Consul is offering launch-day support of AWS Cloud Map.

Consul is a distributed service mesh to connect, secure, and configure services across any runtime platform and public or private cloud. With the launch day support of AWS Cloud Map, Consul users can seamlessly discover services registered in AWS and vice versa. Additionally, having a central catalog gives users a unified view of services, regardless of whether those services are in the cloud or on-premises.

Video

AWS Cloud Map to Consul

Services registered in AWS Cloud Map are actively synced to the Consul catalog without having to make any changes to existing Cloud Map services themselves. Consul users can then discover and connect to these services using Consul DNS interface or the HTTP API.

The syncing process by default syncs all services registered in AWS Cloud Map to Consul. Below is an example of a service called “web” registered in AWS Cloud Map.

Cloud Map Service

The service has three service instances registered with A name records. Shortly after registering the service in AWS Cloud Map, it becomes available in Consul and can be queried using Consul’s DNS interface.

# From a Non-AWS or On-premise server
$ dig web.service.consul
…..
;; QUESTION SECTION:
;web.service.consul.        IN    A

;; ANSWER SECTION:
web.service.consul.    0    IN    A    10.0.0.3
web.service.consul.    0    IN    A    10.0.0.2
web.service.consul.    0    IN    A    10.0.0.1

;; ADDITIONAL SECTION:
web.service.consul.    0    IN    TXT    "external-source=aws"
web.service.consul.    0    IN    TXT    "external-source=aws"
web.service.consul.    0    IN    TXT    "external-source=aws"

The same service can be accessed using Consul’s HTTP API.

Externally registered services from AWS Cloud Map are clearly marked in the UI with the AWS icon and tag (Consul 1.4.1+ is required for the icon to be visible, but earlier versions of Consul work for the sync functionality):

AWS External Service Icon

Consul to AWS Cloud Map

Services registered in the Consul catalog can be actively synced into AWS Cloud Map as well. AWS users and applications can discover those services using one of the AWS SDKs, API calls, or DNS queries. This enables users and applications in AWS to extend service discovery capabilities beyond AWS infrastructure. For example, an application running in AWS can discover a database running in an on-premises data center.

The syncing process by default syncs all services registered in Consul to AWS Cloud Map. In this release, services can also be filtered on their name prefix by supplying the -aws-service-prefix argument. Below is an example of a service called “db” registered in Consul and can be seen using the UI or DNS interface.

DB Service in Consul
$ dig db.service.consul SRV
…..
;; QUESTION SECTION:
;db.service.consul.        IN    SRV

;; ANSWER SECTION:
db.service.consul.    0    IN    SRV    1 1 6379 0a000001.addr.dc1.consul.
db.service.consul.    0    IN    SRV    1 1 6380 0a000001.addr.dc1.consul.

Shortly after registering the service in Consul it becomes available in AWS Cloud Map as shown below.

image

Catalog Syncer

The sync process can be run in an environment with access to AWS and Consul API. There are additional options that can be set to configure sync direction, service name prefix, and more.

$ ./consul-aws sync-catalog -h
Usage: consul-aws sync-catalog [options]

  Sync AWS services, and more with the Consul service catalog.
  This enables AWS services to discover and communicate with external
  services, and allows external services to discover and communicate with
  AWS services.
…..

Command Options

  -aws-dns-ttl=<int>
     DNS TTL for services created in AWS CloudMap in seconds. (Defaults
     to 60)

  -aws-namespace-id=<string>
     The AWS namespace to sync with Consul services.

  -aws-pull-interval=<string>
     The interval between fetching from AWS CloudMap. Accepts a sequence of decimal numbers, each with optional fraction and a unit suffix,
     such as "300ms", "10s", "1.5m". Defaults to 30s)

  -aws-service-prefix=<string>
     A prefix to prepend to all services written to AWS from Consul. If
     this is not set then services will have no prefix.

  -consul-service-prefix=<string>
     A prefix to prepend to all services written to Consul from AWS. If
     this is not set then services will have no prefix.

  -to-aws
     If true, Consul services will be synced to AWS.

  -to-consul
     If true, AWS services will be synced to Consul.

The sync functionality is part of the consul-aws project. This project ships as a single binary that can be run outside or inside the AWS environment. By building this project separate from Consul core, we can iterate on AWS integrations more quickly and release new versions without forcing users to do a full Consul upgrade.

For a full walkthrough for using Consul-AWS, read the guide.

Extending Consul Catalog to AWS App Mesh

At re:Invent, AWS also announced AWS App Mesh, AWS’s service mesh offering for native AWS environments. AWS App Mesh uses AWS Cloud Map as the service registry which allows AWS App Mesh to discover instances of a given service in AWS. Because the integration of AWS Cloud Map and Consul allows services registered using Consul to be available in AWS Cloud Map, AWS App Mesh can also discover these services. This lets users extend AWS App Mesh to private clouds and beyond.

Conclusion

The AWS Cloud Map and HashiCorp Consul integration enables users to extend service discovery to heterogeneous environments without requiring a large amount of manual configuration. Organizations utilizing hybrid cloud infrastructure or operating in multiple regions can ensure that their services have access to necessary resources across all of their data centers. Because of this integration, users will now have a seamless service discovery experience for both native and non-native AWS environments that can easily be incorporated into their existing workflows. Those operating within AWS-only environments can now utilize resources located outside those environments, like on-premises data centers, and Consul users gain greater visibility of services being created by other tools, like AWS App Mesh.

The AWS Cloud Map and Consul integration is available now. To learn more, please refer to the Consul-AWS guide in the Consul documentation.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,125评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,293评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,054评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,077评论 1 291
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,096评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,062评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,988评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,817评论 0 273
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,266评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,486评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,646评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,375评论 5 342
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,974评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,621评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,796评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,642评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,538评论 2 352

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,651评论 18 139
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,322评论 0 10
  • 网上疯转的一道数学题,答案隐藏着性格密码。它的答案不止一个,而且每个答案都应对着一种性格。快快让大脑运转起来,看看...
    达内会计学院阅读 807评论 3 1
  • 经常可以看到3d中的模型不停地换肤,具体怎么做的不知道,但绝对不是简单的重新loading一个新的模型。以下目前使...
    论宅阅读 3,040评论 0 1
  • 没有咖啡做生活失去了不少乐趣,让人疲倦的生活。就算自己是朵永不调落的花朵。可当外力介入的时候,不用说是突如其来的急...
    流年急景阅读 224评论 0 0