fleet is deprecated by coreos, is replaced by kubernetes.
fleet, a simple distributed service manager.
fleet requires etcd
host:
## add vagrant ssh keys $ eval $(ssh-agent) $ valgrant ssh-config Host core-01 HostName 127.0.0.1 User core Port 2200 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /root/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL ForwardAgent yes Host core-02 HostName 127.0.0.1 User core Port 2201 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /root/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL ForwardAgent yes Host core-03 HostName 127.0.0.1 User core Port 2202 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /root/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL ForwardAgent yes ## we can add the keys by 'vagrant ssh-config | sed -n "s/IdentityFile//gp"|xargs ssh-ad' $ ssh-add /root/.vagrant.d/insecure_private_key $ ssh-add -l ## ssh forward with -A, this is same as 'ssh -p 2202 -i /root/.vagrant.d/insecure_private_key core@127.0.0.1' $ vagrant ssh core-03 -- -A
Run a busybox docker container and echo hello world in the container. When we start the unit, it will be running on one of the machines in the cluster.
core@core-03 ~ $ fleetctl NAME: fleetctl - fleetctl is a command-line interface to fleet, the cluster-wide CoreOS init system. USAGE: fleetctl [global options] <command> [command options] [arguments...] VERSION: 0.11.8 COMMANDS: cat Output the contents of a submitted unit destroy Destroy one or more units in the cluster fd-forward Proxy stdin and stdout to a unix domain socket help Show a list of commands or help for one command journal Print the journal of a unit in the cluster to stdout list-machines Enumerate the current hosts in the cluster list-unit-files List the units that exist in the cluster. list-units List the current state of units in the cluster load Schedule one or more units in the cluster, first submitting them if necessary. ssh Open interactive shell on a machine in the cluster start Instruct systemd to start one or more units in the cluster, first submitting and loading if necessary. status Output the status of one or more units in the cluster stop Instruct systemd to stop one or more units in the cluster. submit Upload one or more units to the cluster without starting them unload Unschedule one or more units in the cluster. verify DEPRECATED - No longer works version Print the version and exit GLOBAL OPTIONS: --ca-file= Location of TLS CA file used to secure communication with the fleet API or etcd --cert-file= Location of TLS cert file used to secure communication with the fleet API or etcd --debug=false Print out more debug information to stderr --driver=API Adapter used to execute fleetctl commands. Options include "API" and "etcd". --endpoint=unix:///var/run/fleet.sock Location of the fleet API if --driver=API. Alternatively, if --driver=etcd, location of the etcd API. --etcd-key-prefix=/_coreos.com/fleet/ Keyspace for fleet data in etcd (development use only!) -h=false Print usage information and exit --help=false Print usage information and exit --key-file= Location of TLS key file used to secure communication with the fleet API or etcd --known-hosts-file=~/.fleetctl/known_hosts File used to store remote machine fingerprints. Ignored if strict host key checking is disabled. --request-timeout=3 Amount of time in seconds to allow a single request before considering it failed. --ssh-timeout=10 Amount of time in seconds to allow for SSH connection initialization before failing. --ssh-username=core Username to use when connecting to CoreOS instance. --strict-host-key-checking=true Verify host keys presented by remote machines before initiating SSH connections. --tunnel= Establish an SSH tunnel through the provided address for communication with fleet and etcd. --version=false Print the version and exit core@core-03 ~ $ fleetctl list-machines MACHINE IP METADATA 0d9ba9f8... 172.17.8.102 - 50018d3c... 172.17.8.103 - 68d60645... 172.17.8.101 - core@core-03 ~ $ cat hello.service [Unit] Description=My Service After=docker.service [Service] TimeoutStartSec=0 ExecStartPre=-/usr/bin/docker kill hello ExecStartPre=-/usr/bin/docker rm hello ExecStartPre=/usr/bin/docker pull busybox ExecStart=/usr/bin/docker run --name hello busybox /bin/sh -c "trap 'exit 0' INT TERM; while true; do echo Hello World; sleep 1; done" ExecStop=/usr/bin/docker stop hello core@core-03 ~ $ fleetctl load hello.service Unit hello.service inactive Unit hello.service loaded on 0d9ba9f8.../172.17.8.102 core@core-03 ~ $ core@core-03 ~ $ core@core-03 ~ $ fleetctl cat hello.service [Unit] Description=My Service After=docker.service [Service] TimeoutStartSec=0 ExecStartPre=-/usr/bin/docker kill hello ExecStartPre=-/usr/bin/docker rm hello ExecStartPre=/usr/bin/docker pull busybox ExecStart=/usr/bin/docker run --name hello busybox /bin/sh -c "trap 'exit 0' INT TERM; while true; do echo Hello World; sleep 1; done" ExecStop=/usr/bin/docker stop hello core@core-03 ~ $ fleetctl start hello.service Unit hello.service launched on 0d9ba9f8.../172.17.8.102 core@core-03 ~ $ core@core-03 ~ $ fleetctl status hello.service ● hello.service - My Service Loaded: loaded (/run/fleet/units/hello.service; linked-runtime; vendor preset: disabled) Active: active (running) since Mon 2017-02-13 17:56:47 UTC; 6s ago Process: 6528 ExecStartPre=/usr/bin/docker pull busybox (code=exited, status=0/SUCCESS) Process: 6521 ExecStartPre=/usr/bin/docker rm hello (code=exited, status=0/SUCCESS) Process: 6505 ExecStartPre=/usr/bin/docker kill hello (code=exited, status=1/FAILURE) Main PID: 6535 (docker) Tasks: 7 Memory: 6.3M CPU: 53ms CGroup: /system.slice/hello.service └─6535 /usr/bin/docker run --name hello busybox /bin/sh -c trap 'exit 0' INT TERM; while true; do echo Hello World; sleep 1; done Feb 13 17:56:47 core-02 docker[6528]: latest: Pulling from library/busybox Feb 13 17:56:47 core-02 docker[6528]: Digest: sha256:817a12c32a39bbe394944ba49de563e085f1d3c5266eb8e9723256bc4448680e Feb 13 17:56:47 core-02 docker[6528]: Status: Image is up to date for busybox:latest Feb 13 17:56:47 core-02 systemd[1]: Started My Service. Feb 13 17:56:47 core-02 docker[6535]: Hello World Feb 13 17:56:48 core-02 docker[6535]: Hello World Feb 13 17:56:49 core-02 docker[6535]: Hello World Feb 13 17:56:50 core-02 docker[6535]: Hello World Feb 13 17:56:51 core-02 docker[6535]: Hello World Feb 13 17:56:52 core-02 docker[6535]: Hello World
Standard units are long-running processes that are scheduled onto a single machine. If that machine goes offline, the unit will be migrated onto a new machine and started.
Global units run on all machines in the cluster. A regular unit with a new
[X-Fleet] Global=true
When we start this unit, it will be running on all machines in cluster.
When we start the unit services, they will be running on different machines in the cluster. Create unit file with
[X-Fleet] Conflicts=apache@*.service
Start multiple units
$ fleetctl start apache@1.service $ fleetctl start apache@2.service
The two services won't be run on same machine. When a machine fails to heartbeat back to the fleet leader, all units running on that machine are marked for rescheduling, units are started on new machine. Units that can't be rescheduled will remain stopped until the failed machine recovers.