码迷,mamicode.com
首页 > 其他好文 > 详细

k8s_master_install.sh

时间:2019-07-17 00:35:21      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:top   fir   proxy   limit   bak   pac   isa   stat   etcd集群   

 1 #!/bin/bash
 2 #by zhangjia
 3 #2019年3月30日22:17:14
 4 #k8s_master auto install
 5 ##############################################
 6 set -e
 7 apiserver_id=172.19.81.51
 8 node1_ip=172.19.81.49
 9 #node2_ip=192.168.134.133
10 setenforce 0 && sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
11 systemctl stop firewalld && systemctl disable firewalld
12 #install ntp_server
13 yum -y install ntp && ntpdate pool.ntp.org || true
14 systemctl start ntpd && systemctl enable ntpd
15 
16 k8s_master() {
17     #network_name=eth0
18     #apiserver_id=`ifconfig ${network_name} | grep inet |grep netmask | awk {print $2}`
19     yum install kubernetes etcd flannel -y
20     for i in `ls /etc/kubernetes/`;do cp $i $i.bak ;done
21     #modify /etc/etcd/etcd.conf
22     sed -i "s#ETCD_DATA_DIR=.*#ETCD_DATA_DIR=\"/data/etcd/\"#g" /etc/etcd/etcd.conf
23     sed -i "s#ETCD_NAME=.*#ETCD_NAME=\"etcd_k8s_master\"#g" /etc/etcd/etcd.conf
24     sed -i "s#ETCD_LISTEN_CLIENT_URLS=.*#ETCD_LISTEN_CLIENT_URLS=\"http://0.0.0.0:2379,http://0.0.0.0:4001\"#g" /etc/etcd/etcd.conf
25     sed -i "s#ETCD_ADVERTISE_CLIENT_URLS=.*#ETCD_ADVERTISE_CLIENT_URLS=\"http://0.0.0.0:2379,http://0.0.0.0:4001\"#g" /etc/etcd/etcd.conf
26     [[ ! -d /data/etcd ]] && ( mkdir -p /data/etcd/;chmod 757 -R /data/etcd/ )
27     systemctl restart etcd.service
28 
29     #modify /etc/kubernetes/apiserver
30     sed -i "s#KUBE_API_ADDRESS=.*#KUBE_API_ADDRESS=\"--insecure-bind-address=0.0.0.0\"#g" /etc/kubernetes/apiserver
31     sed -i "/KUBE_API_PORT/ s/#//g" /etc/kubernetes/apiserver
32     sed -i "/KUBELET_PORT/ s/#//g" /etc/kubernetes/apiserver
33     sed -i "s#KUBE_ETCD_SERVERS=.*#KUBE_ETCD_SERVERS=\"--etcd-servers=http://${apiserver_id}:2379\"#g" /etc/kubernetes/apiserver
34     sed -i "s#KUBE_ADMISSION_CONTROL=.*#KUBE_ADMISSION_CONTROL=\"--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota\"#g" /etc/kubernetes/apiserver
35     sed -i s/\ //g /etc/kubernetes/apiserver
36 
37     #modify /etc/kubernetes/config
38     sed -i "s#KUBE_ALLOW.*#KUBE_ALLOW_PRIV=\"--allow-privileged=true\"#g" /etc/kubernetes/config
39     sed -i "s#KUBE_MASTER=.*#KUBE_MASTER=\"--master=http://${apiserver_id}:8080\"#g" /etc/kubernetes/config
40     for I in etcd kube-apiserver kube-controller-manager kube-scheduler;do systemctl restart $I;systemctl enable $I;systemctl status $I;done
41     iptables -P FORWARD ACCEPT
42     #modify /etc/sysconfig/flannel
43     sed -i "s#127.0.0.1#${apiserver_id}#g" /etc/sysconfig/flanneld
44     #在Master服务器,测试Etcd集群是否正常,同时在Etcd配置中心创建flannel网络配置:
45     etcdctl  member list
46     etcdctl cluster-health
47     etcdctl  rm   /atomic.io/network/   --recursive || true
48     etcdctl  mk  /atomic.io/network/config {"Network":"172.17.0.0/16"}
49     etcdctl get /atomic.io/network/config
50     etcdctl -C http://${apiserver_id}:2379 cluster-health
51     for I in flanneld etcd kube-apiserver kube-controller-manager kube-scheduler;do systemctl restart $I;systemctl enable $I;systemctl status $I;done
52 }
53 k8s_node() {
54     uname -r
55     yum -y update
56     yum -y remove docker  docker-common docker-selinux docker-engine
57     yum install -y yum-utils device-mapper-persistent-data lvm2
58     #使用下列命令设置 stable 镜像仓库。您始终需要使用 stable 镜像仓库,即使您还需要通过 edge 或 testing 镜像仓库安装构建也是如此。
59     yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
60     yum list docker-ce --showduplicates | sort -r
61     sudo yum makecache fast
62     #yum -y install docker-ce
63     #network_name=eth0
64     #node1_ip=`ifconfig ${network_name} | grep inet |grep netmask|awk {print $2}`
65     yum install kubernetes docker flannel *rhsm* wget -y
66     wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
67     rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
68     docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
69     #配置文件/etc/kubernetes/kubelet
70     for i in `ls /etc/kubernetes/`;do cp $i $i.bak ;done
71     sed -i "/KUBELET_ADDRESS/ s/127.0.0.1/0\.0\.0\.0/g" /etc/kubernetes/kubelet
72     sed -i "/KUBELET_PORT/ s/#//g" /etc/kubernetes/kubelet 
73     sed -i "s#KUBELET_HOSTNAME.*#KUBELET_HOSTNAME=\"--hostname-override=k8s-node-${node1_ip}\"#g" /etc/kubernetes/kubelet
74     sed -i "s#KUBELET_API_SERVER.*#KUBELET_API_SERVER=\"--api-servers=http://${apiserver_id}:8080\"#g" /etc/kubernetes/kubelet 
75     sed -i s/\ //g /etc/kubernetes/kubelet
76     #配置文件/etc/kubernetes/config
77     sed -i "/KUBE_ALLOW_PRIV/ s/false/true/g" /etc/kubernetes/config
78     sed -i "s#KUBE_MASTER.*#KUBE_MASTER=\"--master=http://${apiserver_id}:8080\"#g" /etc/kubernetes/config
79     #启动 kube-proxy  kubelet  docker
80     for  I  in  kube-proxy  kubelet  docker;do systemctl  restart  $I ;systemctl  enable  $I ;systemctl status $I;done
81     iptables -P FORWARD ACCEPT
82     #k8s_master的/etc/sysconfig/flanneld
83     sed -i "s#FLANNEL_ETCD_ENDPOINTS.*#FLANNEL_ETCD_ENDPOINTS=\"http://${apiserver_id}:2379\"#g" /etc/sysconfig/flanneld
84     for  I  in flanneld kube-proxy  kubelet  docker;do systemctl  restart  $I ;systemctl  enable  $I ;systemctl status $I;done
85     #docker load < pod-infrastructure.tgz
86     #docker tag $(docker images|grep none|awk {print $3}) registry.access.redhat.com/rhel7/pod-infrastructure
87     #docker load < kubernetes-dashboard-amd64.tgz
88     #docker tag $(docker images|grep none|awk {print $3}) bestwu/kubernetes-dashboard-amd64:v1.6.3
89 }
90 
91 #k8s_master
92 #k8s_node

 

k8s_master_install.sh

标签:top   fir   proxy   limit   bak   pac   isa   stat   etcd集群   

原文地址:https://www.cnblogs.com/zhj5551/p/11198293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!