虚拟机k8s 1.26版本安装部署(国内可用)

avatar
作者
筋斗云
阅读量:0

环境信息:

[root@k8s-master k8s-install]# cat /etc/centos-release CentOS Linux release 7.9.2009 (Core) [root@k8s-master k8s-install]# uname -a Linux k8s-master 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux [root@k8s-master k8s-install]# uname -a Linux k8s-master 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux [root@k8s-master k8s-install]# kubeadm version kubeadm version: &version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.9", GitCommit:"d1483fdf7a0578c83523bc1e2212a606a44fd71d", GitTreeState:"clean", BuildDate:"2023-09-13T11:31:28Z", GoVersion:"go1.20.8", Compiler:"gc", Platform:"linux/amd64"} [root@k8s-master k8s-install]# containerd -v containerd containerd.io 1.6.21 3dce8eb055cbb6872793272b4f20ed16117344f8 

更改centos 7 yum镜像源

下载镜像源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
更改镜像源http为https
sed -i ‘s#http://mirrors#https://mirrors#g’ CentOS-Base.repo
升级软件版本按需执行
yum update

k8s组件安装

containerd

添加镜像源

curl -o docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

查看所有可用containerd版本

yum list containerd.io --showduplicates

安装containerd

yum install -y containerd.io-1.6.21
containerd.io.x86_64 1.6.21-3.1.el7

containerd config default > /etc/containerd/config.toml #修改containerd为systemd启动 sed -i 's/SystemdCgroup = false/SystemdCgroup = true/1' config.toml #修改containerd pause镜像源为阿里云镜像源 sed -i 's#registry.k8s.io/pause:3.6#registry.aliyuncs.com/google_containers/pause:3.9#1' config.toml 

systemctl enable containerd
systemctl start containerd
systemctl status containerd

kubelet安装

安装kubeadm,kubelet,kubectl

yum list kubeadm kubelet kubectl --showduplicates|grep 1.26.9-0
yum install -y kubelet-1.26.9 kubeadm-1.26.9 kubectl-1.26.9
systemctl enable kubelet.service

环境修改

关闭selinux防火墙

setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config systemctl stop firewalld systemctl disable firewalld 

cat << EOF > /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter

[root@localhost ~]# cat << EOF > /etc/sysctl.d/99-kubernetes-cri.conf

net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
user.max_user_namespaces=28633
EOF
[root@localhost ~]# sysctl -p /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
user.max_user_namespaces = 28633

关闭swap

swapoff -a
/etc/fstab关闭开机启动
在这里插入图片描述

kubeadm初始化

#查看需要拉取镜像 kubeadm config images list --config kubeadm.yaml #手动拉取镜像 kubeadm config images pull --config kubeadm.yaml 初始化 kubeadm init --config kubeadm.yaml 

advertiseAddress:修改为master ip
imageRepository:使用阿里云镜像仓库地址下载k8s组件镜像

[root@k8s-master k8s-install]# cat kubeadm.yaml  apiVersion: kubeadm.k8s.io/v1beta3 kind: InitConfiguration localAPIEndpoint:   advertiseAddress: 192.168.28.91   bindPort: 6443 nodeRegistration:   criSocket: unix:///run/containerd/containerd.sock   taints:   - effect: PreferNoSchedule     key: node-role.kubernetes.io/master --- apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration kubernetesVersion: 1.26.0 imageRepository: registry.aliyuncs.com/google_containers networking:   podSubnet: 10.244.0.0/16 --- apiVersion: kubelet.config.k8s.io/v1beta1 kind: KubeletConfiguration cgroupDriver: systemd failSwapOn: false --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 kind: KubeProxyConfiguration mode: ipvs 

kubectl命令自动补全

yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo ‘source <(kubectl completion bash)’ >>~/.bashrc

calico部署安装

wget https://docs.projectcalico.org/v3.25/manifests/calico.yaml --no-check-certificate
保持CALICO_IPV4POOL_CIDR配置和kubeadm init config中podSubnet一致

        - name: CALICO_IPV4POOL_CIDR           value: "10.244.0.0/16" 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!