香橙派4LTS和树莓派4B构建K8S集群实践之一:K8S安装

目录

1. 说明

1.1 软硬件环境

1.2 设计目标

2 实现

2.1 准备工作

- 香橙派 (k8s-master-1)

- 树莓派 (k8s-node-1)

- 两派都要干的事

2.2 containerd 安装与设置

2.3 安装 

3 遇到的问题

3.1 k8s-master-1

3.2 k8s-node-1 

4 相关命令

5 Tips

6 参考


1. 说明

1.1 软硬件环境

香橙派4LTS: 命名 k8s-master-1 / 192.168.0.106 / Ubuntu 22.04, 4G / 125G SD卡
树莓派4B : 命名 k8s-node-1 / 192.168.0.104 / Raspi OS(Debian 11), 4G / 64G SD卡

1.2 设计目标

  • 实现K8s集群 (基于containerd V1.62和K8s V1.27)
  • 在其上部署MariaDB Galera Cluster集群

2 实现

2.1 准备工作

- 香橙派 (k8s-master-1)

#加源

cat > /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse 
EOF

 #添加加载的内核模块

tee /etc/modules-load.d/containerd.conf<<EOF
overlay
br_netfilter
EOF

 #加载内核模块

modprobe overlay && modprobe br_netfilter

 #设置并应用内核参数

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

sysctl --system

- 树莓派 (k8s-node-1)

#加源

cat > /etc/apt/sources.list <<EOF
#将文件内容用以下内容替换,换上科大源
deb https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian buster main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian buster-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security buster/updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian-security/ buster/updates main non-free contrib
#将文件内容用以下内容替换,换上清华源(针对aarch64用户)
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
EOF

- 两派都要干的事

  修改/etc/hosts文件

192.168.0.106 k8s-master-1
192.168.0.104 k8s-node-1
199.232.28.133 raw.githubusercontent.com # 以便kubectl apply时能找到

加k8s源 

curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat > /etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF

 检查更新及安装更新

apt update
apt upgrade -y

 安装所需附件

apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates

2.2 containerd 安装与设置

#启用 docker 存储库

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
# 支持x86架构64位cpu
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# 支持arm64架构cpu
add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update && apt install -y containerd.io

#生成containerd的配置文件

containerd config default | tee /etc/containerd/config.toml >/dev/null 2>&1

 #修改cgroup Driver为systemd

sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

 #将镜像源设置为阿里云 google_containers 镜像源

sed -i 's/k8s.gcr.io/registry.aliyuncs.com\/google_containers/g' /etc/containerd/config.toml
systemctl daemon-reload
systemctl start containerd
systemctl enable containerd.service

2.3 安装 

临时关闭Swap, 在我的香橙派中,重启后swap分区又会出来,(试过很多方法都不行),简直是打不死的小强,后期在配置文件(/etc/systemd/system/kubelet.service.d/10-kubeadm.conf)中添加参数--fail-swap-on=false解决,参看遇到的问题一节

# swapoff -a         # 临时关闭
# sed -ri 's/.*swap.*/#&/' /etc/fstab    # 没啥用
apt -y install kubeadm kubelet kubectl # 按最新的来玩

# 固定版本不更新(暂时如此,免得出幺蛾子)
apt-mark hold kubelet kubeadm kubectl 
systemctl enable kubelet.service

# 加入环境变量
echo "export KUBECONFIG=/etc/kubernetes/kubelet.conf" >> /etc/profile
source /etc/profile

master server初始化 (node不需要走init),这里用了区域镜像,否则等到猴年马月..

kubeadm init --apiserver-advertise-address=192.168.0.106 --pod-network-cidr=10.244.0.0/16 \
 --image-repository registry.aliyuncs.com/google_containers 

node 加入 

# 成功后,会得到与token一起的加入提示命令, 在node1运行之
kubeadm join 192.168.0.106:6443 --token {xxx} \
        --discovery-token-ca-cert-hash sha256:{yyy}


[preflight] Running pre-flight checks
        [WARNING SystemVerification]: missing optional cgroups: hugetlb
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

  这时的集群都是NotReady状态的

kubectl get nodes
NAME           STATUS     ROLES                  AGE     VERSION
k8s-master-1   NotReady   control-plane,master   8m15s   v1.27.1
k8s-node-1     NotReady   <none>                 2m30s   v1.27.1

在k8s-master-1上安装 Flannel 网络插件

export KUBECONFIG=/etc/kubernetes/admin.conf

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

