RcokyLinux安装k8s(单机版)
说明
本文章简单的表述单机创建流程,集群版同理创建(参考官方文档)
参考文档
- https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
- https://cloud.tencent.com/developer/article/2296549
- https://juejin.cn/post/7077770045220356104
- https://blog.csdn.net/wenwang3000/article/details/112544931
准备机器
根据master与worker的数量申请或者创建虚拟机
- 虚拟机
- 阿里云\腾讯云服务器
安装系统
- RockyLinux 9.4
更新系统软件
dnf update
dnf makecache
设置hostname
hostnamectl set-hostname k8s-master01
添加网络映射
vim /etc/hosts
172.21.16.2 k8s-master01
... 所有的机器
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
关闭selinux
sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
关闭swap分区
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab # 重启生效
将桥接的 IPv4 流量传递到 iptables 的链
cat > /etc/sysctl.d/k8s.conf << EOF
#开启网桥模式,可将网桥的流量传递给iptables链
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
#关闭ipv6协议
net.ipv6.conf.all.disable_ipv6=1
net.ipv4.ip_forward=1
EOF
加载 ip_vs 模块
for i in $(ls /usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs|grep -o "^[^.]*");do echo $i; /sbin/modinfo -F filename $i >/dev/null 2>&1 && /sbin/modprobe $i;done
安装containerd
dnf install -y containerd.io
systemctl enable containerd.service
systemctl start containerd.service
systemctl status containerd.service
containerd config default > /etc/containerd/config.toml
/etc/containerd/config.toml
- 第65行sanbox_image的内容,从原来的registry.k8s.io/pause:3.8修改成registry.aliyuncs.com/google_containers/pause:3.9
- 第137行 SystemdCgroup的内容,从原来的false改成true
注册k8s源
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF
dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
创建集群
kubeadm version
kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.30.1 --pod-network-cidr=10.10.0.0/16 --service-cidr=10.20.0.0/16 --apiserver-advertise-address=172.21.16.2
创建成功
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 172.21.16.2:6443 --token x8a3ob.npqm1izjavkullbn \
--discovery-token-ca-cert-hash sha256:aeb70113f735837b4bdb8fb79ad479c94c694631fcc4c3147a7be555c93cfb8c
安装网络插件 (Flannel)
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# 修改 "Network": "10.244.0.0/16" 为自己服务器的IPv4 CIDR 10.10.0.0/16
kubectl apply -f kube-flannel.yml
安装Dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
打印加入master的命令
kubeadm token create --print-join-command
未经允许,禁止转载。