1 #!/bin/bash 2 #by zhangjia 3 #2019年3月30日22:17:14 4 #shell auto install k8s 5 ##############################################3333 6 set -e 7 apiserver_id=192.168.134.131 8 network_name=eth0 9 node_ip=`ifconfig ${network_name} | grep inet |grep netmask|awk '{print $2}'` 10 11 k8s_node_step2() { 12 setenforce 0 && sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config 13 systemctl stop firewalld && systemctl disable firewalld 14 yum -y install ntp && ntpdate pool.ntp.org || true 15 systemctl start ntpd && systemctl enable ntpd 16 #install kubernetes-node etcd docker flannel *rhsm 17 yum install kubernetes-node etcd docker flannel *rhsm* -y 18 #配置文件/etc/kubernetes/kubelet 19 sed -i "/KUBELET_ADDRESS/ s/127.0.0.1/0\.0\.0\.0/g" /etc/kubernetes/kubelet 20 sed -i "/KUBELET_PORT/ s/#//g" /etc/kubernetes/kubelet 21 sed -i "s#KUBELET_HOSTNAME.*#KUBELET_HOSTNAME=\"--hostname-override=${node_ip}\"#g" /etc/kubernetes/kubelet 22 sed -i "s#KUBELET_API_SERVER.*#KUBELET_API_SERVER=\"--api-servers=http://${apiserver_id}:8080\"#g" /etc/kubernetes/kubelet 23 sed -i 's/\ //g' /etc/kubernetes/kubelet 24 #配置文件/etc/kubernetes/config 25 sed -i "/KUBE_ALLOW_PRIV/ s/false/true/g" /etc/kubernetes/config 26 sed -i "s#KUBE_MASTER.*#KUBE_MASTER=\"--master=http://${apiserver_id}:8080\"#g" /etc/kubernetes/config 27 #启动 kube-proxy kubelet docker 28 for I in kube-proxy kubelet docker;do systemctl restart $I ;systemctl enable $I ;systemctl status $I;done 29 iptables -P FORWARD ACCEPT 30 } 31 32 flanneld_step4() { 33 #k8s_master的/etc/sysconfig/flanneld 34 sed -i "s#FLANNEL_ETCD_ENDPOINTS.*#FLANNEL_ETCD_ENDPOINTS=\"http://${apiserver_id}:2379\"#g" /etc/sysconfig/flanneld 35 systemctl restart flanneld ; systemctl enable flanneld 36 docker load < pod-infrastructure.tgz 37 docker tag $(docker images|grep none|awk '{print $3}') registry.access.redhat.com/rhel7/pod-infrastructure 38 docker load < kubernetes-dashboard-amd64.tgz 39 docker tag $(docker images|grep none|awk '{print $3}') bestwu/kubernetes-dashboard-amd64:v1.6.3 40 } 41 42 43 44 k8s_node_step2 45 #flanneld_step4