几经周折,完成nodes and pods为running状态,乌拉! 

安装Helm

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh

3 遇到的问题

3.1 k8s-master-1

- 如果删除不了swap交换分区,则kubelet服务会启动不来,由于K8s1.21后的版本能支持swap,所以调整参数(--fail-swap-on=false) 即可,设置方法:

cat /etc/systemd/system/kubelet.service.d/10-kubeadm.conf 
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS --fail-swap-on=false

在启动命令末尾加上: --fail-swap-on=false ,然后reload配置
systemctl daemon-reload
systemctl start kubelet

-  "The connection to the server localhost:8080 was refused - did you specify the right host or port?" 

cd /etc/kubernetes/

查看到有个文件:kubelet.conf, 执行命令
echo "export KUBECONFIG=/etc/kubernetes/kubelet.conf" >> /etc/profile
source /etc/profile

再次查看 kubectl get pods 已经正常。

原因: kubernetes master没有与本机绑定,集群初始化的时候没有绑定,此时设置在本机的环境变量即可解决问题。

3.2 k8s-node-1 

 - 加入时,遇到提示:CGROUPS_MEMORY: missing,

解决办法:编辑 /boot/cmdline.txt,加入:

cgroup_enable=memory cgroup_memory=1

Node为NotReady状态, 日志提示:"Unable to update cni config: No networks found in /etc/cni/net.d"

解决办法: 删除 --network-plugin=cni

nano /var/lib/kubelet/kubeadm-flags.env

# KUBELET_KUBEADM_ARGS="--network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.6"
=>
KUBELET_KUBEADM_ARGS="--pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.6"

 "The following signatures couldn't be verified because the public key is not available: {key}"

解决办法

gpg --keyserver keyserver.ubuntu.com --recv  {key}
gpg --export --armor  {key} | sudo apt-key add -

 "container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized"

解决办法: CNI is not initialized in k8s v1.16.4 · Issue #1236 · flannel-io/flannel · GitHub

cat <<EOL > /etc/cni/net.d/10-flannel.conflist 
{
  "name": "cbr0",
  "cniVersion": "0.3.1",
  "plugins": [
    {
      "type": "flannel",
      "delegate": {
        "hairpinMode": true,
        "isDefaultGateway": true
      }
    },
    {
      "type": "portmap",
      "capabilities": {
        "portMappings": true
      }
    }
  ]
}
EOL

 "Failed to create pod sandbox: open /run/systemd/resolve/resolv.conf: no such file or directory"

解决办法

systemctl enable systemd-resolved.service
systemctl start systemd-resolved

 "failed to pull image \"registry.k8s.io/pause:"

解决方法:

查看日志 journalctl -xeu kubelet
### 生成 containerd 的默认配置文件
containerd config default > /etc/containerd/config.toml 
### 查看 sandbox 的默认镜像仓库在文件中的第几行 
cat /etc/containerd/config.toml | grep -n "sandbox_image"  
### 使用 vim 编辑器 定位到 sandbox_image,将 仓库地址修改成 k8simage/pause:3.6
vim /etc/containerd/config.toml  
sandbox_image = "k8simage/pause:3.6"  
### 重启 containerd 服务  
systemctl daemon-reload  
systemctl restart containerd 

操作时发现当前用户不是 kubernetes-admin@kubernetes, "Error from server (Forbidden): pods "kube-proxy-zvkbq" is forbidden: User "system:node:k8s-master-1" cannot get resource "pods/log" in API group "" in the namespace "kube-system"

export KUBECONFIG=/etc/kubernetes/admin.conf

无厘头的 kube-flannel-ds-xxx 或 kube-proxy-xxx 出现 CrashLooppBackOff, 要检查安装containerd时是否有修改cgroup Driver为systemd

sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

4 相关命令

kubeadm token list  # 查看 tokens
kubeadm token create # 重新生成
kubeadm reset -f # 重置

kubectl logs -n kube-system kube-proxy-zvkbq {pod name} #查日志
kubectl auth can-i create namespace # 查询是否有权做某事

kubectl get nodes
kubectl describe node k8s-node-1 # 查看节点k8s-node-1
kubectl describe nodes # 查看所有节点

kubectl get pods -o wide -A # 查看pods
kubectl describe pod -n kube-system kube-proxy-nxr68 # 查看pod

kubectl delete node <node name>
kubectl delete pod -n kube-flannel <pod  name>

kubectl config current-context # 查看当前上下文(用户)
kubectl config view # 查看配置
kubectl config get-contexts # 上下文(用户)列表
kubectl get role -n kube-public

journalctl -f -u kubelet    # 查看kubelet日志

5 Tips

  • 在树莓派中,最好还是装个proxychains,科学找源,避免找不到或解析问题
  • 关于/etc/kubernetes/ 目录下的四个文件,其作用是:
    admin.conf kubectl与apiServer打交道的文件
    controller-manager.conf controllerManager与apiServer打交道的文件
    kubelet.conf kubelet与apiServer打交道的文件
    scheduler.conf scheduler与apiServer打交道的文件

6 参考

使用树莓派搭建K8S集群(ARM64架构,附安装脚本)_树莓派集群_NaclChan的博客-CSDN博客

Creating a cluster with kubeadm | Kubernetes

Kubernetes安装与踩坑_--apiserver-advertise-address___walden的博客-CSDN博客

使用Kubeadm(1.13+)快速搭建Kubernetes集群

k8s笔记17--ubuntu & k8s 开启 swap功能_k8s swap_昕光xg的博客-CSDN博客

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

反向代理自建教程:你懂的

一、为什么需要自建反代 OpenAI提供了两种访问方式&#xff0c;一种是直接在ChatGPT网页端使用的Access Token方式&#xff0c;这种方式可以免费使用GPT-3.5模型&#xff0c;只需要登录即可使用。但缺点是不稳定&#xff0c;且无法扩展。另一种是使用API&#xff0c;注册用户可…

SpringBoot自动装配原理(附面试快速答法)

文章目录SpringBoot自动装配原理1. 从调用SpringApplication构造器方法开始2. 解析启动类4.按需装配4.1 分析dubbo自动装配5. 如果定义自己的starter6. 面试答法SpringBoot自动装配原理 之前面试被问到这个题目&#xff0c;只会答一些spi、AutoConfigration注解、Import之类的&…

询问ChatGPT的高质量答案艺术——提示工程指南(更新中……)

目录前言一、提示工程简介二、提示技巧2-1、生成法律文件2-2、添加提示技巧三、角色扮演3-1、智能手机产品描述3-2、添加角色扮演四、标准提示4-1、写一篇有关于新智能手机的评论4-2、添加标准提示、角色提示、种子词提示等等五、示例很少、或者没有示例5-1、生成一个手机配置六…

机器学习中的数学原理——过拟合、正则化与惩罚函数

通过这篇博客&#xff0c;你将清晰的明白什么是过拟合、正则化、惩罚函数。这个专栏名为白话机器学习中数学学习笔记&#xff0c;主要是用来分享一下我在 机器学习中的学习笔记及一些感悟&#xff0c;也希望对你的学习有帮助哦&#xff01;感兴趣的小伙伴欢迎私信或者评论区留言…

Docker系列 基于OpenAI API自建ChatGPT

转自我的博客文章https://blognas.hwb0307.com/linux/docker/4201&#xff0c;内容更新仅在个人博客可见。欢迎关注&#xff01; 前言 我用帐号/密码使用chatGPT已经有一段时间。但是&#xff0c;我有几个私交较密的朋友&#xff0c;他们并不具备使用chatGPT的条件&#xff1b…

