实验
三台一起
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
swapoff -a
vim /etc/hosts
192.168.10.40 master
192.168.10.60 node1
192.168.10.70 node2
hostnamectl set-hostname (改主机名)
桥接的 IPv4 流量传递到 iptables 的链
modprobe overlay
modprobe br_netfilter
vim /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward= 1
net.bridge.bridge-nf-call-ip6tables= 1
sysctl --system
安装Docker
yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
配置 Docker
设置驱动
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl daemon-reload
systemctl restart docker
安装 Kubeadm 工具
配置 yum 源
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=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
安装 Kubeadm 工具
yum install -y kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0
systemctl enable kubelet
systemctl start kubelet
mkdir k8s
cd k8s
导入镜像
托包 kubernetes_images_1.23.tar.gz
docker load -i kubernetes_images_1.23.tar.gz
在Master节点上
初始化Mster节点
kubeadm init --apiserver-advertise-address=192.168.10.30 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.0 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
没成功就用 kubeadm reset 初始化在重复上一步操作
配置 Master 节点
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
在后两个node节点上
操作在Master上提示的命令
kubeadm join 192.168.10.30:6443 --token ........(具体的Master上提示的有)
在Mster节点上
托文件 kube-flannel.yaml
kubectl apply -f kube-flannel.yaml
kubectl get node
kubectl get cs