项目作者: nicgrobler

项目描述 :
高级语言: Go
项目地址: git://github.com/nicgrobler/pinger.git
创建时间: 2020-02-10T12:15:15Z
项目社区:https://github.com/nicgrobler/pinger

开源协议:MIT License

下载


Pinger

Used to deploy a server/client that polls a list of endpoints, and also accepts polls from each of them. This leads to a “mesh” topology whereby each
relies on a functioning overlay network, and its DNS service. All connections are logged to stderr as well as (optional) Graylog. This makes it
trivial to spot when containers within an overlay network lose their ability to talk to each other.

There are lots of issues which have plagued Docker Swarm overlay networks, especially when using encryption - and this simply helps to pin-point
where the issue lies. This issue is very hard to diagnose by looking at application logs from other containers. The diagram below shows how docker dns works (from: https://stackoverflow.com/questions/44724497/what-is-overlay-network-and-how-does-dns-resolution-work):

alt text

This code works by deploying a “pinger” service onto each node in the swarm, and each of these will discover the others of its kind (same stack) and start to attempt to:

  • resolve the partner(s) address (this verifies dns)
  • connect to each partner’s http listener

once done, it will send a status log entry for each - showing either an error, or an ok. This means that within your logging solution (or just the service’s logs) it is easy to see whether the underlying overlay network is experiencing issues. These issues include things such as:

  • dns hangs
  • connection attempts to known addresses fail

setup

The only requirements are that you modify the “.env” and “docker-compose.yaml” files before deploying the stack into your swarm. Just follow the comments within the respective files.

syntax

docker stack deploy —compose-file docker-compose.yaml testpinger

gives:

  1. <admin>$ docker stack deploy --compose-file docker-compose.yaml testpinger
  2. Creating network testpinger_my-test-bridge
  3. Creating service testpinger_pinger

view the service:

  1. <admin>$docker service ps testpinger_pinger
  2. ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
  3. lohmi5w7ypkf testpinger_pinger.1 nicgrobler/pinger:v1.0.0 docker-desktop Running Running 5 minutes ago
  4. cppf5llddb7j testpinger_pinger.2 nicgrobler/pinger:v1.0.0 docker-desktop Running Running 5 minutes ago
  5. i2j6tddgnke8 testpinger_pinger.3 nicgrobler/pinger:v1.0.0 docker-desktop Running Running 5 minutes ago

view logs:

  1. <admin>$docker service logs -f testpinger_pinger
  2. testpinger_pinger.1.lohmi5w7ypkf@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="logging to stderr only - no graylog url supplied"
  3. testpinger_pinger.1.lohmi5w7ypkf@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="http listener on: 0.0.0.0:8111"
  4. testpinger_pinger.1.lohmi5w7ypkf@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="starting clients..."
  5. testpinger_pinger.3.i2j6tddgnke8@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="starting clients..."
  6. testpinger_pinger.3.i2j6tddgnke8@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="logging to stderr only - no graylog url supplied"
  7. testpinger_pinger.3.i2j6tddgnke8@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="http listener on: 0.0.0.0:8111"
  8. testpinger_pinger.2.cppf5llddb7j@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="starting clients..."
  9. testpinger_pinger.2.cppf5llddb7j@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="http listener on: 0.0.0.0:8111"
  10. testpinger_pinger.2.cppf5llddb7j@docker-desktop | time="2020-02-27T15:58:49Z" level=info msg="logging to stderr only - no graylog url supplied"
  11. testpinger_pinger.3.i2j6tddgnke8@docker-desktop | time="2020-02-27T15:58:59Z" level=info msg="ok:http://testpinger_pinger.2.cppf5llddb7j7asz2up0679li.testpinger_my-test-bridge:8111/ping - returned ok"
  12. testpinger_pinger.2.cppf5llddb7j@docker-desktop | time="2020-02-27T15:58:59Z" level=info msg="ok:http://testpinger_pinger.1.lohmi5w7ypkfajvx1upsgk2o8.testpinger_my-test-bridge:8111/ping - returned ok"
  13. testpinger_pinger.2.cppf5llddb7j@docker-desktop | time="2020-02-27T15:58:59Z" level=info msg="ok:http://testpinger_pinger.3.i2j6tddgnke8ag1mhbchwyvtq.testpinger_my-test-bridge:8111/ping - returned ok"
  14. testpinger_pinger.1.lohmi5w7ypkf@docker-desktop | time="2020-02-27T15:58:59Z" level=info msg="ok:http://testpinger_pinger.3.i2j6tddgnke8ag1mhbchwyvtq.testpinger_my-test-bridge:8111/ping - returned ok"
  15. testpinger_pinger.1.lohmi5w7ypkf@docker-desktop | time="2020-02-27T15:58:59Z" level=info msg="ok:http://testpinger_pinger.2.cppf5llddb7j7asz2up0679li.testpinger_my-test-bridge:8111/ping - returned ok"
  16. testpinger_pinger.3.i2j6tddgnke8@docker-desktop | time="2020-02-27T15:59:09Z" level=info msg="ok:http://testpinger_pinger.1.lohmi5w7ypkfajvx1upsgk2o8.testpinger_my-test-bridge:8111/ping - returned ok"
  17. testpinger_pinger.3.i2j6tddgnke8@docker-desktop | time="2020-02-27T15:59:09Z" level=info msg="ok:http://testpinger_pinger.2.cppf5llddb7j7asz2up0679li.testpinger_my-test-bridge:8111/ping - returned ok"
  18. testpinger_pinger.2.cppf5llddb7j@docker-desktop | time="2020-02-27T15:59:09Z" level=info msg="ok:http://testpinger_pinger.3.i2j6tddgnke8ag1mhbchwyvtq.testpinger_my-test-bridge:8111/ping - returned ok"
  19. testpinger_pinger.2.cppf5llddb7j@docker-desktop | time="2020-02-27T15:59:09Z" level=info msg="ok:http://testpinger_pinger.1.lohmi5w7ypkfajvx1upsgk2o8.testpinger_my-test-bridge:8111/ping - returned ok"
  20. testpinger_pinger.1.lohmi5w7ypkf@docker-desktop | time="2020-02-27T15:59:09Z" level=info msg="ok:http://testpinger_pinger.3.i2j6tddgnke8ag1mhbchwyvtq.testpinger_my-test-bridge:8111/ping - returned ok"
  21. testpinger_pinger.1.lohmi5w7ypkf@docker-desktop | time="2020-02-27T15:59:09Z" level=info msg="ok:http://testpinger_pinger.2.cppf5llddb7j7asz2up0679li.testpinger_my-test-bridge:8111/ping - returned ok"
  22. <admin>$

finally, to stop:

  1. <admin>$docker stack rm testpinger
  2. Removing service testpinger_pinger
  3. Removing network testpinger_my-test-bridge

Advanced mode

The image (dockerhub) with versions > 3.0.0 contain an extra binary: composer
This talks directly to the docker api, and creates the stack automatically - given the parameters in its own .env file, which is passed into the containers, and supercedes the one in this repo (it is a superset).

At runtime, the binary will create a stack-per-network - for each and every network of type “overlay”, with the exception of the default “ingress” network. Each non-manager node (by default) will run a container-per-network, all of which talk to partnets in the same overlay network as its running in.

First step is to extract the pre-built binary from within the container (Linux x64 build):

  1. $ docker run nicgrobler/pinger:latest &
  2. $ docker ps
  3. CONTAINER ID IMAGE COMMAND CREATED STATUS
  4. e7f501f3b744 nicgrobler/pinger:latest "/go/bin/pinger" 11 seconds ago Up 11 seconds
  5. $ docker cp e7f501f3b744:/go/bin/composer composer

The following shows how to run it:

  1. $ ./composer
  2. created server: test_stack_bubbles_pinger
  3. created server: test_stack_bubbles_test_overlay_pinger

Then to verify:

  1. $ docker stack ls
  2. NAME SERVICES ORCHESTRATOR
  3. test_stack_bubbles 1 Swarm
  4. test_stack_bubbles_test_overlay 1 Swarm

From this stage, these function as any stacks deployed using “docker stack deploy…”