【无功优化】基于多目标差分进化算法的含DG配电网无功优化模型【IEEE33节点】(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

java遍历字符串的方法

在 java中&#xff0c;我们需要遍历字符串&#xff0c;如何遍历呢&#xff1f;首先我们先了解一下遍历的概念&#xff1a; 在我们的计算机中&#xff0c;存储的都是二进制数据&#xff0c;为了方便存储和管理&#xff0c;我们把一段数据分成多个字符串。在 java中&#xff0c;遍…

网络IO(non-blocking io)基础

BIO&#xff08;blocking io&#xff09; 传统的网络io模式&#xff0c;面向流&#xff0c;一个线程对接一个会话&#xff0c;因此高并发时会因线程阻塞而性能低效 Java代码&#xff1a; public class BIO implements Connector {private Integer port 8080;Overridepublic v…

SAP Business Technology Platform (BTP)的架构理解

查资料看到的&#xff0c;转一下&#xff0c;附上链接&#xff1a; SAP Business Technology Platform (BTP)的架构理解 长期以来&#xff0c;我在与客户和伙伴的沟通交流中发现大家依然对SAP业务技术平台 – SAP Business Technology Platform (以下简称BTP)纯有各种疑惑&…

Web 攻防之业务安全:密码找回流程绕过测试.(利用链接跳到后面去)

Web 攻防之业务安全&#xff1a;密码找回流程绕过测试 业务安全是指保护业务系统免受安全威胁的措施或手段。广义的业务安全应包括业务运行的软硬件平台&#xff08;操作系统、数据库&#xff0c;中间件等&#xff09;、业务系统自身&#xff08;软件或设备&#xff09;、业务所…

13.vue-cli

单页面应用程序&#xff1a;所有的功能只在index.html中完成 vue-cli是vue版的webpack 目录 1 安装vue-cli 2 创建项目 3 使用预设 4 删除预设 5 开启项目 6 项目文件内容 6.1 node_moduls 中是项目依赖的库 6.2 public 6.2.1 favicon.ico 是浏览器页签内部…

Android屏幕适配dp、px两套解决办法

最新最全文章(2018-08-25)&#xff1a;Android dp方式的屏幕适配-原理(后期补充完整讲解)_手机dp输出是横屏还是竖屏_android阿杜的博客-CSDN博客 “又是屏幕适配&#xff0c;这类文章网上不是很多了吗&#xff1f;” 我也很遗憾&#xff0c;确实又是老问题。但本文重点对网上…

MYSQL学习 - DDL数据库操作

前言 从今天开始, 健哥就带各位小伙伴学习数据库技术。数据库技术是Java开发中必不可少的一部分知识内容。也是非常重要的技术。本系列教程由浅入深, 全面讲解数据库体系。 非常适合零基础的小伙伴来学习。 ------------------------------前戏已做完&#xff0c;精彩即开始---…

基于springboot和ajax的简单项目 06 日志界面的delete功能(根据选择的checkbox)

01.这次后台开始&#xff1b; 顺序依次是dao->xml->service->serviceimpl->controller->html 02.dao接口 public int doDeleteObjects(Param("ids") Integer... ids);03.xml文件 <update id"doDeleteObjects" >delete from sys_lo…

用友U8 cloud,信创云ERP的数智先锋

编辑&#xff1a;阿冒设计&#xff1a;沐由从来未曾有过一个春天&#xff0c;能够像当下这般被如此由衷地期待。经历了漫长的1000多个日日夜夜之后&#xff0c;我们的工作与生活终于回到正轨。自2023年以来&#xff0c;中国市场迎来“开门红”&#xff0c;消费市场加速回暖&…

第十四届蓝桥杯大赛软件赛省赛 C/C++ 大学 A 组 E 题

颜色平衡树问题描述格式输入格式输出样例输入样例输出评测用例规模与约定解析参考程序问题描述 格式输入 输入的第一行包含一个整数 n &#xff0c;表示树的结点数。 接下来 n 行&#xff0c;每行包含两个整数 Ci , Fi&#xff0c;用一个空格分隔&#xff0c;表示第 i 个结点 …

新能源汽车高压配电管理(PDU/BDU)

一、概念与组成 PDU(Power Distribution Unit)&#xff0c;即高压配电单元&#xff0c;功能是负责新能源车高压系统中的电源分配与管理&#xff0c;为整车提供充放电控制、高压部件上电控制、电路过载短路保护、高压采样、低压控制等功能&#xff0c;保护和监控高压系统的运行…

智慧井盖-物联网智能井盖系统-管网数字化监测,守护城市生命线

平升电子智慧井盖-物联网智能井盖系统-管网数字化监测,守护城市生命线实现对井下设备和井盖状态的监测及预警&#xff0c;是各类智慧管网管理系统中不可或缺的重要设备&#xff0c;解决了井下监测环境潮湿易水淹、电力供应困难、通讯不畅等难题&#xff0c; 适合安装于城市主干…

【MySQL--05】表的约束

文章目录 1.表的约束1.1空属性1.2默认值default vs null1.3列描述1.4 zerofill1.5主键primary key1.6 自增长auto_increment1.7唯一键 unique如何设计主键&#xff1f;1.8 外键 foreign key 1.表的约束 真正的约束字段的是数据类型&#xff0c;但是数据类型约束很单一&#xf…

基于springboot和ajax的简单项目 02.一直会出现的页面的上一页,下一页,分页与总页数 (下)

在各种功能中会一直出现页面分页的问题。 对此&#xff0c;可以使用pojo对象&#xff0c;来一直管理页面分页的功能。 01.创建相关的pojo对象。 由于属性是来辅助sql语句的&#xff0c;这个pojo对象。 Setter Getter ToString NoArgsConstructorpublic class PageObject<T&…