Skip to content

Instantly share code, notes, and snippets.

@Ranjandas
Created December 23, 2022 02:10
Show Gist options
  • Save Ranjandas/14ab098509f5a6f1ac9a94a0d98fc8df to your computer and use it in GitHub Desktop.
Save Ranjandas/14ab098509f5a6f1ac9a94a0d98fc8df to your computer and use it in GitHub Desktop.
service {
name = "counting"
id = "counting"
port = 9003
address = "127.0.0.2"
connect {
sidecar_service {}
}
check {
id = "counting-check"
http = "http://localhost:9003/health"
method = "GET"
interval = "1s"
timeout = "1s"
}
}
service {
name = "dashboard"
port = 9002
address = "127.0.0.1"
connect {
sidecar_service {
proxy {
upstreams = [
{
destination_name = "counting"
local_bind_port = 5000
destination_peer = "dc2"
},
]
}
}
}
check {
id = "dashboard-check"
http = "http://localhost:9002/health"
method = "GET"
interval = "1s"
timeout = "1s"
}
}
Kind = "exported-services"
Name = "default"
Services = [
{
Name = "counting"
Consumers = [
{
Peer = "dc1"
}
]
}
]
Kind = "proxy-defaults"
Name = "global"
MeshGateway {
mode = "local"
}
@Ranjandas
Copy link
Author

Prerequisite

  • If running on macOS, add an additional IP to loopback

    sudo ifconfig lo0 alias 127.0.0.2
    
  • Consul 1.14.3

  • A supported envoy binary

Steps

  • Start dc1 with dashboard service registered

    consul agent -dev -bind 127.0.0.1 -client 127.0.0.1 -datacenter dc1 -config-file dashboard.hcl
    
  • Start dc2 with counting service registered

    consul agent -dev -bind 127.0.0.2 -client 127.0.0.2 -datacenter dc2 -config-file counting.hcl
    
  • Generate peering token in dc1

    consul peering generate-token -name dc2 | pbcopy
    
  • Establish peering in dc2

    consul peering establish -name dc1 -http-addr 127.0.0.2:8500 -peering-token $(pbpaste)
    
  • Run mesh-gateway in dc1

    consul connect envoy -gateway=mesh -register -service "gateway-primary" -address "127.0.0.1:8443" -wan-address "127.0.0.1:8443"
    
  • Run mesh-gateway in dc2

    export CONSUL_HTTP_ADDR=http://127.0.0.2:8500
    export CONSUL_GRPC_ADDR=http://127.0.0.2:8502
    consul connect envoy -gateway=mesh -register -service "gateway-secondary" -address "127.0.0.2:8443" -wan-address "127.0.0.2:8443"  -admin-bind 127.0.0.2:19000
    
  • Run dummy Python webservers for counting and dashboard

    mkdir -p health
    python3 -m http.server --bind 127.0.0.1 9002
    
    mkdir -p health
    python3 -m http.server --bind 127.0.02 9003
    
  • Run dashboard sidecar proxy

    consul connect envoy -sidecar-for dashboard -admin-bind 127.0.0.1:19001
    
  • Run counting sidecar proxy

    export CONSUL_HTTP_ADDR=http://127.0.0.2:8500
    export CONSUL_GRPC_ADDR=http://127.0.0.2:8502
    consul connect envoy -sidecar-for counting -admin-bind 127.0.0.2:19001
    
  • Export counting to dc1

    consul config write -http-addr 127.0.0.2:8500 export-counting.hcl
    
  • Write proxy-defaults to both DCs

    consul config write proxy-defaults.hcl  
    consul config write -http-addr 127.0.0.2:8500 proxy-defaults.hcl 
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment