Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some bugs and add fabric #566

Merged
merged 38 commits into from
Aug 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
297bc2a
add
gongweibao Jul 27, 2017
dc50be2
fix2
gongweibao Jul 28, 2017
09f2a14
fix centos version
gongweibao Jul 28, 2017
25d1042
add some colors and fix
gongweibao Jul 28, 2017
61382ac
fix resgistry error
gongweibao Jul 28, 2017
8a8b6b0
fix rm bugs
gongweibao Jul 28, 2017
0fac779
fix
gongweibao Jul 28, 2017
76b8e6f
fix by comments
gongweibao Jul 29, 2017
da21864
add fabric
gongweibao Jul 29, 2017
256b372
add fabric
gongweibao Jul 29, 2017
9724b1b
fix
gongweibao Jul 29, 2017
084a4b2
add pxe option
gongweibao Jul 29, 2017
880d6d8
add gpu
gongweibao Jul 31, 2017
6fdb2a0
add reboot
gongweibao Jul 31, 2017
18cf173
add mac_host
gongweibao Jul 31, 2017
2343476
fix
gongweibao Jul 31, 2017
e3e78a8
fix
gongweibao Jul 31, 2017
d134f6b
fix mac
gongweibao Jul 31, 2017
5e30fb6
add k8s install
gongweibao Aug 1, 2017
80282ea
fix
gongweibao Aug 1, 2017
4675261
add gpu
gongweibao Aug 1, 2017
b0830b4
add log.sh
gongweibao Aug 2, 2017
2e58e05
fix logs
gongweibao Aug 2, 2017
09810ec
add log ok
gongweibao Aug 2, 2017
449e439
set host ok
gongweibao Aug 2, 2017
cef4f47
rm not need
gongweibao Aug 2, 2017
2828e87
set startpxe
gongweibao Aug 3, 2017
042dfd3
modify etcd path ok
gongweibao Aug 3, 2017
b92438b
change docker path ok
gongweibao Aug 3, 2017
37d0027
etcd path ok
gongweibao Aug 3, 2017
a969494
rm not need
gongweibao Aug 3, 2017
a6e2b6b
add reame
gongweibao Aug 3, 2017
e55ec05
fix etcd path
gongweibao Aug 3, 2017
dd81911
Merge branch 'fix' of https://github.com/gongweibao/sextant into fix
gongweibao Aug 3, 2017
038857a
fix kubelet start bug
gongweibao Aug 3, 2017
6d15c86
fix by comments
gongweibao Aug 5, 2017
15b275c
fix readme
gongweibao Aug 5, 2017
86641e7
Merge branch 'fix' of https://github.com/gongweibao/sextant into fix
gongweibao Aug 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bsroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
# bootstrap server when the bootstrapper server is "offline". Or, you can run
# bsroot.sh directly on the bootstrap server.

alias cp='cp'

SEXTANT_ROOT=${PWD}
source $SEXTANT_ROOT/scripts/log.sh
source $SEXTANT_ROOT/scripts/common.sh

check_prerequisites
check_cluster_desc_file



echo "Install OS: ${cluster_desc_os_name}"
if [[ $cluster_desc_os_name == "CentOS" ]]; then
source $SEXTANT_DIR/scripts/centos.sh
Expand Down Expand Up @@ -63,3 +64,4 @@ build_bootstrapper_image
generate_tls_assets
prepare_setup_kubectl
generate_addons_config
log info "bsroot done!"
4 changes: 1 addition & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM alpine
#FROM golang:alpine
FROM distribution/registry

# Install required software packages.
RUN set -ex && \
Expand All @@ -9,7 +8,6 @@ apk add dnsmasq openssl
# Upload Sextant Go programs and retrieve dependencies.
RUN mkdir -p /go/bin
COPY cloud-config-server /go/bin
COPY registry /go/bin

# NOTICE: change install.sh HTTP server ip:port when running entrypoint.sh
COPY entrypoint.sh /
Expand Down
15 changes: 11 additions & 4 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#!/bin/sh

# start dnsmasq
mkdir -p /bsroot/dnsmasq
dnsmasq --log-facility=- --conf-file=/bsroot/config/dnsmasq.conf \
--dhcp-leasefile=/bsroot/dnsmasq/dnsmasq.leases
if [[ $# != 1 ]]; then
echo "need to set start_pxe"
exit 1
fi

if [[ $1 == " y" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“ y” 引号里有一空格?

Copy link
Contributor Author

@gongweibao gongweibao Aug 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的。脚本解析yaml文件的时候有一个空格。

# start dnsmasq
mkdir -p /bsroot/dnsmasq
dnsmasq --log-facility=- --conf-file=/bsroot/config/dnsmasq.conf \
--dhcp-leasefile=/bsroot/dnsmasq/dnsmasq.leases
fi

# start cloud-config-server
/go/bin/cloud-config-server -addr ":80" \
Expand Down
50 changes: 50 additions & 0 deletions fabric/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 前言
Sextant设计之初考虑的是在裸机集群中一键式的解决方案。实际使用的过程中,企业内部的集群一般都有了自己的初始化安装环境,如部署了DHCP服务器,有自己的DNS,机器也有自己的hostname,机器之间通过hostname相互也能ping同。这种情况下,同时两个DHCP服务器无疑是有冲突的,需要对Sextant做一些改动以便适应这种的环境。

我们可以把Sextant PXE服务部分设置为可选项,保留资源cache服务部分。由于post_script不能通过kick start的方式启动,所以引入fabric作为集群管理者,方便安装、配置、检查、启动、关闭软件。我们写的如下的步骤,都是在考虑了企业一般的现实情况来做的。

首先,`copy host.template.yaml host.yaml`,然后修改之。

***注意:***
- 符合要求的步骤可以略过
- 需要已经安装centos7的基础操作系统

# 步骤一:机器之间可以访问
我们需要机器都可以通过hostname来相互之间访问。如果企业的网络不支持,需要我们把静态解析写入各个节点`/etc/hosts`中(已经支持的可以忽略)。

```
# get mac_ip_host
fab -f get_mac_ip_host.py get_mac_addr

# display all before set them
fab -f set_hosts.py display

# set hosts
fab -f set_hosts.py set_mac_hosts
```

# 步骤二:生成bsroot
注意设置cluster-desc.yaml中的`start_pxe: n`。


# 步骤三:升级kernel
```
fab -f upgrade_kernel.py prepare
fab -f upgrade_kernel.py upgrade
fab -f upgrade_kernel.py reboot
```

# 步骤四:安装gpu driver
```
fab -f gpu_driver.py prepare
fab -f gpu_driver.py install
fab -f gpu_driver.py check
```

# 步骤五:安装k8s需要的软件
```
fab -f k8s.py prepare
fab -f k8s.py install
```

# TODO: 启动etcd flannel kubelet等
33 changes: 33 additions & 0 deletions fabric/get_mac_ip_host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import fabric.operations as op
import yaml
import sys
import re

def get_mac_addr():
src_path = "/etc/mac_ip_host"

cmd = """ default_iface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route | uniq) &&
default_iface=`echo ${default_iface} | awk '{ print $1 }'` &&
mac_addr=`ip addr show dev ${default_iface} | awk '$1 ~ /^link\// { print $2 }'` &&
echo $mac_addr %s $HOSTNAME > %s
""" % (env.host_string, src_path)
run(cmd)

dst_path = env.host_string + "/mac_ip_host"
get(src_path, dst_path)

with open("hosts.yaml", 'r') as stream:
try:
y = yaml.load(stream)
env.hosts = y["hosts"]
env.user = y["user"]
env.password = y["password"]
except yaml.YAMLError as exc:
print(exc)
abort("load yaml error")



46 changes: 46 additions & 0 deletions fabric/gpu_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import fabric.operations as op
import yaml
import sys

driver_version=""
http_gpu_dir=""
boot_strapper=""

def prepare():
cmd = """setenforce 0
&& sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
&& cat /etc/selinux/config | grep SELINUX"""
run(cmd)

def install():
# Imporant: gpu must be installed after the kernel has been installed
run("wget -P /root %s/build_centos_gpu_drivers.sh" % http_gpu_dir)
cmd = "bash -x /root/build_centos_gpu_drivers.sh %s %s" % (driver_version, http_gpu_dir)
run(cmd)

#@parallel
def check():
cmd="ret=`nvidia-smi | grep \"Driver Version\" | grep %s` ; if [[ -z $ret ]]; then exit 1; fi " % driver_version
result = run(cmd)
if result.failed:
abort(env.host_string + ": check failed")

with open("hosts.yaml", 'r') as stream:
try:
y = yaml.load(stream)
env.hosts = y["hosts"]
env.user = y["user"]
env.password = y["password"]

boot_strapper = y["boot_strapper"]
driver_version = y["gpu"]["driver_version"]

http_gpu_dir="http://%s/static/CentOS7/gpu_drivers" % boot_strapper
except yaml.YAMLError as exc:
print(exc)
abort("load yaml error")


26 changes: 26 additions & 0 deletions fabric/hosts.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
user: "root"
password: "passwd"
hosts:
- 192.168.16.23
- 192.168.16.24
- 192.168.16.25
- 192.168.16.26
- 192.168.16.27
- 192.168.16.28
- 192.168.16.29
kernel:
old_version: "3.10.0-327.el7.x86_64"
new_version: "4.4.79-1.el7.elrepo.x86_64"
gpu:
driver_verion: 375.26
boot_strapper: "192.168.16.23"

# host, mac, all
set_type: host

# change hostname to mac?
set_mac_hostname: n

# set "" if not need to change default path
docker_data_path: "/home/var/lib/docker"
etcd_data_path: "/home/var/lib/etcd"
63 changes: 63 additions & 0 deletions fabric/k8s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import fabric.operations as op
import yaml
import sys
import re


boot_strapper=""
set_mac_hostname=""
docker_data_path=""
etcd_data_path=""

def prepare():
run("systemctl stop firewalld && systemctl disable firewalld")
run("wget -O /etc/yum.repos.d/Cloud-init.repo http://%s/static/CentOS7/repo/cloud-init.repo" % boot_strapper)
run("wget -O /root/post-process.sh http://%s/centos/post-script/00-00-00-00-00-00" % boot_strapper)
run("wget -O /root http://%s/static/CentOS7/post_cloudinit_provision.sh" % boot_strapper)

def install():
run("yum --enablerepo=Cloud-init install -y cloud-init docker-engine etcd flannel")
run("""cd /root
&& export set_mac_hostname=%s
&& export docker_data_path=%s
&& bash post-process.sh""" % (set_mac_hostname, docker_data_path))

if len(etcd_data_path) > 0 :
run("id -u etcd &>/dev/null || useradd etcd")
run("mkdir -p %s && chown etcd -R %s" % (etcd_data_path, etcd_data_path))

run(""" cd /root
&& export bootstrapper_ip=%s
&& export etcd_data_path=%s
&& bash post_cloudinit_provision.sh""" % (boot_strapper, etcd_data_path))

def rm_clouinit_cache():
run("rm -rf /var/lib/cloud/instances/iid-local01")

def start_etcd():
run("""systemctl daemon-reload
&& systemctl stop etcd
&& systemctl enable etcd
&& systemctl start etcd""")

with open("hosts.yaml", 'r') as stream:
try:
y = yaml.load(stream)
env.user = y["user"]
env.password = y["password"]
env.hosts = y["hosts"]
boot_strapper = y["boot_strapper"]

set_mac_hostname = y["set_mac_hostname"]
docker_data_path = y["docker_data_path"]
etcd_data_path = y["etcd_data_path"]
except yaml.YAMLError as exc:
print(exc)
abort("load yaml error")




79 changes: 79 additions & 0 deletions fabric/set_hosts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import fabric.operations as op
import yaml
import sys
import re

mac_ip={}
host_ip={}
set_type=""

def modify_mac_hosts(path, ips):
import copy
local = copy.deepcopy(ips)

#hostname->ip
hosts = []
with open(path, "r") as fp:
for line in fp.read().split('\n'):
if len(re.sub('\s*', '', line)) and not line.startswith('#'):
parts = re.split('\s+', line)
ip = parts[0]
host_name = " ".join(parts[1:])
hosts.append([host_name, ip])
fp.close()

for n in hosts:
if n[0] in local:
n[1] = local[n[0]]
local[n[0]]= ""

with open(path, "w") as fw:
for n in hosts:
fw.write("%s %s\n" % (n[1], n[0]) )
for n in local:
if len(local[n]) > 0:
fw.write("%s %s\n" % (local[n], n) )
fw.close()

def set_mac_hosts():
src_path = "/etc/hosts"
dst_path = env.host_string + "/hosts"
get(src_path)
if set_type == "mac" or set_type == "all":
modify_mac_hosts(dst_path, mac_ip)
if set_type == "host" or set_type == "all":
modify_mac_hosts(dst_path, host_ip)
put(dst_path, src_path)

def display():
print host_ip
print mac_ip

with open("hosts.yaml", 'r') as stream:
try:
y = yaml.load(stream)
env.hosts = y["hosts"]
env.user = y["user"]
env.password = y["password"]

set_type = y["set_type"]
except yaml.YAMLError as exc:
print(exc)
abort("load yaml error")

for h in env.hosts:
dst_path = h + "/mac_ip_host"
with open(dst_path, "r") as fp:
for line in fp.read().split('\n'):
if len(re.sub('\s*', '', line)) and not line.startswith('#'):
parts = re.split('\s+', line)
mac = parts[0].replace(":", "-")
ip = parts[1]
host_name = parts[2]

mac_ip[mac] = ip
host_ip[host_name] = ip

Loading