前置操作:Kubernetes快速安装组件Kubectl Kubeadam Kubeinit

news2024/7/4 5:10:30

文章目录

  • 配置K8S主从集群前置准备操作
  • 一:主节点操作 查看主机域名->编辑域名
    • 1.1 编辑HOST 从节点也做相应操作
    • 1.2 从节点操作 查看从节点102域名->编辑域名
    • 1.3 从节点操作 查看从节点103域名->编辑域名
  • 二:安装自动填充,虚拟机默认没有
  • 三:关闭防火墙
  • 四:关闭交换空间
  • 五:禁用 Selinux
  • 六: 允许 ip tables 检查桥接流量
  • 七:设置K8S相关系统参数
    • 7.1:配置Docker 阿里源
    • 7.2:添加阿里云 k8s 镜像仓库
    • 7.3:安装 k8s 1.14.0 所需依赖
      • 7.3.1:设置所 sysctl 参数,重新启动后配置不变
      • 7.3.2:应用 sysctl 参数而不重新启动
  • 八:安装K8S -- kubelet,kubeadm,kubectl核心组件
    • 8.1:安装命令
    • 8.2:查看服务状态
    • 8.3:发现异常 "command failed" err="failed to load kubelet config file(注意:此异常和主从节点配置有关,放在后面解决)
      • 8.3.1:查看具体报错
    • 8.3.2: 发现异常 Flag --cgroup-driver has been deprecated, This parameter should be set via the config file
    • 8.4:针对上述异常操作如下
      • 8.4.1: 修改docker cgroup驱动
      • 8.4.2:配置网络,选择 Calico
    • 8.5: 下载相关操作
      • 8.5.1:安装wget
      • 8.5.2:下载网络
      • 8.5.3:修改 calico.yaml
      • 8.5.4:配置K8S 网络
  • 九:再次查看 pods,nodes
    • 9.1:注意异常: The connection to the server localhost:8080 was refused(和主从节点有关,先kubeinit没问题)
    • 9.2:解决方式
    • 9.3:再次执行抛异常处的命令 kubeadm init
    • 9.4:注意异常 hostname和 CRI v1 runtime API
    • 9.5:解决 kubeadm init 相关异常
      • 9.5.1:编辑vim /etc/hosts
      • 9.5.2:ps aux | grep docker | grep -v grep
      • 9.5.3:cat /etc/containerd/config.toml
      • 9.5.4:rm -fr /etc/containerd/config.toml
      • 9.5.5:systemctl restart containerd
      • 9.5.6:systemctl status containerd.service
  • 十:解决 & 再次执行kubeadm init 查看
    • 10.1:执行kubeadm init

配置K8S主从集群前置准备操作

一:主节点操作 查看主机域名->编辑域名

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname nodemaster
[root@localhost ~]# hostname
nodemaster
[root@localhost ~]#

1.1 编辑HOST 从节点也做相应操作

