使用swarmpit来监控你的swarm集群

简介

大家都用过portainer吧,但是个人感觉它的界面挺丑,而且容器的监控数据不能长久的保存,今天推荐一款同样是管理swarm集群的软件 swarmpit

官网

https://swarmpit.io/

从官网就可以看出,真的挺好看的一个dashboard,关键是移动端友好,如果你周围没有电脑,那么使用swarmpit你就可以在手机上轻松管理你的swarm集群了

安装

安装方式有很多,你可以使用官网推荐的一键安装方式

1
2
3
4
docker run -it --rm \
  --name swarmpit-installer \
  --volume /var/run/docker.sock:/var/run/docker.sock \
swarmpit/install:1.9

当然,因为我集群的缘故,所以我是直接修改yaml的

git clone https://github.com/swarmpit/swarmpit -b master

原来的yaml文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
version: '3.3'

services:
  app:
    image: swarmpit/swarmpit:latest
    environment:
      - SWARMPIT_DB=http://db:5984
      - SWARMPIT_INFLUXDB=http://influxdb:8086
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - 888:8080
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080"]
      interval: 60s
      timeout: 10s
      retries: 3
    networks:
      - net
    deploy:
      resources:
        limits:
          memory: 1024M
        reservations:
          memory: 512M
      placement:
        constraints:
          - node.role == manager
  db:
    image: treehouses/couchdb:2.3.0
    volumes:
      - db-data:/opt/couchdb/data
    networks:
      - net
    deploy:
      resources:
        limits:
          memory: 256M
        reservations:
          memory: 128M

  influxdb:
    image: influxdb:1.7
    volumes:
      - influx-data:/var/lib/influxdb
    networks:
      - net
    deploy:
      resources:
        limits:
          memory: 256M
        reservations:
          memory: 128M

  agent:
    image: swarmpit/agent:latest
    environment:
      - DOCKER_API_VERSION=1.35
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - net
    deploy:
      mode: global
      labels:
        swarmpit.agent: 'true'
      resources:
        limits:
          memory: 64M
        reservations:
          memory: 32M

networks:
  net:
    driver: overlay

volumes:
  db-data:
    driver: local
  influx-data:
    driver: local

说一下上面的相关组件

  • app 就是swarmpit
  • agent 和portainer一样,swarmppit在每个节点上都会部署一个agent收集信息
  • db 使用的是CouchDB用来存储应用的数据
  • influxdb 存储的是集群的信息

因为我是使用traefik做网关的,所以添加了traefik相关的label在app组件中

1
2
3
        - traefik.http.routers.swarmpit-swarmpit-http.rule=Host(``)
        - traefik.http.routers.swarmpit-swarmpit-http.entrypoints=web
        - traefik.http.services.swarmpit-swarmpit.loadbalancer.server.port=8080

同时修改了volume和network

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
networks:
  app-net:
    external: true

volumes:
  db-data:
    driver_opts:
      type: "nfs"
      o: "addr=10.10.100.244,rw"
      device: ":/nas/docker-volume/swarmpit/db-data"

  influx-data:
    driver_opts:
      type: "nfs"
      o: "addr=10.10.100.244,rw"
      device: ":/nas/docker-volume/swarmpit/influx-data"

最后就是直接部署

docker stack deploy -c swarmpit/docker-compose.yml swarmpit

欢迎关注我的博客 www.bboy.app

Have Fun