k8s_master_install_v2.sh
Posted zhj5551
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s_master_install_v2.sh相关的知识,希望对你有一定的参考价值。
1 #!/bin/bash 2 #by zhangjia 3 #2019年3月30日22:17:14 4 #k8s_master auto install 5 ##############################################3333 6 set -e 7 network_name=eth0 8 apiserver_ip=`ifconfig $network_name | grep inet |grep netmask | awk ‘print $2‘` 9 node_ip=`ifconfig $network_name | grep inet |grep netmask|awk ‘print $2‘` 10 setenforce 0 && sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config 11 systemctl stop firewalld && systemctl disable firewalld 12 yum -y install ntp && ntpdate pool.ntp.org || true 13 systemctl start ntpd && systemctl enable ntpd 14 15 16 k8s_master_step1() 17 yum install kubernetes-master etcd flannel -y 18 #modify /etc/etcd/etcd.conf 19 sed -i "s#ETCD_DATA_DIR=.*#ETCD_DATA_DIR=\"/data/etcd/\"#g" /etc/etcd/etcd.conf 20 sed -i "s#ETCD_NAME=.*#ETCD_NAME=\"etcd_k8s_master\"#g" /etc/etcd/etcd.conf 21 sed -i "s#ETCD_LISTEN_CLIENT_URLS=.*#ETCD_LISTEN_CLIENT_URLS=\"http://localhost:2379,http://$apiserver_ip:2379\"#g" /etc/etcd/etcd.conf 22 sed -i "s#ETCD_ADVERTISE_CLIENT_URLS=.*#ETCD_ADVERTISE_CLIENT_URLS=\"http://localhost:2379,http://$apiserver_ip:2379\"#g" /etc/etcd/etcd.conf 23 [[ ! -d /data/etcd ]] && ( mkdir -p /data/etcd/;chmod 757 -R /data/etcd/ ) 24 systemctl restart etcd.service 25 26 #modify /etc/kubernetes/apiserver 27 sed -i "s#KUBE_API_ADDRESS=.*#KUBE_API_ADDRESS=\"--insecure-bind-address=0.0.0.0\"#g" /etc/kubernetes/apiserver 28 sed -i "/KUBE_API_PORT/ s/#//g" /etc/kubernetes/apiserver 29 sed -i "/KUBELET_PORT/ s/#//g" /etc/kubernetes/apiserver 30 sed -i "s#KUBE_ETCD_SERVERS=.*#KUBE_ETCD_SERVERS=\"--etcd-servers=http://$apiserver_ip:2379\"#g" /etc/kubernetes/apiserver 31 sed -i "s#KUBE_ADMISSION_CONTROL=.*#KUBE_ADMISSION_CONTROL=\"--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota\"#g" /etc/kubernetes/apiserver 32 sed -i ‘s/\ //g‘ /etc/kubernetes/apiserver 33 34 #modify /etc/kubernetes/config 35 sed -i "s#KUBE_ALLOW.*#KUBE_ALLOW_PRIV=\"--allow-privileged=true\"#g" /etc/kubernetes/config 36 sed -i "s#KUBE_MASTER=.*#KUBE_MASTER=\"--master=http://$apiserver_ip:8080\"#g" /etc/kubernetes/config 37 38 #start etcd kube-apiserver kube-controller-manager kube-scheduler 39 for I in etcd kube-apiserver kube-controller-manager kube-scheduler;do systemctl restart $I;systemctl enable $I;systemctl status $I;done 40 iptables -P FORWARD ACCEPT 41 42 43 k8s_node_step2() 44 #install kubernetes-node etcd docker flannel *rhsm 45 yum install kubernetes-node etcd docker flannel *rhsm* -y 46 #配置文件/etc/kubernetes/kubelet 47 sed -i "/KUBELET_ADDRESS/ s/127.0.0.1/0\.0\.0\.0/g" /etc/kubernetes/kubelet 48 sed -i "/KUBELET_PORT/ s/#//g" /etc/kubernetes/kubelet 49 sed -i "s#KUBELET_HOSTNAME.*#KUBELET_HOSTNAME=\"--hostname-override=$node_ip\"#g" /etc/kubernetes/kubelet 50 sed -i "s#KUBELET_API_SERVER.*#KUBELET_API_SERVER=\"--api-servers=http://$apiserver_ip:8080\"#g" /etc/kubernetes/kubelet 51 sed -i ‘s/\ //g‘ /etc/kubernetes/kubelet 52 #配置文件/etc/kubernetes/config 53 sed -i "/KUBE_ALLOW_PRIV/ s/false/true/g" /etc/kubernetes/config 54 sed -i "s#KUBE_MASTER.*#KUBE_MASTER=\"--master=http://$apiserver_ip:8080\"#g" /etc/kubernetes/config 55 #启动 kube-proxy kubelet docker 56 for I in kube-proxy kubelet docker;do systemctl restart $I ;systemctl enable $I ;systemctl status $I;done 57 iptables -P FORWARD ACCEPT 58 59 60 61 62 flannel_step3() 63 #modify /etc/sysconfig/flannel 64 sed -i "s#127.0.0.1#$apiserver_ip#g" /etc/sysconfig/flanneld 65 #在Master服务器,测试Etcd集群是否正常,同时在Etcd配置中心创建flannel网络配置: 66 etcdctl member list 67 etcdctl cluster-health 68 etcdctl rm /atomic.io/network/ --recursive || true 69 etcdctl mk /atomic.io/network/config ‘"Network":"172.17.0.0/16"‘ 70 etcdctl get /atomic.io/network/config 71 systemctl restart flanneld ; systemctl enable flanneld 72 73 74 75 flanneld_step4() 76 #k8s_master的/etc/sysconfig/flanneld 77 sed -i "s#FLANNEL_ETCD_ENDPOINTS.*#FLANNEL_ETCD_ENDPOINTS=\"http://$apiserver_id:2379\"#g" /etc/sysconfig/flanneld 78 systemctl restart flanneld ; systemctl enable flanneld 79 docker load < pod-infrastructure.tgz 80 docker tag $(docker images|grep none|awk ‘print $3‘) registry.access.redhat.com/rhel7/pod-infrastructure 81 docker load < kubernetes-dashboard-amd64.tgz 82 docker tag $(docker images|grep none|awk ‘print $3‘) bestwu/kubernetes-dashboard-amd64:v1.6.3 83 84 85 86 dashboard_step5() 87 #然后在Master端,创建dashboard-controller.yaml 88 #创建dashboard-service.yaml 89 sed -i "/apiserver-host/ s#http.*#http://$apiserver_ip:8080#g" dashboard-controller.yaml 90 kubectl delete -f dashboard-controller.yaml || true ; kubectl create -f dashboard-controller.yaml 91 kubectl delete -f dashboard-service.yaml || true ; kubectl create -f dashboard-service.yaml 92 kubectl get namespace 93 kubectl get deployment --all-namespaces 94 kubectl get svc --all-namespaces 95 kubectl get pods --all-namespaces 96 kubectl get pod -o wide --all-namespaces 97 kubectl describe service/kubernetes-dashboard --namespace="kube-system" 98 #kubectl describe pod/kubernetes-dashboard-530803917-816df --namespace="kube-system" 99 #kubectl delete pod/kubernetes-dashboard-530803917-816df --namespace="kube-system" --grace-period=0 --force 100 101 102 103 #k8s_master_step1 104 #flannel_step3 105 #dashboard_step5
以上是关于k8s_master_install_v2.sh的主要内容,如果未能解决你的问题,请参考以下文章