Centos7安装K8S

news2024/9/25 7:22:44

Centos7安装K8S


安装过程中没有出现的错误可以往下

根据以前一些博主写的博客,在小阳翻了不下几十篇博客之后,我果断是放弃了,于是找到了官网地址,然后也有

1. 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

2. 关闭 selinux(2,3根据自己情况选择哈)

sed -i 's/enforcing/disabled/' /etc/selinux/config 这个是永久关闭
setenforce 0 临时关闭是这个哟

3、关闭 swap

swapoff -a # 临时关闭
vim /etc/fstab # 永久关闭
#注释掉 /dev/mapper/centos-swap swap swap defaults 0 0 这行
然后呢
systemctl reboot #重启生效
free ‐m #查看下swap交换区是否都为0,如果都为0则swap关闭成功

4.给三台机器分别设置主机名

hostnamectl set‐hostname 主机名称
第一台:k8s-master 第二台:k8s-node1 第三台:k8s-node2

5.在 k8s-master机器添加hosts,注意ip地址哟
cat >> /etc/hosts << EOF
192.168.2.64 k8s-master
192.168.2.59 k8s-node1
192.168.2.51 k8s-node2
EOF
6.将桥接的IPv4流量传递到iptables
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

需要让它生效哈
sysctl --system

7.设置时间
yum install ntpdate -y
ntpdate -u ntp.api.bz
出现
21 Mar 17:07:17 ntpdate[3124]: adjust time server 114.118.7.161 offset 0.013776 sec
即为成功注意我的日期为2022321日,日期和你自己对上即可
8. yum源切换与yum k8s

此处有bug切记别着急复制粘贴,请往下看

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y kubelet kubeadm kubectl ------ 坑在这呢
systemctl enable kubelet && systemctl start kubelet #开机启动kubelet

ps: 由于官网未开放同步方式, 可能会有索引gpg检查失败的情况, 这时请用 yum install -y --nogpgcheck kubelet kubeadm kubectl 安装<<<<<<<<<这是官网写的字体老小了
这是报的错

https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno -1] repomd.xml signature could not be verified for kubernetes
Trying other mirror.


 One of the configured repositories failed (Kubernetes),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=kubernetes ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable kubernetes
        or
            subscription-manager repos --disable=kubernetes

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=kubernetes.skip_if_unavailable=true

failure: repodata/repomd.xml from kubernetes: [Errno 256] No more mirrors to try.

这是正确的配置

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y --nogpgcheck kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet

此处需要注意(9、10)均在k8s-master机器上执行指令

9.初始化

ip为master的ip地址,其次注意版本,剩下的无需改动

kubeadm init --apiserver-advertise-address=192.168.2.64 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.0 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16

这行执行的话需要注意至少两个cpu,就是红色框框里面的数字是个2就行
在这里插入图片描述
改完之后呢,有报错了/(ㄒoㄒ)/~~

[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost:10248/healthz": dial tcp [::1]:10248: connect: connection refused.
	Unfortunately, an error has occurred:
		timed out waiting for the condition
	This error is likely caused by:
		- The kubelet is not running
		- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
	If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
		- 'systemctl status kubelet'
		- 'journalctl -xeu kubelet'
	Additionally, a control plane component may have crashed or exited when started by the container runtime.
	To troubleshoot, list all containers using your preferred container runtimes CLI.
	Here is one example how you may list all Kubernetes containers running in docker:
		- 'docker ps -a | grep kube | grep -v pause'
		Once you have found the failing container, you can inspect its logs with:
		- 'docker logs CONTAINERID'
error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher

处理办法详见<<<此处有个超链接

当初始化完成之后出现红色框框即为初始化成功,下面的绿色框框为下来所需要执行的指令
在这里插入图片描述

10.配置 kubectl 命令工具
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

然后验证一下
kubectl get nodes

安装 Pod 网络插件
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
不成功的话
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kubeflannel.yml

那么此处需要在node节点的两台机器上执行这一行指令,这个指令就是上图初始化完成蓝色框框中的

kubeadm join 192.168.2.64:6443 --token bxtr03.7ekvjxxyx57dh2nz --discovery-token-ca-cert-hash sha256:5f41464af9fab2003b357d445a9927445e3ad540872b01e07bb3e85995a30e65

本小阳此处是报错了的
unexpected kernel config: CONFIG_CGROUP_PIDS

解决第一个error为以下指令
echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables
地址: https://blog.csdn.net/m0_47219942/article/details/110873272

剩下两个问题主要是内核版本过低导致的,详细可见CentOS7升级内核并启用BBR
此时已是开始搭建的一周后了,因为总是忘记,此时报的错误

error execution phase preflight: couldn't validate the identity of the API Server: could not find a JWS signature in the cluster-info ConfigMap for token ID "bxtr03"

Token过期,那么此时需要重新生成
https://blog.csdn.net/YouMing_Li/article/details/117553658
此时再次执行

kubeadm reset

之后重新加入主节点之后
在这里插入图片描述
此时的报错含义为

kubelet没有运行  
kubelet是不健康的,因为节点在某种程度上配置错误(需要禁用cgroups)  

此处结局方案,原文链接
在这里插入图片描述

然后呢

kubectl get nodes

在这里插入图片描述
上面红色框中的NotReady状态解决,链接

下面开始测试
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pod,svc -o wide

执行完需要注意端口号
在这里插入图片描述
完了之后三台机器都可以通过此端口访问到
在这里插入图片描述
此时已经完了哈
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1380296.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

算法通关村番外篇-LeetCode编程从0到1系列四

大家好我是苏麟 , 今天带来算法通关村番外篇-LeetCode编程从0到1系列四 . 矩阵 1672. 最富有客户的资产总量 描述 : 给你一个 m x n 的整数网格 accounts &#xff0c;其中 accounts[i][j] 是第 i​​​​​ 位客户在第 j 家银行托管的资产数量。返回最富有客户所拥有的 资产…

【UEFI基础】EDK网络框架(IP4)

IP4 IP4协议说明 IP全称Internet Protocol&#xff0c;它属于网络层&#xff0c;对其下各种类型的数据链路层进行了包装&#xff0c;这样网络层可以跨越不同的数据链路&#xff0c;即使是在不同的数据链路上也能实现两端节点之间的数据包传输。 IP层的主要作用就是“实现终端…

java应用CPU过高查找原因

用top查到占用cpu最高的进程pid 根据进程ID找到占用CPU高的线程 ps -mp 60355 -o THREAD,tid | sort -r 用 printf "%x \n" 将tid换为十六进制&#xff1a;xid printf "%x \n" 6036 根据16进制格式的线程ID查找线程堆栈信息 jstack 60355 |grep ebcb -A…

Fiddler怎么抓请求做接口

第一步:安装fiddler 可以在官网下载最新版本 VIP小伙伴可以在课前准备下载,如果已经安装,请忽略 打开fiddler开始抓取测试对象的请求,以教管系统登录为例 打开fiddler,准备开始抓取,清空会话,开启抓取状态,因为fiddler默认抓取http协议,所以这里不需要设置什么。 打开系统登…

Windows项目部署流程

一、部署前需要的工作 ①配置环境变量&#xff1a;将所需的软件和工具的安装路径添加到系统的环境变量中&#xff0c;以便在命令行中可以直接使用。 ②部署项目文件&#xff1a;将项目的文件和代码复制到服务器上的指定目录中&#xff0c;例如Web服务器的网站根目录。 ③配置…

idea使用谷歌翻译 有道翻译 百度翻译

中文版&#xff1a;文件——设置——工具——Translation&#xff0c;然后选择需要配置的翻译 英文版&#xff1a;File——settings——Tools——Translation&#xff0c;然后选择需要配置的翻译 谷歌翻译大家可以度娘直接搜索Google_translation_win 有道和百度翻译得去注册申…

什么是有机搜索引擎优化以及如何入门

什么是有机搜索引擎优化&#xff1f; 有机搜索引擎优化&#xff0c;简称 SEO&#xff0c;是指从搜索引擎的无偿搜索结果中增加网站流量的做法。 未付费搜索结果是获得的列表&#xff0c;而不是付费的。 这样做的目的是让您的网页在与您业务相关的未付费搜索结果中排名靠前。…

Spring自带分布式锁你用过吗?

环境&#xff1a;SpringBoot2.7.12 本篇文章将会为大家介绍有关spring integration提供的分布式锁功能。 1. 简介 Spring Integration 是一个框架&#xff0c;用于构建事件驱动的应用程序。在 Spring Integration 中&#xff0c;LockRegistry 是一个接口&#xff0c;用于管理…

无需任何三方库,在 Next.js 项目在线预览 PDF 文件

前言&#xff1a; 之前在使用Vue和其它框架的时候&#xff0c;预览 PDF 都是使用的 PDFObject 这个库&#xff0c;步骤是&#xff1a;下载依赖&#xff0c;然后手动封装一个 PDF 预览组件&#xff0c;这个组件接收本地或在线的pdf地址&#xff0c;然后在页面中使用组件的车时候…

黑马程序员 Docker笔记

本篇学习笔记文档对应B站视频&#xff1a; 暂时无法在飞书文档外展示此内容 同学们&#xff0c;在前两天我们学习了Linux操作系统的常见命令以及如何在Linux上部署一个单体项目。大家想一想自己最大的感受是什么&#xff1f; 我相信&#xff0c;除了个别天赋异禀的同学以外&a…

学习笔记-mysql基础(DDL,DML,DQL)

一.DDL DDL,Data Definition Language,数据库定义语言,该语言包括以下内容: 对数据库的常用操作对表结构的常用操作修改表结构 1.对数据库的常用操作 -- 查看所有的数据库 show databases -- 创建数据库 create database [if not exists] test [charsetutf8] -- 切换 选择 …

如何判断 vite 的运行环境是开发模式还是生产模式 production? development?

如何判断 vite 的运行环境是开发模式还是生产模式 production&#xff1f; development&#xff1f; vite 有两种获取当前运行环境模式的方法&#xff1a; 官方说明&#xff1a; 完整说明地址&#xff1a; https://cn.vitejs.dev/guide/env-and-mode.html#node-env-and-modes…

Netty开篇——NIO章上(三)

Java NIO基本介绍 java non-blocking I/O 称为NIO(也叫New IO)。JDK4开始提供,同步非阻塞相关内容在 java.nio 包及子包下&#xff0c;对java.io 包中的很多类进行改写。三大核心: Channel(通道)&#xff0c;Buffer(缓冲区),Selector(选择器)NIO是面向缓冲区或者面向块编程的。…

使用Java连接MongoDB (6.0.12) 报错

报错&#xff1a; Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 352: Unsupported OP_QUERY command: create. 上图中“The client driver may require an upgrade”说明了“客户端驱动需要进行升级”&#xff0c;解…

【昕宝爸爸小模块】如何让Java的线程池顺序执行任务

➡️博客首页 https://blog.csdn.net/Java_Yangxiaoyuan 欢迎优秀的你&#x1f44d;点赞、&#x1f5c2;️收藏、加❤️关注哦。 本文章CSDN首发&#xff0c;欢迎转载&#xff0c;要注明出处哦&#xff01; 先感谢优秀的你能认真的看完本文&…

【Python数据可视化】matplotlib之设置坐标:添加坐标轴名字、设置坐标范围、设置主次刻度、坐标轴文字旋转并标出坐标值

文章传送门 Python 数据可视化matplotlib之绘制常用图形&#xff1a;折线图、柱状图&#xff08;条形图&#xff09;、饼图和直方图matplotlib之设置坐标&#xff1a;添加坐标轴名字、设置坐标范围、设置主次刻度、坐标轴文字旋转并标出坐标值matplotlib之增加图形内容&#x…

进程的创建与回收学习笔记

目录 一、进程内容&#xff1a; 二、进程常用命令 三、创建子进程 四、子进程进阶 五、进程的退出 六、进程的回收 一、进程内容&#xff1a; 程序&#xff1a; 存放在磁盘上的指令和数据的有序集合&#xff08;文件&#xff09; 静态的 进程&#xff1a; 执行一个程序所…

仓储库房温湿度监测解决方案——福建蜂窝物联

一、背景 1.1 现状 在实际应用中&#xff0c;仓储对环境变化非常敏感。例如医药行业中的冷库主要存放需要低温保存的试剂或物品&#xff0c;一旦温度、湿度发生变化&#xff0c;容易影响到产品质量。对于现在很多大型工厂或者物流基地来说&#xff0c;仓库无疑是存放物品的重…

Linux 内核学习 2 - 用户程序如何被塞进内核进行调度?

Shell是系统的用户界面&#xff0c;提供了用户与内核进行交互操作的一种接口。它接收用户输入的命令并把它送入内核去执行。 fork里copy了父进程的信息&#xff0c;并激活task放到运行队列&#xff0c;当系统发生调度并获得执行机会时开始执行&#xff0c;但这时还不是hello程序…

LeetCode讲解篇之47. 全排列 II

文章目录 题目描述题解思路题解代码 题目描述 题解思路 初始化一个nums中元素是否被访问的数组used、记录还需要递归的深度deep&#xff0c;遍历nums&#xff0c;如果当前元素被访问过或者当前元素等于前一个元素且前一个元素没被访问过就跳过该次遍历&#xff0c;否则选择当前…