K8S

作者: 心疼你萌萌哒 | 来源:发表于2018-07-04 13:04 被阅读0次

部署k8smaster

#!/bin/bash
hostname  master 

cat > /etc/hosts <<eof
192.168.44.44 master
192.168.44.44 etcd
192.168.44.44 registry
192.168.44.45 node1
192.168.44.46 node2
eof

systemctl stop firewalld && systemctl disable firewalld && setenforce 0  

yum -y install etcd  > /dev/null 2>&1
if [ $? ==0 ];then
sed -ri '/ETCD_LISTEN_CLIENT_URLS=/c ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001" ' /etc/etcd/etcd.conf
sed -ri '/ETCD_NAME=/c ETCD_NAME="master1" ' /etc/etcd/etcd.conf
sed -ri '/ETCD_ADVERTISE_C/c ETCD_ADVERTISE_CLIENT_URLS="http://etcd:2379,http://etcd:4001"' /etc/etcd/etcd.conf
systemctl start etcd
echo 'etcd 安装配置好了'
fi

yum install docker -y > /dev/null 2>&1
if [ $? == 0 ];then
sed -ri '/OPTIONS=/c OPTIONS="--insecure-registry registry:5000 "' /etc/sysconfig/docker
systemctl start docker && systemctl enable docker 
echo 'docker 安装配置好了'
fi

#在kubernetes master上需要运行以下组件:
#Kubernets API Server
#Kubernets Controller Manager
#Kubernets Scheduler
yum install kubernetes -y > /dev/null 2>&1
if [ $? == 0 ];then
sed -ri '/KUBE_API_ADDR/c KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"' /etc/kubernetes/apiserver
sed -ri '/# KUBE_API_POR/c KUBE_API_PORT="--port=8080"' /etc/kubernetes/apiserver
sed -ri '/KUBE_ETCD_SERVE/c KUBE_ETCD_SERVERS="--etcd-servers=http://etcd:2379"' /etc/kubernetes/apiserver
sed -ri '/KUBE_ADMISSION/c KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"' /etc/kubernetes/apiserver 
sed -ri '/KUBE_MASTER=/c  KUBE_MASTER="--master=http://master:8080"' /etc/kubernetes/config
echo 'kubernetes 安装配置好了'
systemctl enable kube-apiserver.service && \
systemctl start kube-apiserver.service && \
systemctl enable kube-controller-manager.service && \
systemctl start kube-controller-manager.service && \
systemctl enable kube-scheduler.service && \
systemctl start kube-scheduler.service 
fi
yum install flannel -y  > /dev/null 2>&1
if [ $? == 0 ];then
sed -ri '/FLANNEL_ETCD_END/c FLANNEL_ETCD_ENDPOINTS="http://etcd:2379"' /etc/sysconfig/flanneld
etcdctl mk /atomic.io/network/config '{ "Network": "10.0.0.0/16" }' > /dev/null 2>&1
echo 'flannel 安装配置好了'
fi
systemctl enable flanneld.service && systemctl start flanneld.service \
&& systemctl restart  docker && systemctl restart kube-apiserver.service && \
systemctl restart kube-controller-manager.service && \
systemctl restart kube-scheduler.service 

部署k8s node1 node2 (改node1为node2 共两处)

#!/bin/bash
hostname  node1
cat > /etc/hosts <<eof
192.168.44.44 master
192.168.44.44 etcd
192.168.44.44 registry
192.168.44.45 node1
192.168.44.46 node2
eof

systemctl stop firewalld && systemctl disable firewalld && setenforce 0            

yum install docker -y  > /dev/null 2>&1
if [ $? == 0 ];then
sed -ri "/OPTIONS=/c OPTIONS='--insecure-registry registry:5000'" /etc/sysconfig/docker
systemctl enable docker
systemctl start docker
else
echo "docker 启动失败"
fi
#在kubernetes node上需要运行以下组件:
#Kubelet
#Kubernets Proxy
yum install kubernetes -y  > /dev/null 2>&1
if [ $? == 0 ];then
sed -ri '/KUBE_MASTER/c KUBE_MASTER="--master=http://master:8080"'  /etc/kubernetes/config
sed -ri '/KUBELET_ADDRESS/c KUBELET_ADDRESS="--address=0.0.0.0"'  /etc/kubernetes/kubelet
sed -ri '/KUBELET_HOSTNAME/c KUBELET_HOSTNAME="--hostname-override=node1"' /etc/kubernetes/kubelet
sed -ri '/KUBELET_API_SERVE/c KUBELET_API_SERVER="--api-servers=http://master:8080"' /etc/kubernetes/kubelet
systemctl enable kubelet.service
systemctl start kubelet.service
systemctl enable kube-proxy.service
systemctl start kube-proxy.service
else
echo "kubernetes 安装失败了"
fi

yum install flannel -y   > /dev/null 2>&1
if [ $? == 0 ];then
sed -ri '/FLANNEL_ETCD_ENDPOINT/c FLANNEL_ETCD_ENDPOINTS="http://etcd:2379"' /etc/sysconfig/flanneld
systemctl enable flanneld.service 
systemctl start flanneld.service 
systemctl restart  docker 
systemctl restart kubelet.service
systemctl restart kube-proxy.service
else
echo "flannel 安装失败了"
fi

相关文章

网友评论

      本文标题:K8S

      本文链接:https://www.haomeiwen.com/subject/scjeuftx.html