百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术分类 > 正文

kubeadm搭建k8s集群

ztj100 2025-01-01 23:47 11 浏览 0 评论

前言

本教程搭建的k8s cluster 集群版本为v1.25

由于k8s从v1.24版本开始便不在内置docker

但是如果还想继续使用的话只能加上中间层cri-docker

Linux主机

本教程基于centos7系统,利用VMWare自带的克隆技术快速的创建出三台linux主机

IP

hostname

node

192.168.32.137

k8s-master

master

192.168.32.138

k8s-node-1

worker1

192.168.32.139

k8s-node-2

worker2

基础环境

hostname设置

# 不同节点设置不同的hostname
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node-1
hostnamectl set-hostname k8s-node-2

# 设置集群ip信息
vi /etc/hosts

192.168.32.137 k8s-master
192.168.32.138 k8s-node-1
192.168.32.139 k8s-node-2

yum更新

yum install update
yum install lrzsz
yum install -y conntrack ipvsadm ipset jq sysstat curl iptables libseccomp

docker安装

# 设置repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 设置国内镜像
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://j16wttpi.mirror.aliyuncs.com"]
}
EOF

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

# 进行安装
yum install -y docker-ce
systemctl start docker
systemctl enable docker

# 查看是否成功
docker info

k8s安装准备

# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld

# 关闭selinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

# 关闭swap
swapoff -a
sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab

# 配置iptables的ACCEPT规则
iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT

# 设置系统参数
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system

部署 cri-dockerd

引用

  • 开源地址: https://gitcode.net/mirrors/Mirantis/cri-dockerd?utm_source=csdn_github_accelerator
  • 下载地址:https://gitcode.net/mirrors/Mirantis/cri-dockerd/-/releases/v0.2.6?spm=1033.2243.3001.5876
  • 我的地址:[cri-dockerd-0.2.6.amd64.tgz] https://note.youdao.com/ynoteshare/index.html?id=f5a7f4b2772959a2e6ca3c022ffc157a&type=note&_time=1670996952444

cri-dockerd部署

# 解压并执行以下命令
tar -xf cri-dockerd-0.2.6.amd64.tgz
cp cri-dockerd/cri-dockerd /usr/bin/
chmod +x /usr/bin/cri-dockerd

# 配置启动?件,执行如下命令
cat <<"EOF" > /usr/lib/systemd/system/cri-docker.service
[Unit]
Description=CRI Interface for Docker Application Container Engine
Documentation=https://docs.mirantis.com
After=network-online.target firewalld.service docker.service
Wants=network-online.target
Requires=cri-docker.socket
[Service]
Type=notify
ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
EOF

# ?成 socket ?件,执行如下命令
cat <<"EOF" > /usr/lib/systemd/system/cri-docker.socket
[Unit]
Description=CRI Docker Socket for the API
PartOf=cri-docker.service
[Socket]
ListenStream=%t/cri-dockerd.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF

# 启动 cri-docker 并设置开机?动启动
systemctl daemon-reload
systemctl enable cri-docker --now
systemctl is-active cri-docker

# 添加阿?云 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

k8s安装

安装 kubeadm kubelet kubectl

# 执行如下命令
yum install -y kubelet-1.25.0 kubeadm-1.25.0 kubectl-1.25.0
kubeadm version
systemctl enable kubelet

# 修改配置文件
cat <<EOF > /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"
EOF

# 初始化master节点,此命令只在master节点执行
kubeadm init \
--apiserver-advertise-address=192.168.32.137 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.0 \
--service-cidr=10.10.0.0/12 \
--pod-network-cidr=172.17.0.0/16 \
--cri-socket /var/run/cri-dockerd.sock \
--ignore-preflight-errors=all

# master节点启动成功后,复制加入集群的命令到node1和node2节点执行
# master节点和node节点都执行, 其中admin.conf 需要从master节点拷贝到node节点
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

# 只在node节点执行
kubeadm join 192.168.32.137:6443 --token sg644x.nnnskgv24bid6u88 
 --discovery-token-ca-cert-hash sha256:e995194e28d8b8ea9006ac84eb112c645f15c48e7b3c38f05f71403a6524bc48 --cri-socket /var/run/cri-dockerd.sock