[root@vbox-master-01-vbox-01 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.101  master-k8s-vbox

1.2 从节点操作 查看从节点102域名->编辑域名

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname nodeslavetwo
[root@localhost ~]# hostname
nodeslavetwo

1.3 从节点操作 查看从节点103域名->编辑域名

[root@localhost /]# hostname
localhost.localdomain
[root@localhost /]# hostnamectl set-hostname nodeslavethree
[root@localhost /]# hostname
nodeslavethree

二:安装自动填充,虚拟机默认没有

[root@vbox-master-01-vbox-01 ~]# yum -y install bash-completion
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Determining fastest mirrors
 * base: ftp.sjtu.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.aliyun.com

三:关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

四:关闭交换空间

free -h
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
free -h

五:禁用 Selinux

sed -i “s/^SELINUX=enforcing/SELINUX=disabled/g” /etc/sysconfig/selinux

[root@nodemaster /]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux

六: 允许 ip tables 检查桥接流量

iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT

七:设置K8S相关系统参数

cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

7.1:配置Docker 阿里源

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://hnkfbj7x.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

7.2:添加阿里云 k8s 镜像仓库

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

7.3:安装 k8s 1.14.0 所需依赖

7.3.1:设置所 sysctl 参数,重新启动后配置不变

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

7.3.2:应用 sysctl 参数而不重新启动

sudo sysctl --system

八:安装K8S – kubelet,kubeadm,kubectl核心组件

8.1:安装命令

yum install -y kubelet-1.25.5-0 kubeadm-1.25.5-0 kubectl-1.25.5-0 --disableexcludes=kubernetes --nogpgcheck

8.2:查看服务状态

systemctl status kubelet

8.3:发现异常 “command failed” err="failed to load kubelet config file(注意:此异常和主从节点配置有关,放在后面解决)

"command failed" err="failed to load kubelet config file, error: failed to load Kubelet config file /var/lib/kubelet/config.yaml, error failed to read kubelet config file \"/var/lib/kubelet/config.yaml\", error: open /var/lib/kubelet/config.yaml: no such file or directory, path: /var/lib/kubelet/config.yaml"

8.3.1:查看具体报错

journalctl -u kubelet.service

8.3.2: 发现异常 Flag --cgroup-driver has been deprecated, This parameter should be set via the config file

Flag --cgroup-driver has been deprecated, This parameter should be set via the config file

 Unable to update cni config: no networks found i

在这里插入图片描述

8.4:针对上述异常操作如下

8.4.1: 修改docker cgroup驱动

cat > /etc/docker/daemon.json <<EOF
{"exec-opts": ["native.cgroupdriver=systemd"]}
EOF
[root@vbox-master-01-vbox-01 ~]# cat > /etc/docker/daemon.json <<EOF
> {"exec-opts": ["native.cgroupdriver=systemd"]}
> EOF
[root@vbox-master-01-vbox-01 ~]#

8.4.2:配置网络,选择 Calico

8.5: 下载相关操作

8.5.1:安装wget

yum -y install wget

8.5.2:下载网络

wget --no-check-certificate https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml

8.5.3:修改 calico.yaml

yum -y install vim-enhanced
vim calico.yaml

 # 在 - name: CLUSTER_TYPE 下方添加如下内容
- name: CLUSTER_TYPE
  value: "k8s,bgp"
  # 下方为新增内容
- name: IP_AUTODETECTION_METHOD
  value: "interface=网卡名称"


# INTERFACE_NAME=ens33
# sed -i '/k8s,bgp/a \            - name: IP_AUTODETECTION_METHOD\n              value: "interface=INTERFACE_NAME"' calico.yaml
# sed -i "s#INTERFACE_NAME#$INTERFACE_NAME#g" calico.yaml

8.5.4:配置K8S 网络

kubectl apply -f calico.yaml

九:再次查看 pods,nodes

kubectl get nodes -o wide

9.1:注意异常: The connection to the server localhost:8080 was refused(和主从节点有关,先kubeinit没问题)

[root@vbox-master-01-vbox-01 ~]# kubectl apply -f calico.yaml
The connection to the server localhost:8080 was refused - did you specify the right host or port?

9.2:解决方式

cd /etc/kubernetes/
echo “export KUBECONFIG=/etc/kubernetes/kubelet.conf” >> /etc/profile
source /etc/profile

[root@vbox-master-01-vbox-01 ~]# kubectl apply -f calico.yaml
The connection to the server localhost:8080 was refused - did you specify the right host or port?
[root@vbox-master-01-vbox-01 ~]#
[root@vbox-master-01-vbox-01 ~]# cd /etc/kubernetes/
[root@vbox-master-01-vbox-01 kubernetes]# echo "export KUBECONFIG=/etc/kubernetes/kubelet.conf" >> /etc/profile
[root@vbox-master-01-vbox-01 kubernetes]#
[root@vbox-master-01-vbox-01 kubernetes]# source /etc/profile
[root@vbox-master-01-vbox-01 kubernetes]#

9.3:再次执行抛异常处的命令 kubeadm init

kubeadm init

9.4:注意异常 hostname和 CRI v1 runtime API

[WARNING Hostname]: hostname "vbox-master-01-vbox-01": lookup vbox-master-01-vbox-01 on 192.168.1.1:53: no such host

error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR CRI]: container runtime is not running: output: time="2023-05-02T02:16:37+08:00" level=fatal msg="validate service connection: CRI v1 runtime API is not implemented for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"
, error: exit status 1

9.5:解决 kubeadm init 相关异常

9.5.1:编辑vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.101  vbox-master-01-vbox-01

9.5.2:ps aux | grep docker | grep -v grep

9.5.3:cat /etc/containerd/config.toml

查看到disabled_plugins = [“cri”]
在这里插入图片描述

9.5.4:rm -fr /etc/containerd/config.toml

9.5.5:systemctl restart containerd

9.5.6:systemctl status containerd.service

