Swarmkit install

来自linux中国网wiki
跳到导航 跳到搜索

install

info and pre

hostname  这一步其它可以不要 不像k8s那样一定要
192.168.88.20 manager 
192.168.88.21 worker1
192.168.88.22 worker2

hostnamectl --static set-hostname

ins docker

Docker入门

ins swarmkit

搭建Go开发环境

#不建议用这个方法 请见下面的go docker
#axel 就行哦   还是FQ吧
axel  https://dl.google.com/go/go1.8.6.linux-amd64.tar.gz

export GOROOT=/usr/local/go
export PATH=/root/go/src/github.com/docker/swarmkit/bin:/usr/local/go/bin:$PATH
export GOPATH=/root/go
export SWARM_SOCKET=/tmp/controller/swarm.sock

tar  -xvf go1.12.6.linux-amd64.tar.gz  -C /usr/local/

加入

echo 'export PATH=$PATH:/usr/local/go/bin' >>/etc/profile

export GOROOT=/usr/local/go/
 export PATH=/usr/local/go/bin/:$PATH
export GOPATH=/root



 mkdir src/github.com/docker/ -p
cp -a swarmkit_bak/* src/github.com/docker/


go docker 镜像

建议用这种办法更加方便 第一种我试过 更加麻烦

#clone src 
git clone   https://github.com/docker/swarmkit.git
#不用 cd 进去目录
docker pull golang:1.12
[root@centos7 ]# docker run --rm  -it \
 -v `pwd`/swarmkit:/go/src/github.com/docker/swarmkit \
 -w /go/src/github.com/docker/swarmkit/ golang:1.12 \
 make binaries

🐳 bin/swarmd
🐳 bin/swarmctl
🐳 bin/swarm-bench
🐳 bin/swarm-rafttool
🐳 bin/protoc-gen-gogoswarm
🐳 binaries

#这一步 所有要加入swarmkit集群的节点都要
[root@centos7 ~]# mv swarmkit/bin/swarmctl  swarmkit/bin/swarmd  /usr/local/bin/
[root@centos7 ~]# ls /usr/local/bin/
swarmctl  swarmd

Initialize the node

Initialize the first node

swarmd --state-dir  /tmp/node-mgmt-01  --listen-control-api /tmp/mgmt-01.sock --hostname mgmt-01 >/tmp/mmt-01.log 2>&1 &

swarmctl 查看集群信息

加入到环境变量吧
export SWARM_SOCKET=/tmp/mgmt-01.sock
export SWARM_SOCKET=/tmp/mgmte-01.sock #有一次多个e


[root@manager ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 0e:68:40:d2:cd:4e brd ff:ff:ff:ff:ff:ff
    inet 192.168.88.20/24 brd 192.168.88.255 scope global eth0


[root@manager ~]# swarmctl cluster inspect default 
ID          : ufcwpkw98g7wnxcjn7e3r79no
Name        : default
Orchestration settings:
  Task history entries: 5
Dispatcher settings:
  Dispatcher heartbeat period: 5s
Certificate Authority settings:
  Certificate Validity Duration: 2160h0m0s
  Join Tokens:
    Worker: SWMTKN-1-270tl6zrmapolhgc6wa88lz523apjt0zlvujqmajve0n3jaoma-4fgi6jba3bym7wsaogb9mrr7g
    Manager: SWMTKN-1-270tl6zrmapolhgc6wa88lz523apjt0zlvujqmajve0n3jaoma-1hiykln32o7ssmjr4k6vbi7ax

#--join-add 后为manager ip 
swarmd -d /tmp/node-2 --hostname node-2 --join-addr 192.168.88.20:4242 --join-token SWMTKN-1-270tl6zrmapolhgc6wa88lz523apjt0zlvujqmajve0n3jaoma-4fgi6jba3bym7wsaogb9mrr7g >/tmp/node-02.log 2>&1 &
swarmd -d /tmp/node-3 --hostname node-3 --join-addr 192.168.88.20:4242 --join-token SWMTKN-1-270tl6zrmapolhgc6wa88lz523apjt0zlvujqmajve0n3jaoma-4fgi6jba3bym7wsaogb9mrr7g >/tmp/node-03.log 2>&1 &

[root@manager ~]# swarmctl  node ls 
ID                         Name     Membership  Status  Availability  Manager Status
--                         ----     ----------  ------  ------------  --------------
c1k7uwl4st3ninfsfe0gp9bau  mgmt-01  ACCEPTED    READY   ACTIVE        REACHABLE *
x1ty0szhvhzvyeljj9yhpk3lt  node-2   ACCEPTED    READY   ACTIVE        
xm0moxdqlobo23gger0wxfw43  node-3   ACCEPTED    READY   ACTIVE  

看到有三台机器了 
 
停机 维护  swarmctl  node drain  节点id 
恢复  swarmctl  node activate   节点id 


usage

集群上运行服务



[root@manager ~]# swarmctl  service create --name nginx --image nginx:1.16-alpine
nmjywh2kajsv5kdiwa5v4ohmw
[root@manager ~]# swarmctl  service ls 
ID                         Name   Image              Replicas
--                         ----   -----              --------
nmjywh2kajsv5kdiwa5v4ohmw  nginx  nginx:1.16-alpine  0/1

# 添加容器 副本个数 
[root@manager ~]# swarmctl  service update nginx --replicas 3
nmjywh2kajsv5kdiwa5v4ohmw


[root@manager ~]# swarmctl  service ls 
ID                         Name   Image              Replicas
--                         ----   -----              --------
nmjywh2kajsv5kdiwa5v4ohmw  nginx  nginx:1.16-alpine  3/3



trouble

得用go1.12(docker) 不然编译有问题 还是用docker方便 安装文件的老是有问题呢 
2019年 06月 13日 星期四 10:13:46 CST

tatus: Downloaded newer image for golang:1.8
WARNING: IPv4 forwarding is disabled. Networking will not work.

解决办法:
# vi /etc/sysctl.conf
或者
# vi /usr/lib/sysctl.d/00-system.conf
添加如下代码:
    net.ipv4.ip_forward=1

 重启network服务
# systemctl restart network

查看是否修改成功
# sysctl net.ipv4.ip_forward

如果返回为“net.ipv4.ip_forward = 1”则表示成功了

这时,重启容器即可。

https://yq.aliyun.com/articles/233818

make: *** No rule to make target 'binaries'.  Stop.
不要cd 进去swarmkit 目录

docker go 环境老报错
# github.com/docker/swarmkit/manager/allocator/cnmallocator
manager/allocator/cnmallocator/drivers_ipam.go:18: undefined: strings.Builder
direct.mk:94: recipe for target 'bin/swarmd' failed
make: *** [bin/swarmd] Error 2

see also

官方教程一定要看 很多在里面来的 https://github.com/docker/swarmkit

SwarmKit 知多少——来自源码世界的深入解读


SwarmKit初体验(redis service) 比传统集群工具更方便


Docker发布SwarmKit,一线工程师的体验总结

swarmkit

Hello Docker Swarm with SwarmKit

Docker SwarmKit 学习笔记 - 1 搭建实验环境

Docker swarmkit学习笔记