网络插件calico

  • calico下载,这里直接给出修改过的yaml
    • calico.yaml
    • https://note.youdao.com/ynoteshare/index.html?id=bc7da0afb3991e47cf7c05f8d88b689a&type=note&_time=1670997076862
  • 下载calico镜像压缩包,然后上传到每台linux主机
    • caliconodev3.24.3.tar.gz
    • https://note.youdao.com/ynoteshare/index.html?id=d2356b61a7406be37bb86f493ae5ba2e&type=note&_time=1670997126822
    • calicokubecontrollers~v3.24.3.tar.gz
    • https://note.youdao.com/ynoteshare/index.html?id=aed6620815c8fc8b7582f5b555c2229a&type=note&_time=1670997180220
    • calicocniv3.24.3.tar.gz
    • https://note.youdao.com/ynoteshare/index.html?id=0b434c123be173f5490e06d26a815d84&type=note&_time=1670997194778
  • 每台linux主机通过docker离线加载镜像
docker load -i calico~cni~v3.24.3.tar.gz
docker load -i calico~kube~controllers~v3.24.3.tar.gz
docker load -i calico~node~v3.24.3.tar.gz
  • 查看calico镜像是否加载成功
 docker images | grep calico
  • 在master节点执行命令进行calico插件安装
kubectl apply -f calico.yaml

查看节点情况

[root@k8s-master ~]# kubectl get node -o wide
NAME         STATUS   ROLES           AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION           CONTAINER-RUNTIME
k8s-master   Ready    control-plane   10h   v1.25.0   192.168.32.137   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://20.10.21
k8s-node-1   Ready    <none>          10h   v1.25.0   192.168.32.138   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://20.10.21
k8s-node-2   Ready    <none>          10h   v1.25.0   192.168.32.139   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://20.10.21

相关推荐

Whoosh,纯python编写轻量级搜索工具

引言在许多应用程序中,搜索功能是至关重要的。Whoosh是一个纯Python编写的轻量级搜索引擎库,可以帮助我们快速构建搜索功能。无论是在网站、博客还是本地应用程序中,Whoosh都能提供高效的全文搜...

如何用Python实现二分搜索算法(python二分法查找代码)

如何用Python实现二分搜索算法二分搜索(BinarySearch)是一种高效的查找算法,适用于在有序数组中快速定位目标值。其核心思想是通过不断缩小搜索范围,每次将问题规模减半,时间复杂度为(O...

路径扫描 -- dirsearch(路径查找器怎么使用)

外表干净是尊重别人,内心干净是尊重自己,干净,在今天这个时代,应该是一种极高的赞美和珍贵。。。----网易云热评一、软件介绍Dirsearch是一种命令行工具,可以强制获取web服务器中的目录和文件...

78行Python代码帮你复现微信撤回消息!

来源:悟空智能科技本文约700字,建议阅读5分钟。本文基于python的微信开源库itchat,教你如何收集私聊撤回的信息。...

从零开始学习 Python!2《进阶知识》 Python进阶之路

欢迎来到Python学习的进阶篇章!如果你说已经掌握了基础语法,那么这篇就是你开启高手之路的大门。我们将一起探讨面向对象编程...

白帽黑客如何通过dirsearch脚本工具扫描和收集网站敏感文件

一、背景介绍...

Python之txt数据预定替换word预定义定位标记生成word报告(四)

续接Python之txt数据预定替换word预定义定位标记生成word报告(一)https://mp.toutiao.com/profile_v4/graphic/preview?pgc_id=748...

假期苦短,我用Python!这有个自动回复拜年信息的小程序

...

Python——字符串和正则表达式中的反斜杠(&#39;\&#39;)问题详解

在本篇文章里小编给大家整理的是关于Python字符串和正则表达式中的反斜杠('\')问题以及相关知识点,有需要的朋友们可以学习下。在Python普通字符串中在Python中,我们用'\'来转义某些普通...

Python re模块:正则表达式综合指南

Python...

Python中re模块详解(rem python)

在《...

python之re模块(python re模块sub)

re模块一.re模块的介绍1.什么是正则表达式"定义:正则表达式是一种对字符和特殊字符操作的一种逻辑公式,从特定的字符中,用正则表达字符来过滤的逻辑。(也是一种文本模式;)2、正则表达式可以帮助我们...

MySQL、PostgreSQL、SQL Server 数据库导入导出实操全解

在数字化时代,数据是关键资产,数据库的导入导出操作则是连接数据与应用场景的桥梁。以下是常见数据库导入导出的实用方法及代码,包含更多细节和特殊情况处理,助你应对各种实际场景。一、MySQL数据库...

Zabbix监控系统系列之六:监控 mysql

zabbix监控mysql1、监控规划在创建监控项之前要尽量考虑清楚要监控什么,怎么监控,监控数据如何存储,监控数据如何展现,如何处理报警等。要进行监控的系统规划需要对Zabbix很了解,这里只是...

mysql系列之一文详解Navicat工具的使用(二)

本章内容是系列内容的第二部分,主要介绍Navicat工具的使用。若查看第一部分请见:...

取消回复欢迎 发表评论: