k8s v1.28.2集群部署(1m2n)
k8s v1.28.2集群部署
·
env
- CentOS7
- kubeadm v1.28.2
- kubelet v1.28.2
- kubectl v1.28.2
- containerd v1.6.24
master
1.配置静态ip
vi /etc/sysconfig/network-scripts/ifcfg-ens33
需要修改的项见下图
保存完配置文件后重启网络:sudo systemctl restart network
2.设置主机名
hostnamectl set-hostname km1
3.配置hosts文件
vi /etc/hosts
192.168.10.100 km1
4.同步时间
1. 更改时区
timedatectl // 查看当前时区
timedatectl list-timezones // 列出所有可用时区
timedatectl set-timezone Asia/Shanghai // 更改时区
2. 安装ntpdate
yum install -y ntpdate
3. 同步网络时间
ntpdate cn.pool.ntp.org
5.配置网络转发
6.安装containerd
1. 安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
2. 添加yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3. 安装containerd
yum install -y containerd
4. 生成配置文件
containerd config default > /etc/containerd/config.toml
5. 替换镜像
line61: sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
6. 开启SystemdCgroup
line125: SystemdCgroup = true
7. 重启containerd
systemctl restart containerd
7. 关闭swap
swapoff -a // 临时关闭
修改文件/etc/fstab // 永久关闭
free // 查看
8. 禁用selinux
sudo setenforce 0 // 临时关闭
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config // 永久关闭
sestatus // 查看
9.配置k8s的yum仓库源
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
10.安装kubeadm, kubelet, kubectl
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
sudo systemctl enable --now kubelet
11.添加crictl的配置文件
cat /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
12.启动kubeadm
kubeadm init \
--apiserver-advertise-address=192.168.10.100 \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers \
--kubernetes-version=1.28.2 \
--service-cidr=10.96.0.0/16 \
--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
export KUBECONFIG=/etc/kubernetes/admin.conf
13.安装网络插件
// 插件地址https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
// 下载之后执行以下命令
kubectl apply -f kube-flannel.yml
Node
1.初始化环境
同 Master 部分的 1~11 步
2.加入cluster
kubeadm join 192.168.10.100:6443 \
--token 4yhxqr.fowt5ni891b34jx9 \
--discovery-token-ca-cert-hash sha256:9c21461e7e97767fab6a9dde95f816208de3fabef22bf966f549506aa7ea267f
Additional
1. 重新生成加入cluster的命令(master的token过期或者找不到时)
kubeadm token create --print-join-command
更多推荐
已为社区贡献1条内容
所有评论(0)