当前位置:网站首页>Kubernetes——裸机搭建集群环境
Kubernetes——裸机搭建集群环境
2022-06-22 05:10:00 【吴声子夜歌】
主节点需要
- docker(可以是其它容器运行时)
- kubectl(集群命令行交互工具)
- kubeadm(集群初始化工具)
工作节点需要
- docker(也可以是其它容器运行时)
- kubelet(管理Pod和容器,确保他们健康稳定运行)
- kube-proxy(网络代理,负责网络相关的工作)
准备3台服务器
Master (10.0.20.9)
Node1 (10.0.8.8)
Node2 (10.0.12.12)
每个节点分别设置对应的主机名
hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2



所有节点都修改hosts
vim /etc/hosts
10.0.20.9 master
10.0.8.8 node1
10.0.12.12 node2
所有节点关闭SELinux
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
所有节点确保防火墙关闭
systemctl stop firewalld
systemctl disable firewalld
关闭swap
sudo swapoff -a (如果机器重启,这句需要重新执行一次)
也可以永久禁用
sudo vim /etc/fstab
将 swap 那一行注释掉
添加安装源
添加k8s安装源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
添加Docker安装源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装所需组建(所有节点)
# 不要装1.24,无法初始化集群
yum install -y docker-ce
yum install -y kubelet-1.23.0
yum install -y kubeadm-1.23.0
yum install -y kubectl-1.23.0
启动kubelet、docker,并设置开机启动(所有节点)
systemctl enable kubelet
systemctl start kubelet
systemctl enable docker
systemctl start docker
修改docker配置(所有节点)
# kubernetes官方推荐docker等使用systemd作为cgroupdriver,否则kubelet启动不了
cat <<EOF > daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "registry-mirrors": ["https://ud6340vz.mirror.aliyuncs.com"] } EOF
mv daemon.json /etc/docker/
# 重启生效
systemctl daemon-reload
systemctl restart docker
用kuberadm初始化集群(仅主节点)
# 初始化集群控制台 Control plan
# 失败了可以用 kubeadm reset重置
kubeadm init --kubernetes-version=v1.23.0 --image-repository=registry.aliyuncs.com/google_containers --v=6
# 记得把kubeadm join xxx保存起来
# 忘记了则需重新获取:kubeadm token create --print-join-command
# 复制授权文件,以便kubectl可以有权限访问集群
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
#在其它机器上创建 ~/.kube/config 文件也能通过kubectl访问到集群


把工作节点加入集群(只在工作节点运行)
# 初始化集群时返回的
kubeadm join 10.0.20.9:6443 --token 0dlyrh.wpzp6dvpx5fdxfzt --discovery-token-ca-cert-hash sha256:5b6f9a7d6ac30904c6b2018567930ff7ca3d652f804bbb100a72360003305d75

查看节点:kubectl get node
安装网络插件,否则node是NotReady状态(主节点运行)
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

节点已经Ready:
边栏推荐
- [scientific research notes] focal loss
- Arrangement of soft test subjects in the second half of 2022
- 软件架构与模式:结构、组件、关系
- Postman uses (reads) JSON files for batch testing
- 8. Gateway request logging
- flink部署模式(二)- yarn三种部署模式
- Getting the return value of DPI function is always 96 | getting the return value of DPI function is incorrect | why the return value of getdpiformonitor/getdevicecaps is incorrect
- 不允许方法被重写的方式包括哪些?
- Web page design and production final assignment report - College Students' online flower shop
- Accelerate the promotion of industrial Internet, and map out a new blueprint for development
猜你喜欢

It is easy to analyze and improve R & D efficiency by understanding these five figures

The Impossible Triangle of NLP?

6. Local - custom filter factory

Understanding of service container, service provider and facade of laravel

NLP 的 不可能三角?

Sort ten integers using selection

Flynk deployment mode summary

flink部署模式总结
![[chrome] Google tips Google browser comes with scrolling screenshot (full screen shot)](/img/9b/6ad704959a77abf9cb28fdd33b81b5.png)
[chrome] Google tips Google browser comes with scrolling screenshot (full screen shot)

In 2022, the super intern plans to make a breakthrough in the offer of it famous enterprises, and the nine high salary skills help the dream of famous enterprises
随机推荐
Idea创建方法时,使用注解提示方法参数(param)、返回值(return)、方法作用(Description)
Understanding of service container, service provider and facade of laravel
9. Gateway cross domain processing
数据的备份与恢复
软件架构与模式:结构、组件、关系
Remote Dictionary Server(Redis)——基于 KV 结构的作为 Cache 使用的 NoSQL 数据库管理系统
mysql day01课堂笔记
Golang concise architecture practice
Great! Huaibei and Huaibei enterprises are approved to use special marks for geographical indication products
Progress information collection for progress control of Zhiyuan project management SPM system
DTS迁移秘籍-Oracle篇
MySQL common SQL
VirtualBox 6.1.34 release
What is cloud hosting and what are its advantages?
DeformConv
第6章无穷级数_傅立叶级数
Non recursive printing Fibonacci sequence
[scientific research notes] about using the downsampling multiple of openslide cut
flink部署模式总结
Web design and production final assignment report -- animator Hayao Miyazaki