[root@vbox-master-01-vbox-01 /]# systemctl status containerd.service
● containerd.service - containerd container runtime
   Loaded: loaded (/usr/lib/systemd/system/containerd.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2023-05-02 03:06:09 CST; 2min 35s ago
     Docs: https://containerd.io
  Process: 20008 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
 Main PID: 20010 (containerd)
    Tasks: 45
   Memory: 117.1M
   CGroup: /system.slice/containerd.service
           ├─11977 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 82a64934d6d49e4a3b55883f2fa3c959a1d16f091133644c2f2ab75de46ec09e -address ...
           ├─12134 /usr/bin/containerd-shim-runc-v2 -namespace moby -id f0d1f44c6dd8bb6015af52737aaebcdec2a35f6df0ff7d538c399c19bc622a41 -address ...
           ├─13051 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 6de7f49404eb3aa5ea14e02405c973bc850217a519a8b3a85bf47bf8aae23e2d -address ...
           └─20010 /usr/bin/containerd

502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.691263973+08:00" level=error msg="failed to load cni du...onfig"
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.691710874+08:00" level=info msg=serving... address=/run....ttrpc
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.691797968+08:00" level=info msg=serving... address=/run...d.sock
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.691949132+08:00" level=info msg="containerd successfull...1014s"
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.705709657+08:00" level=info msg="Start subscribing cont...event"
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.705803917+08:00" level=info msg="Start recovering state"
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.705874098+08:00" level=info msg="Start event monitor"
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.705891342+08:00" level=info msg="Start snapshots syncer"
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.705900497+08:00" level=info msg="Start cni network conf...fault"
502 03:06:09 vbox-master-01-vbox-01 containerd[20010]: time="2023-05-02T03:06:09.705907733+08:00" level=info msg="Start streaming server"
Hint: Some lines were ellipsized, use -l to show in full.

十:解决 & 再次执行kubeadm init 查看

10.1:执行kubeadm init

[root@vbox-master-01-vbox-01 kubernetes]# kubeadm init
I0502 02:25:08.004988   18148 version.go:256] remote version is much newer: v1.27.1; falling back to: stable-1.25
[init] Using Kubernetes version: v1.25.9
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'

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

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

相关文章

对接ChatGPT开发对话机器人小程序

前言 ChatGPT已经非常火爆了&#xff0c;企业开始招聘ChatGPT工程师&#xff0c;可能对接ChatGPT接口进行企业级开发是程序员必备的技能了。本篇文章主要是基于ChatGPT开发接口进行对接&#xff0c;使用微信小程序制作一款自己的聊天机器人&#xff0c;通过这一案例你可以展开…

图神经网络:在KarateClub上动手实现图神经网络

文章说明&#xff1a; 1)参考资料&#xff1a;PYG官方文档。超链。 2)博主水平不高&#xff0c;如有错误还望批评指正。 3)我在百度网盘上传了这篇文章的jupyter notebook。超链。提取码8888。 文章目录 文献阅读&#xff1a;代码实操&#xff1a; 文献阅读&#xff1a; 参考文…

JavaWeb05(删除增加修改功能实现连接数据库)

目录 一.实现删除功能 1.1 url如何传参&#xff1f; xx.do?参数参数值&参数名参数值 1.2 servlet如何拿对应值&#xff1f; //根据参数名拿到对应的参数值 String str req.getParameter("参数名") 1.3 如何询问&#xff1f; οnclick"return con…

区位码-GB2312

01-09区为特殊符号 10-15区为用户自定义符号区&#xff08;未编码&#xff09; 16-55区为一级汉字&#xff0c;按拼音排序 56-87区为二级汉字&#xff0c;按部首/笔画排序 88-94区为用户自定义汉字区&#xff08;未编码&#xff09; 特殊符号 区号:01 各类符号 0 1 2 3 4 …

I/O多路转接——epoll服务器代码编写

目录 一、poll​ 二、epoll 1.epoll 2.epoll的函数接口 ①epoll_create ②epoll_ctl ③epoll_wait 3.操作原理 三、epoll服务器编写 1.日志打印 2.TCP服务器 3.Epoll ①雏形 ②InitEpollServer 与 RunServer ③HandlerEvent 四、Epoll的工作模式 1.LT模式与ET…

第二十一章 光源

光源是每个场景必不可少的部分&#xff0c;光源除了能够照亮场景之外&#xff0c;还可以产生阴影效果。 Unity中分为四种光源类型&#xff1a; 1. 方向光&#xff1a;Directional Light 用于模拟太阳光&#xff0c;方向光任何地方都能照射到。 2. 点光源&#xff1a;Point L…

JavaWeb-Servlet【内含思维导图】

目录 Servlet思维导图​编辑 1.什么是Servlet 2.Servelt概述 3.Servlet-Quickstart Your Project 3.1创建一个Web项目&#xff0c;导入Servlet依赖 3.1.1 选择Servlet导入依赖 3.1.2 导入Servlet依赖 3.2 在Web项目&#xff0c;定义类&#xff0c;实现Servlet接口…

Java8新特性-流式操作

在Java8中提供了新特性—流式操作&#xff0c;通过流式操作可以帮助我们对数据更快速的进行一些过滤、排序、去重、最大、最小等等操作并且内置了并行流将流划分成多个线程进行并行执行&#xff0c;提供更高效、快速的执行能力。接下来我们一起看看Java8为我们新增了哪些便捷呢…

Python基础合集 练习19(类与对象3(多态))

