二、Consul Service Mesh

一、Consul Connect

tips: -dev

1.service definition

counting.json

{
  "service": {
    "name": "counting",
    "id": "counting-1",
    "port": 9003,
    "check": {
      "http": "http://localhost:9003/health",
      "method": "GET",
      "interval": "1s",
      "timeout": "1s"
    },
    "connect": {
      "sidecar_service": {}
    }
  }
}

dashboard.json

{
  "service": {
    "name": "dashboard",
    "port": 9002,
    "connect": {
      "sidecar_service": {
        "proxy": {
      	  "upstreams": [{
      	    "destination_name": "counting",
      	    "local_bind_port": 5000
      	  }]
      	}
      }
    },
    "check": {
      "id": "dashboard-check",
      "http": "http://localhost:9002/health",
      "method": "GET",
      "interval": "1s",
      "timeout": "1s"
    }
  }
}
2.service register
consul services register counting.json
consul services register dashboard.json
consul catalog services
3.create intention
consul intention create dashboard counting
# Created: dashboard => counting(allow)
4.start services
PORT=9002 COUNTING_SERVICE_URL="http://localhost:5000" ./dashboard-service &
PORT=9003 ./counting-service &
5.start sidecar proxy
consul connect proxy -sidecar-for counting-1 > counting-proxy.log &
consul connect proxy -sidecar-for dashboard > dashboard-proxy.log &
# we can visit http://localhost:5000 for counting-1 now.
6.test proxy connections
consul intention create -deny -replace dashboard counting
consul intention create -allow -replace dashboard counting
7.clean up
consul intention delete dashboard counting
consul services deregister counting.json
consul services deregister dashboard.json
posted @ 2021-04-08 22:46  GhostAnt  阅读(162)  评论(0编辑  收藏  举报