Centos7安装K8S

这篇具有很好参考价值的文章主要介绍了Centos7安装K8S。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

centos7 安装k8s node,kubernetes

此处需要注意(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就行
centos7 安装k8s node,kubernetes
改完之后呢,有报错了/(ㄒ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

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

当初始化完成之后出现红色框框即为初始化成功,下面的绿色框框为下来所需要执行的指令
centos7 安装k8s node,kubernetes

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

本小阳此处是报错了的
centos7 安装k8s node,kubernetes

解决第一个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

之后重新加入主节点之后
centos7 安装k8s node,kubernetes
此时的报错含义为

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

此处结局方案,原文链接
centos7 安装k8s node,kubernetes

然后呢

kubectl get nodes

centos7 安装k8s node,kubernetes
上面红色框中的NotReady状态解决,链接

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

执行完需要注意端口号
centos7 安装k8s node,kubernetes
完了之后三台机器都可以通过此端口访问到
centos7 安装k8s node,kubernetes
此时已经完了哈
centos7 安装k8s node,kubernetes文章来源地址https://www.toymoban.com/news/detail-795597.html

到了这里,关于Centos7安装K8S的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Centos7安装部署k8s(kubernetes)最新v1.27.1版本超详细安装教程

    从零开始的k8s安装 硬件配置要求 cpu = 2核 硬盘 = 20G 内存 = 2G 节点数量建议为奇数(3, 5, 7, 9等)(1台好像也能搭,没试过) 以下命令出除特殊要求外,其余都建议在master主机执行 本教程配置如下 主机名 IP 配置 master 192.168.42.150 2核+2G+20G node1 192.168.42.151 2核+2G+20G node2 192.168.

    2024年02月11日
    浏览(47)
  • m1使用VMware安装CentOS7并部署k8s高可用集群

    项目 版本 处理器 Apple M1 Max 操作系统 macOS Ventura 13.0 虚拟机应用 VMware Fusion 专业版 12.2.3 虚拟机操作系统 CentOS Linux 7 (AltArch) 容器运行时版本 docker 1.13.1 集群版本 Kubernetes 1.21.0 2.1 安装 VMware 安装包下载地址:VMware Fusion 专业版 12.2.3 应用许可证问题请自行解决 2.2 安装虚拟机 2.

    2024年02月02日
    浏览(38)
  • 基于centos7的k8s最新版v1.29.2安装教程

    Kubernetes 是一个可移植、可扩展的开源平台,用于管理容器化的工作负载和服务,可促进声明式配置和自动化。 Kubernetes 拥有一个庞大且快速增长的生态,其服务、支持和工具的使用范围相当广泛。 Kubernetes  这个名字源于希腊语,意为“舵手”或“飞行员”。k8s 这个缩写是

    2024年03月18日
    浏览(47)
  • k8s 安装 kubernetes安装教程 虚拟机安装k8s centos7安装k8s kuberadmin安装k8s k8s工具安装 k8s安装前配置参数

    k8s采用master, node1, node2 。三台虚拟机安装的一主两从,机器已提前安装好docker。下面是机器配置,k8s安装过程,以及出现的问题与解决方法   虚拟机全部采用静态ip, master 30机器, node1 31机器, node2 32机器                                        机器ip 192.168.

    2024年02月11日
    浏览(42)
  • Centos7部署单机版K8S

    2024年02月04日
    浏览(41)
  • VMWare中Centos7部署K8S集群

    关于我们要搭建的K8S: Docker版本:docker-ce-19.03.9; K8S版本:1.20.2; 三个节点:master、node1、node2(固定IP); 容器运行时:仍然使用Docker而非Containerd; Pod网络:用Calico替换Flannel实现 Pod 互通,支持更大规模的集群; 集群构建工具:Kubeadm(这个没啥好说的吧); 关于网络配

    2024年02月15日
    浏览(37)
  • centos7搭建k8s环境并部署springboot项目

    之前看了很多文章,都是部署后一直报错,百度解决后下次又忘了,这次决定把从头到尾的过程记录下来方便下次再看 ,部署参考文章尚硅谷Kubernetes(k8s)视频学习笔记_尚硅谷k8s笔记_溯光旅者的博客-CSDN博客 1、先去下载vmware虚拟机安装,我安装的是这个版本VMware Workstati

    2024年02月03日
    浏览(34)
  • CentOS7使用kubeadm部署k8s-1.28集群

    参考资料:生产环境 记录使用CentOS7.9进行k8s-1.28版本部署,运行时环境使用containerd,网络插件使用calic,集群搭建完成后。搭建NFS共享存储环境,测试运行pod并挂载使用持久卷。 主机名 **IP地址 ** 角色 基础组件 el7-linux-node-01 192.168.240.11 k8s-master kubeadm,kubelet,kubectl,containerd,nf

    2024年04月26日
    浏览(37)
  • CentOS7(Linux)详细安装教程(手把手图文详解版)_centos7安装教程

    3、选择合适版本的镜像进行下载 选择合适的存放地址(这里的地址包含中文名称我用起来好像也没出啥问题,如果怕出错的同学可以使用全英文) 1、打开我们的虚拟机(VMware Workstation),点击文件进行新建 2、选择典型之后,下一步 3、选择稍会安装操作系统 4、因为安装的

    2024年04月29日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包