searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

单机搭建k8s集群

2024-09-26 09:25:47
18
0

前置条件

单机内存够大,我的机器是32G,安装VMware,初始化出3台虚拟机(centos7)

环境准备

虚拟机 IP 组件
node1 192.168.152.128 docker,kubectl,kubeadm,kubelet
node2 192.168.152.129 docker,kubectl,kubeadm,kubelet
node3 192.168.152.130 docker,kubectl,kubeadm,kubelet

配置host

编辑三台虚拟机的/etc/hosts文件,添加下面内容

cat >> /etc/hosts << EOF
192.168.152.128 node1
192.168.152.129 node2
192.168.152.130 node3
EOF

时间同步

yum install ntpdate -y
 
ntpdate time.windows.com

关闭防火墙

systemctl stop firewalld
 
systemctl disable firewalld

关闭selinux

selinux sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
 
setenforce 0 # 临时

禁用swap分区

swapoff -a # 临时
sed -ri 's/.\*swap.\*/#&/' /etc/fstab # 永久

修改Linux内核参数

cat <<EOF | sudo tee /etc/sysctl.d/kubernetes.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

sudo sysctl --system

安装kubernetes组件kubectl、kubelet、kubeadm

yum install -y kubectl kubelet kubeadm

初始化config.toml并配置镜像源

mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
#修改sandbox
# sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6"

systemctl restart containerd.service

初始化集群

kubeadm init \
 
            --apiserver-advertise-address=192.168.152.128 \
            --image-repository registry.aliyuncs.com/google_containers \
 
            --kubernetes-version v1.30.2 \
 
            --service-cidr=10.96.0.0/12 \
 
             --pod-network-cidr=10.244.0.0/16
 
返回参数: 
kubeadm join 192.168.152.128:6443 --token 1fbmmf.5shzkqvg432mvir0 \
	--discovery-token-ca-cert-hash sha256:a9e8731f039f35ccbc39488251675fa236ac97709df952cdebf094f98447caaf 
 
# 创建必要文件
 
mkdir -p $HOME/.kube
 
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 
sudo chown $(id -u):$(id -g) $HOME/.kube/config

至此,一个简单的3节点k8s集群搭建完毕。

0条评论
作者已关闭评论
l****n
3文章数
0粉丝数
l****n
3 文章 | 0 粉丝
l****n
3文章数
0粉丝数
l****n
3 文章 | 0 粉丝
原创

单机搭建k8s集群

2024-09-26 09:25:47
18
0

前置条件

单机内存够大,我的机器是32G,安装VMware,初始化出3台虚拟机(centos7)

环境准备

虚拟机 IP 组件
node1 192.168.152.128 docker,kubectl,kubeadm,kubelet
node2 192.168.152.129 docker,kubectl,kubeadm,kubelet
node3 192.168.152.130 docker,kubectl,kubeadm,kubelet

配置host

编辑三台虚拟机的/etc/hosts文件,添加下面内容

cat >> /etc/hosts << EOF
192.168.152.128 node1
192.168.152.129 node2
192.168.152.130 node3
EOF

时间同步

yum install ntpdate -y
 
ntpdate time.windows.com

关闭防火墙

systemctl stop firewalld
 
systemctl disable firewalld

关闭selinux

selinux sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
 
setenforce 0 # 临时

禁用swap分区

swapoff -a # 临时
sed -ri 's/.\*swap.\*/#&/' /etc/fstab # 永久

修改Linux内核参数

cat <<EOF | sudo tee /etc/sysctl.d/kubernetes.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

sudo sysctl --system

安装kubernetes组件kubectl、kubelet、kubeadm

yum install -y kubectl kubelet kubeadm

初始化config.toml并配置镜像源

mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
#修改sandbox
# sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6"

systemctl restart containerd.service

初始化集群

kubeadm init \
 
            --apiserver-advertise-address=192.168.152.128 \
            --image-repository registry.aliyuncs.com/google_containers \
 
            --kubernetes-version v1.30.2 \
 
            --service-cidr=10.96.0.0/12 \
 
             --pod-network-cidr=10.244.0.0/16
 
返回参数: 
kubeadm join 192.168.152.128:6443 --token 1fbmmf.5shzkqvg432mvir0 \
	--discovery-token-ca-cert-hash sha256:a9e8731f039f35ccbc39488251675fa236ac97709df952cdebf094f98447caaf 
 
# 创建必要文件
 
mkdir -p $HOME/.kube
 
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 
sudo chown $(id -u):$(id -g) $HOME/.kube/config

至此,一个简单的3节点k8s集群搭建完毕。

文章来自个人专栏
环境搭建
2 文章 | 1 订阅
0条评论
作者已关闭评论
作者已关闭评论
0
1