-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-k8s.py
68 lines (52 loc) · 1.74 KB
/
deploy-k8s.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
#!/bin/env python
# -*- encoding: utf-8 -*-
import os
from Kube.init import KubeInit
from Util.args import Args
from Util.log import Logger as logger
from Util.conf import Conf as conf
from Util import util
BASE_DIR = os.path.dirname((os.path.abspath(__file__)))
CONF_PATH = os.path.join(BASE_DIR, "config.yaml")
def main(params):
if params.configFile:
logger.get().debug("加载配置文件{}".format(params.configFile))
conf.add_conf(params.configFile)
conf.init()
else:
logger.get().debug("加载配置文件{}".format(CONF_PATH))
conf.add_conf(CONF_PATH)
conf.init()
conf.set("base_dir", BASE_DIR)
conf.set("all_ip", conf.master['servers'] + conf.node['servers'])
kube = KubeInit(conf)
if params.initAnsible:
passwd = input("请输入ssh密码:")
util.CreateNoPasswdLogin(conf.all_ip, conf.ssh_user, passwd, conf.ssh_port)
util.CreateAnsibleInventory(conf)
util.UpdateHosts(conf)
if params.initEnv:
if not os.path.isfile("/etc/ansible/hosts"):
logger.get().error("ansibe host文件不存在")
exit(1)
kube.init_docker_env()
if params.initMaster:
kube.init_master_node()
kube.cp_config()
kube.check_cluster_status()
kube.init_network_plugin()
if params.initOthers:
kube.init_other_master_node()
kube.check_cluster_status()
if params.Join:
kube.join_cluster()
if params.Reset:
kube.reset(conf.all_ip)
if __name__ == "__main__":
if not os.getenv("LOG_LEVEL"):
logger.start("INFO")
else:
logger.start(os.getenv("LOG_LEVEL"))
params, unparsed = Args.get().parse_known_args()
# print(args)
main(params)