多态 class Horse: def init(self, name) -> None: self.name name def fature(self):return 父亲-----马的名字: {0}.format(self.name)def mover(self):print(马儿跑起来很潇洒)class Monkey: def init(self, name) -> None: self.name name def fature(self):ret…

《用于准确连续非侵入性血压监测的心跳内生物标志物》阅读笔记

目录 0 基础知识 1 论文摘要 2 论文十问 3 实验结果 4 论文亮点与不足之处 5 与其他研究的比较 6 实际应用与影响 7 个人思考与启示 参考文献 0 基础知识 非侵入性是指在进行医学检查或治疗时&#xff0c;不需要切开皮肤或穿刺体内组织&#xff0c;而是通过外部手段进…

【VQGAN论文精读】Taming Transformers for High-Resolution Image Synthesis

【VQGAN论文精读】Taming Transformers for High-Resolution Image Synthesis 0、前言Abstract1. Introduction2. Related Work3. Approach3.1. Learning an Effective Codebook of Image Constituents for Use in Transformers学习一个有效的图像成分的Codebook为了在Transfor…

高性能:负载均衡

目录 什么是负载均衡 负载均衡分类 服务端负载均衡 服务端负载均衡——软硬件分类 服务端负载均衡——OSI模型分类 客户端负载均衡 负载均衡常见算法 七层负载均衡做法 DNS解析 反向代理 什么是负载均衡 将用户请求分摊&#xff08;分流&#xff09; 到不同的服务器上…

小记Java调用C++开发的动态链接库(DLL)

一、背景 五一快乐吖&#xff01;死肥宅正趁着五一这段时间&#xff0c;努力提升自己&#xff01; 最近使用Java拦截Windows系统中一些默认事件时&#xff0c;发现了一些瓶颈。 我用Java操作浏览器、用Java最小化其他应用窗口&#xff0c;但是我发现这个操作&#xff0c;他都…

【Unity-UGUI控件全面解析】| InputField 输入框组件详解

🎬【Unity-UGUI控件全面解析】| InputField 输入框组件详解一、组件介绍二、组件属性面板2.1 Content Type(内容类型)三、代码操作组件四、组件常用方法示例4.1 代码限制输入字符4.2 校验文本输入格式4.3 校验输入文本长度💯总结🎬 博客主页:https://xiaoy.blog.csdn.…

话说【永恒之塔sf】里面最有前途的职业:商人

如果有人问我永恒之塔里面什么职业最有前途&#xff01;那我告诉你就是商人&#xff01; 做一个NB商人比拥有一身牛b装备要更有成就感。 在老区由于进入的比较晚&#xff0c;所以最后随了大流被淹死在千万基纳中。为了证明商人在永恒之塔是钱途无量的&#xff0c;我转到了新区—…

快解析动态域名解析,实现外网访问内网数据库

今天跟大家分享一下如何借助快解析动态域名解析&#xff0c;在两种特定网络环境下&#xff0c;实现外网访问内网mysql数据库。 第1种网络环境&#xff1a;路由器分配的是动态公网IP&#xff0c;且有路由器登录管理权限。如何实现外网访问内网mysql数据库&#xff1f; 针对这种…

IDEA2022版教程上()

0、前景摘要 0.1 概览 0.2 套课程适用人群 初学Java语言&#xff0c;熟悉了记事本、EditPlus、NotePad或Sublime Text3等简易开发工具的Java初学者熟练使用其他Java集成开发环境&#xff08;IDE&#xff09;&#xff0c;需要转向IDEA工具的Java工程师们关注IDEA各方面特性的J…

Hadoop大数据分析技术(伪分布式搭建)

一.安装JDK和配置SSH免密登录 &#xff08;1&#xff09;准备软件 &#xff08;2&#xff09;解压压缩包 tar -zxvf jdk-8u221-linux-x64.tar.gz &#xff08;3&#xff09;在此处我们配置系统环境变量&#xff0c;使用命令&#xff1a; vim /etc/profile &#xff08;4&#x…

Python入门教程(高级版)

Python用了好几年了&#xff0c;但似乎一直没 “系统入门” 过&#xff08;o(╯□╰)o&#xff09;。今年&#xff08;2023年&#xff09;趁着五一假期&#xff0c;我做了一次相对完整的 “入门” ——本文是这次学习历程的详细记录。 目录 1 Python基础1.1 Python1.1.1 认识Py…

Oracle VM VirtualBox安装centos7步骤 for win10

目录 1.安装VirtualBox 2.安装vagrant 3.安装centos7 4.查看网络与百度和物理机连通情况 5.设置IP 1.安装VirtualBox 下载的链接:Downloads – Oracle VM VirtualBox 2.安装vagrant 根据自己的操作系统选择对应的版本。 Install | Vagrant | HashiCorp Developer 我的P…