CentOS 7 安装k8s集群

发布时间:2022-06-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了CentOS 7 安装k8s集群脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

1、创建3台虚拟机,并绑定可以连接外网的eiP

2、配置主机名、添加hostshostnamectl set-hostname k8s-master1hostnamectl set-hostname k8s-node1hostnamectl set-hostname k8s-node2

cat >> /etc/hosts << EOF192.168.56.11 k8s-master1192.168.56.12 k8s-node1192.168.56.13 k8s-node2EOF

3、关闭火墙、SELINUX和swap分区Systemctl stop firewalld && systemctl disable firewalldsetenforce 0 &amp;& sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configswapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstab

4、配置阿里yumcd /etc/yum.repos.d/ && mkdir bak && mv *.repo bak

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.COM/repo/Centos-7.repocurl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repocurl -o/etc/yum.repos.d/EPEL.repo http://mirrors.aliyun.com/repo/ePEl-7.repo

cat <<EOF > /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/enabled=1gpgcheck=0repo_gpgcheck=0EOF

yum clean all && yum makecache

CentOS 7 安装k8s集群

 

 

5、将桥接的ipv4流量传递到iptables 的链cat > /etc/sysctl.d/k8s.conf << EOFnet.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1EOF

sysctl --system

CentOS 7 安装k8s集群

 

 

7、安装k8syum install -y kubelet kubeadm kubectl

systemctl enable kubelet

8、统一docker运行方式vim /usr/lib/systemd/system/docker.serviceExecStart=/usr/bin/dockerd 后面添加 --exec-opt native.cgroupdriver=systemd

9、在master节点初始化kubeadm inIT --apiserver-advertise-address=192.168.56.11 --image-repository registry.aliyuncs.com/GOOGLE_containers --kubernetes-version v1.23.5 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

CentOS 7 安装k8s集群

 

按照上图提示先完成集群启动配置文件的配置

@H_512_57@

 

 

 

10、此时集群状态为notReady,需要先创建网络,如果无法获取文件,需要先想办法获取到对应的yaML文件kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

 

CentOS 7 安装k8s集群

 

 

11、在node节点执行节点加入集群操作,使用第9步初始化的时候打印出来的命令

CentOS 7 安装k8s集群

 

 

 

12、使能node节点可以使用kubectl命令mkdir ~/.kube && scp k8s-master1:/root/.kube/config ~/.kube/

CentOS 7 安装k8s集群

 

 

13、使能kube命令补全yum -y install bash-completionsource /usr/share/bash-completion/bash_completionsource <(kubectl completion bash)echo "source <(kubectl completion bash)" >> ~/.bashrc

 

脚本宝典总结

以上是脚本宝典为你收集整理的CentOS 7 安装k8s集群全部内容,希望文章能够帮你解决CentOS 7 安装k8s集群所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。