MAC + 虚拟机(centOS7) 安装多节点K8S平台实践(v1.18.1)
花了一天的实践终于有空做这个实践了,之前一直用Mac的 Docker + 自带Kubernetes 单节点环境,很多东西糊里糊涂的。而且不想在本机上装Docker了,现在的K8S都升级到了1.8.1了,加上最近在公司也在玩内部的平台,感觉有些东西还是没能理解,尤其是在平台级别的应用。所以借次机会在实践和整理一下。KubeAdmin工具现在也很方便了,虽然 碰到了很多坑点(参考坑点),也对一些知识理解更加深入,Mac再也不用装Docker了。
参考资料:
https://www.kubernetes.org.cn/7189.html
https://blog.csdn.net/qq_38900565/article/details/102585741
https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/
https://blog.csdn.net/twingao/article/details/105382305
环境和部署计划
软件说明:
- VMware Fusion 专业版 11.5 (windows的更加容易找)
- CentOS Linux release 7.7.1908 (Core)
- docker-ce-cli.x86_64 1:19.03.8-3.el7
- Kubernetes 1.18.1
host name | ip | description |
---|---|---|
k8s-master | 192.168.1.15 | Master |
k8s-node1 | 192.168.1.16 | node1 |
k8s-node2 | 192.168.1.17 | node2 |
k8s-node3 | 192.168.1.19 | node3 |
k8s-nfs | 192.168.1.18 | NFS服务器 |
准备基础镜像
不得不说有镜像这个东西,能让工作方便很多。基础镜像可以给所有节点使用。
- 关闭swape,Kubernetes Amin 安装必须要关闭swap
sed -ri 's/.*swap.*/#&/' /etc/fstab
查看
[root@k8s-master /]# free
total used free shared buff/cache available
Mem: 1863088 880148 135824 10288 847116 820336
Swap: 0 0 0
[root@k8s-master /]#
- [ ] 设置iptable bridge
cat <<EOF> /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
modprobe br_netfilter
sysctl --system
-----output----
[root@k8s-master ~]# modprobe br_netfilter
[root@k8s-master ~]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/k8s.conf ...
net.bridge.bridge-nf-call-ip6tables = 1 <!--这里会显示 ->
net.bridge.bridge-nf-call-iptables = 1 <!--effective here ->
* Applying /etc/sysctl.conf ...
- [ ] 关闭selinux
vi /etc/selinux/config
修改
SELINUX=disabled
---注意这里千万别改错成SELINUXTYPE,这个会令系统无法启动---
- [ ] 更新IP的主机
vim /etc/hosts
#
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
192.168.1.15 k8s-master
192.168.1.16 k8s-node1
192.168.1.17 k8s-node2
192.168.1.18 k8s-nfs
192.168.1.19 k8s-node3
255.255.255.255 broadcasthost
::1 localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
vi /etc/hostname
k8s-master
修改IP地址 (我的是ens33,大家看看自己的系统对应的是什么名字)
vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.15
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=8.8.8.8
NAME=ens33
UUID=d2faf7a5-af21-4815-b630-7d27f718fac3
DEVICE=ens33
ONBOOT=yes
PS:这里没做免密SSH
- [ ] 关闭防火墙
本环境都是在局域网,学习研究之用。关闭防火墙比较方便,否则得去写入规则
systemctl stop firewalld.service
- [ ] 更新国内yum源(阿里镜像)添加Kubernetes 国内镜像源。
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
vim /etc/yum.repos.d/kubernetes.repo
##添加以下内容
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
ps:你也可以加在你现有的源(我加在 CentOS-Base.repo)
/etc/yum.repos.d 这个目录是yum的源目录
- [ ] 安装 Docker-CE
查看最新版本的docker-ce
yum list docker-ce
docker-ce.x86_64 3:19.03.8-3.el7
直接安装吧
yum install docker-ce
- 设置Docker国内镜像或者阿里云镜像加速(需要阿里账号)
vi /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]