K8S:kubeadm安装k8s(docker引擎)
规划主机
192.168.50.200 k8s-master 2核4g
192.168.50.201 k8s-node1 2核2g
192.168.50.202 k8s-node2 2核2g
初始操作
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
# 关闭swap
swapoff -a # 临时
sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久
# 关闭完swap后,一定要重启一下虚拟机!!!
# 根据规划设置主机名
hostnamectl set-hostname <hostname>
# 在master添加hosts
cat >> /etc/hosts << EOF
192.168.50.200 k8s-master
192.168.50.201 k8s-node1
192.168.50.202 k8s-node2
EOF
# 将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system # 生效
# 时间同步
yum install ntpdate -y
ntpdate time.windows.com
添加k8s与docker的repo
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
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装组件并配置镜像加速与docker驱动
# 安装docker与k8s安装组件
yum -y install docker-ce-20.10.24-3.el7 docker-ce-cli-20.10.24-3.el7 containerd.io kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6
# 开机自启
systemctl enable docker
systemctl enable kubelet
# 配置docker
mkdir /etc/docker
vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://hub-mirror.c.163.com/",
"https://dockerhub.icu",
"https://doublezonline.cloud",
"https://docker.m.daocloud.io",
"https://-----.aliyuncs.com" #你的阿里云加速
],
"insecure-registries": [
],
"exec-opts": [
"native.cgroupdriver=systemd" #修改docker驱动
]
}
# 启动docker
systemctl start docker
部署k8s的master
kubeadm init \
--apiserver-advertise-address=192.168.113.120 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.23.6 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
成功后
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
节点加入
复制master的Token
kubeadm join 192.168.113.120:6443 --token w34ha2.66if2c8nwmeat9o7 --discovery-token-ca-cert-hash sha256:20e2227554f8883811c01edd850f0cf2f396589d32b57b9984de3353a7389477
节点检查
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master NotReady control-plane,master 15h v1.23.6
k8s-node1 NotReady <none> 15h v1.23.6
k8s-node2 NotReady <none> 99s v1.23.6
注意
k8s支持的最后的docker版本为20.10.24,若高于此版本请降级。
docker需要修改驱动。