Fleet(集群管理器)

工作原理

fleet 是通过systemd来控制你的集群的,控制的任务被称之为unit(单元),控制的命令是fleetctl

unit运行方式

unit的运行方式有两种:

  • standard
  • global

standard:unit在一台机器上运行。如果这台机器下线,它将被迁移到一台新机器开始运行。

global:unit将在所有计算机上运行。

查看unit

这有两个命令来查看集群中的单元:

  • list-unit-files
  • list-units

list-unit-files将会列出fleet知道的unit,和他们是否为global。

$ fleetctl list-unit-files
UNIT                   HASH     DSTATE    STATE     TMACHINE
global-unit.service    8ff68b9  launched  launched  3 of 3
standard-unit.service  7710e8a  launched  launched  148a18ff.../10.10.1.1

list-units将会列出在集群中运行的unit的状态。

$ fleetctl list-units
UNIT                    MACHINE                  ACTIVE    SUB
global-unit.service     148a18ff.../10.10.1.1    active    running
global-unit.service     491586a6.../10.10.1.2    active    running
global-unit.service     c9de9451.../10.10.1.3    active    running
standard-unit.service   148a18ff.../10.10.1.1    active    running

查看集群中的机器

fleetctl list-machines命令用于列出集群中的机器

$ fleetctl list-machines
MACHINE                                 IP          METADATA
148a18ff-6e95-4cd8-92da-c9de9bb90d5a    10.10.1.1   -
491586a6-508f-4583-a71d-bfc4d146e996    10.10.1.2   -
c9de9451-6a6f-1d80-b7e6-46e996bfc4d1    10.10.1.3   -

在集群中运行容器

运行单个容器是很容易的。所有你需要做的是提供一个普通的没有[install]部分单元文件。让我们来运行systemd入门指南上一个示例。首先保存这些内容myapp.service的CoreOS机器上:

[Unit]
Description=MyApp
After=docker.service
Requires=docker.service

[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill busybox1
ExecStartPre=-/usr/bin/docker rm busybox1
ExecStartPre=/usr/bin/docker pull busybox
ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
ExecStop=/usr/bin/docker stop busybox1

如果你曾经运行过docker命令,请注意不要使用detached mode (-d),detached mode不会以unit的子线程的方式运行容器,这将会造成unit运行几秒后退出。

用start命令来让它在集群上启动

$ fleetctl start myapp.service

现在它应该已经在服务器上运行了

$ fleetctl list-units
UNIT              MACHINE                 ACTIVE    SUB
myapp.service     c9de9451.../10.10.1.3   active    running
原文地址:https://www.cnblogs.com/wanghongxu/p/4992410.html