-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfabfile.py
85 lines (67 loc) · 2.78 KB
/
fabfile.py
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
82
83
84
85
from fabric.api import *
from fabric.decorators import task
from fabric.tasks import Task
from fabric.contrib.project import upload_project
from paramiko import Transport
from socket import getdefaulttimeout, setdefaulttimeout
env.user = 'core'
class SkipIfOfflineTask(Task):
def __init__(self, func, *args, **kwargs):
super(SkipIfOfflineTask, self).__init__(*args, **kwargs)
self.func = func
def run(self, *args, **kwargs):
original_timeout = getdefaulttimeout()
setdefaulttimeout(3)
try:
Transport((env.host, int(env.port)))
return self.func(*args, **kwargs)
except:
print "Skipping offline host: " + env.host_string
setdefaulttimeout(original_timeout)
@task
def set_hosts(hostfile='allhosts'):
""" read and set up server list from file """
remote_servers = []
file = open(hostfile, 'r')
for line in file.readlines():
remote_servers.append(line.strip('\r\n'))
env.hosts = remote_servers
@task
def deploy_binaries():
""" deploy pre-built executables """
sudo('mkdir -p /opt/bin')
upload_project(local_dir='./bin', remote_dir='/opt', use_sudo=True)
put('./scripts/*', '/opt/bin', use_sudo=True, mirror_local_mode=True)
@task
def deploy_common_services():
""" deploy common service files """
put('./minion/*', '/etc/systemd/system', use_sudo=True)
sudo('source /etc/environment')
sudo('/opt/bin/substitute_private_ipv4.sh /etc/systemd/system/flannel.service')
sudo('/opt/bin/substitute_private_ipv4.sh /etc/systemd/system/kubelet.service')
sudo('systemctl enable /etc/systemd/system/flannel.service')
sudo('systemctl enable /etc/systemd/system/docker.service')
sudo('systemctl enable /etc/systemd/system/kube-proxy.service')
sudo('systemctl enable /etc/systemd/system/kubelet.service')
sudo('systemctl daemon-reload')
sudo('systemctl start flannel')
sudo('systemctl start docker')
sudo('systemctl start kube-proxy')
sudo('systemctl start kubelet')
@task(task_class=SkipIfOfflineTask)
def deploy_minion():
""" deploy minion node """
deploy_binaries()
deploy_common_services()
@task(task_class=SkipIfOfflineTask)
def deploy_master():
""" deploy master node """
put('./master/*', '/etc/systemd/system', use_sudo=True)
sudo('/opt/bin/substitute_machines.sh /etc/systemd/system/kube-controller-manager.service')
sudo('systemctl enable /etc/systemd/system/kube-apiserver.service')
sudo('systemctl enable /etc/systemd/system/kube-controller-manager.service')
sudo('systemctl enable /etc/systemd/system/kube-scheduler.service')
sudo('systemctl daemon-reload')
sudo('systemctl start kube-apiserver')
sudo('systemctl start kube-controller-manager')
sudo('systemctl start kube-scheduler')