debian11 安装 k8s,containerd ,阿里云镜像(已成功)

1. 环境准备

系统要求:至少 2GB RAM(建议 4GB 或更多),网络连接。
节点准备:至少 3 台机器,1 台作为 Master 节点,2 台作为 Worker 节点。
安装sudo

apt update
apt install sudo

设置主机名(在每台机器上):

sudo hostnamectl set-hostname <主机名>

替换 <主机名> 为 k8s-master、k8s-node1、k8s-node2

配置 /etc/hosts(在所有节点上):
将所有节点的 IP 地址和主机名添加到 /etc/hosts 文件中。

root@k8s-node1:~# echo “192.168.0.147 k8s-master” >> /etc/hosts
root@k8s-node1:~# echo “192.168.0.217 k8s-node1” >> /etc/hosts

更新系统:

 
sudo apt update && sudo apt upgrade -y

2. 安装 containerd

在所有节点上执行以下步骤:

安装 containerd:

 
sudo apt install -y containerd

2.2 更新containered到最新版本1.7

默认安装的版本是1.4,如果不更新,后面 init 的时候会报如下错误

 
[ERROR CRI]: container runtime is not running: output: time="2024-02-03T22:17:09+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[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

到 https://github.com/containerd/containerd/releases 下载最新版本

  1. 解压缩文件
    首先,您需要解压下载的压缩包。打开终端,切换到包含下载文件的目录,然后运行:
 
tar xzvf containerd-1.7.13-linux-amd64.tar.gz
sudo mv bin/* /usr/bin/

containerd --version 可以查看版本号为1.7

2.3 配置 containerd:

生成默认配置文件

 
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
修改配置文件
nano /etc/containerd/config.toml文件中 sandbox_image做如下修改,因为后面init的时候指定的是阿里云的sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]SystemdCgroup = true #这个很重要,否则,k8s启动起来后会自动停止,kubectl get pods -n kube-system 也会出现监听端口6443访问失败的报错

启用并启动 containerd:

sudo systemctl restart containerd
sudo systemctl enable containerd

sudo systemctl status containerd 可查看状态

3. 安装 Kubernetes

在所有节点上执行以下步骤:

安装必需的包:首先,确保你的系统安装了 apt-transport-https、ca-certificates 和 curl:

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

添加 Kubernetes 的 GPG 密钥:

 
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -

添加 Kubernetes 仓库:

 
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

更新软件包列表:

 
sudo apt-get update

安装 kubeadm、kubelet 和 kubectl:

sudo apt-get install -y kubelet=1.28.2-00 kubeadm=1.28.2-00  kubectl=1.28.2-00 sudo apt-mark hold kubelet kubeadm kubectl

安装配置br_netfilter 模块:

sudo modprobe br_netfilter

确保 IP 转发被启用:


echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.confecho "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.confsudo sysctl -p
# 4. 初始化 Kubernetes 集群(在 Master 节点上执行)

4.2 初始化集群:(Master节点)

直接执行下面的会报错

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

报错:

	[ERROR ImagePull]: failed to pull image registry.k8s.io/kube-apiserver:v1.28.6: output: E0212 19:15:37.560180   22897 remote_image.go:171] "P

应该执行下面的

sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers --kubernetes-version=v1.28.2

以下是 kubeadm init 命令的输出。

 root@ecs-2144:~# sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containerssudo kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers --kubernetes-version=v1.28.6
unknown command "kubeadm" for "kubeadm init"
To see the stack trace of this error execute with --v=5 or higher
root@ecs-2144:~# sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers --kubernetes-version=v1.28.6
[init] Using Kubernetes version: v1.28.6
[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'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [k8s-master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.0.147]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [k8s-master localhost] and IPs [192.168.0.147 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8s-master localhost] and IPs [192.168.0.147 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 4.001658 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node k8s-master as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node k8s-master as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: c5ir0f.h8x43oj54kb1gppe
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxyYour Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.0.147:6443 --token c5ir0f.h8x43oj54kb1gppe \--discovery-token-ca-cert-hash sha256:42dc8386b03f8c6c415e06153c4b978e2020ca48d19b7b8b383d1c5d311a36e7  

5. 设置 kubectl(仅限 Master 节点)

 
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

6. 安装网络插件(在 Master 节点上)

 
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml --request-timeout='0'

#不加–request-timeout=‘0’ 可能会导致超时
如果出现连接连接端口错误
运行 journalctl -u kubelet 可以看日志,如果看到以下错误

err="failed to load kubelet config file, path: /var/lib/kubelet/config.yaml, err>

可能是没有授权访问权限,运行以下即可

sudo chown root:root /var/lib/kubelet/config.yaml
sudo chmod 644 /var/lib/kubelet/config.yaml

然后重新运行kubelet
sudo systemctl restart kubelet //经测试只需要这一行即可
sudo systemctl status kubelet
sudo systemctl restart containerd
sudo systemctl status containerd

然后重新运行上面的 kubectl apply …
可能还会出现报错 unable to connect to the server: net/http: TLS handshake timeout
重新执行一遍一般就会成功

7. 将 Worker 节点加入集群

在每个 Worker 节点上,运行在初始化 Master 节点时得到的 kubeadm join 命令。
效果如下:

root@ecs-7d63:~# kubeadm join 192.168.0.147:6443 --token lj3ooj.2x39tu70gyx5uj3v --discovery-token-ca-cert-hash sha256:7ce5191c1581dfcee7b33457bdd9341fa1ee128a19ac248c8daf9e69a57a8b18 
[preflight] Running pre-flight checks
[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.
  1. 验证集群状态
    在 M
    aster 节点上,运行:
kubectl get nodes

你应该能看到所有节点的状态为 Ready。

支持基础安装完成,下一步就是配置k8s

开放端口

API Server:

6443: Kubernetes API server。这是最关键的端口,用于集群管理通信。
etcd:

2379-2380: 用于etcd服务器客户端API通信。只有Kubernetes的API server才需要访问etcd,所以这些端口只需要在Master节点之间开放。

Kubelet:

10250: Kubelet API。这个端口用于API server获取节点和Pod的信息。
Kube-proxy:

Kubernetes中的Controller Manager和Scheduler虽然主要与API Server进行通信,但它们也监听在特定端口上,主要用于健康检查和指标收集。这些端口主要用于集群内部通信,而不是外部访问。下面是Controller Manager和Scheduler所监听的端口:

Kubernetes Controller Manager
默认端口:
10252: 用于健康检查和指标(metrics)的非安全HTTP访问。
安全端口:
当配置了安全访问(例如,通过启用HTTPS或认证和授权),Controller Manager可以配置为通过安全端口提供服务,但这需要手动配置,包括证书和相关的安全设置。
Kubernetes Scheduler
默认端口:
10251: 用于健康检查和指标的非安全HTTP访问。

排错

列出所有系统pod
kubectl get pods -n kube-system

calico-kube-controllers-7ddc4f45bc-snh9v 1/1 Running 1 (2m10s ago) 158m
calico-node-5mnpd 1/1 Running 1 (2m10s ago) 158m
calico-node-s6w74 1/1 Running 0 156m
coredns-66f779496c-cvwjx 1/1 Running 1 (2m10s ago) 171m
coredns-66f779496c-qx7fr 1/1 Running 1 (2m10s ago) 171m
etcd-k8s-master 1/1 Running 1 (2m10s ago) 171m
kube-apiserver-k8s-master 1/1 Running 1 (2m10s ago) 171m
kube-controller-manager-k8s-master 1/1 Running 1 (2m10s ago) 171m
kube-proxy-k7c6l 1/1 Running 1 (2m10s ago) 171m
kube-proxy-stft6 1/1 Running 0 156m
kube-scheduler-k8s-master 1/1 Running 1 (2m10s ago) 171m

找出名称后,可以查看该pod的日志
kubectl logs -n kube-system

调用 kubectl get pods -n kube-system
如果响应
root@k8s-master:~# kubectl get pods -n kube-system
The connection to the server 192.168.0.147:6443 was refused - did you specify the right host or port?
说明kubelet停了,需要调用
sudo systemctl restart kubelet 重启,

journalctl -u kubelet 可查看kubelet日志

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

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

相关文章

Java图形化界面编程——AWT概论 笔记

2.3 Container容器 2.3.1 Container继承体系 Winow是可以独立存在的顶级窗口,默认使用BorderLayout管理其内部组件布局;Panel可以容纳其他组件&#xff0c;但不能独立存在&#xff0c;它必须内嵌其他容器中使用&#xff0c;默认使用FlowLayout管理其内部组件布局&#xff1b;S…

Spring Cloud Feign:声明式服务调用

1. 介绍 Spring Cloud Feign 1.1 什么是 Spring Cloud Feign Spring Cloud Feign 是一个基于 Netflix Feign 的声明式服务调用客户端&#xff0c;它简化了基于 REST 的服务调用&#xff0c;使得服务之间的通信变得更加轻松和直观。通过 Feign&#xff0c;开发人员可以像调用本…

交通管理|交通管理在线服务系统|基于Springboot的交通管理系统设计与实现(源码+数据库+文档)

交通管理在线服务系统目录 目录 基于Springboot的交通管理系统设计与实现 一、前言 二、系统功能设计 三、系统实现 1、用户信息管理 2、驾驶证业务管理 3、机动车业务管理 4、机动车业务类型管理 四、数据库设计 1、实体ER图 五、核心代码 六、论文参考 七、最新计…

MySQL学习Day15——MySQL安装与使用

一、Linux下的MySQL的安装与使用: 卸载MySQL: 1.关闭当前MySQL服务:systemctl stop mysql.service 2.查看当前mysql安装状况:rpm -qa | grep -i mysql 3.卸载上述命令查询出的已安装的程序:yum remove mysql-xxx mysql-xxx mysql-xxxx 4.删除mysql相关文件: (1)查找相关文…

Python五级考试笔记

Python五级考试笔记【源源老师】 五级标准 一、 掌握字符串的转义符、format()格式化方法。 二、 掌握列表、元组、字符串、range类型的用法及常用操作。 三、 理解字典类型的概念&#xff0c;掌握它的基础用法及操作。 四、 理解集合类型的概念&#xff0c;掌握它的基础用法及…

解决vscode报错,在赋值前使用了变量“XXX“

问题&#xff1a;如图所示 解决方法&#xff1a; 法一&#xff1a; 补全函数使其完整 法二&#xff1a; 使用断言

c++Qt网络操作

1、基础概念 1.1 TCP/UDP TCP 是一种面向连接的传输层协议&#xff0c;它能提供高可靠性通信(即数据无误、数据无丢失、 数据无失序、数据无重复到达的通信) 适用情况&#xff1a; 1.SN/QQ等即时通讯软件的用户登录账户管理相关的功能通常采用TCP协议 2、适合于对传输质量要求较…

【STM32 CubeMX】串口编程DMA

文章目录 前言一、DMA方式1.1 DMA是什么1.2 CubeMX配置DMA1.3 DMA方式函数使用DMA的发送接收函数 总结 前言 在嵌入式系统中&#xff0c;串口通信是一项至关重要的功能&#xff0c;它允许单片机与外部设备进行数据交换&#xff0c;如传感器、显示器或其他设备。然而&#xff0…

Linux笔记之xhost +和docker的关系以及GDK_SCALE和GDK_DPI_SCALE详解

Linux笔记之xhost 和docker的关系以及GDK_SCALE和GDK_DPI_SCALE详解 ——2024-02-11 code review! 文章目录 Linux笔记之xhost 和docker的关系以及GDK_SCALE和GDK_DPI_SCALE详解xhost 的作用xhost 与 Docker 的关系 -e GDK_SCALE 和 -e GDK_DPI_SCALE详解GDK_SCALEGDK_DPI_SC…

【使用IntelliJ IDEA 配置Maven入门——详细讲解】

使用IntelliJ IDEA 配置Maven 1. 介绍2. 安装 Maven&#xff08;如果你的系统尚未安装&#xff09;3. 在 IntelliJ IDEA 中配置 Maven4. 创建/导入 Maven 项目5. 编译和运行 Maven 项目6. 提示 1. 介绍 IntelliJ IDEA 是一个广受欢迎的Java集成开发环境&#xff08;IDE&#x…

【Linux】进程的初步认识

进程的初步认识 基本概念描述进程task_struct-PCB的一种task_stuct内容分类 查看进程通过系统调用获取进程标识符 基本概念 要了解进程&#xff0c;首先我们要知道两点 我们可以同时启动多个程序&#xff0c;也就意味着我们可以将多个.exe文件加载到内存操作系统如何去管理这些…

Resolving Low-Level Graphics Issues

Resolving Low-Level Graphics Issues 在远程操作其他工作站上的matlab的时候&#xff0c;无法显示仿真结果&#xff0c;但是在真实的工作站上操作的话又可以看到simulation的结果&#xff0c;并且远程的时候进行仿真&#xff0c;就会显示以下的错误提示&#xff1a; >>…

036-安全开发-JavaEE应用第三方组件Log4j日志FastJson序列化JNDI注入

036-安全开发-JavaEE应用&第三方组件&Log4j日志&FastJson序列化&JNDI注入 #知识点&#xff1a; 1、JavaEE-组件安全-Log4j 2、JavaEE-组件安全-Fastjson 3、JavaEE-基本了解-JNDI-API 演示案例&#xff1a; ➢Java-三方组件-Log4J&JNDI ➢Java-三方组件-Fa…

OpenAI全新发布文生视频模型Sora - 现实,不存在了

OpenAI&#xff0c;发他们的文生视频大模型&#xff0c;Sora了。。。。。 而且&#xff0c;是强到&#xff0c;能震惊我一万年的程度。。。 https://openai.com/sora 如果非要用三个词来总结Sora&#xff0c;那就是“60s超长长度”、“单视频多角度镜头”和“世界模型” &am…

Codeforces Round 926 (Div. 2)(A,B,C,D,E,F)

这场还是很有含金量的&#xff0c;B题开始就有难度了&#xff0c;B是个推结论的题&#xff0c;C要推结论然后递推&#xff0c;D题是有点难的树上DP&#xff08;主要是状态转移方程不好写&#xff09;&#xff0c;E题是个二进制预处理然后状压DP&#xff0c;F题是个数论&#xf…

力扣代码学习日记三

Problem: 242. 有效的字母异位词 文章目录 思路解题方法复杂度代码 思路 给定两个字符串 s 和 t &#xff0c;编写一个函数来判断 t 是否是 s 的字母异位词。 注意&#xff1a;若 s 和 t 中每个字符出现的次数都相同&#xff0c;则称 s 和 t 互为字母异位词。 示例 1: 输入: s…

写一个程序,输入数量不确定的[0,9]范围内的整数,统计每一种数字出现的次数输入-1表示结束

#include <stdio.h> int main(void) {int x;int count[10];int i;for(i0;i<10;i){//初始化数组 count[i]0;}scanf("%d",&x);while(x!-1){if( x>0 && x<9){count[x];//数组参与运算 }scanf("%d",&x);}for(i0;i<10;i){pr…

coding持续集成构建环境自定义node版本

coding持续集成构建环境自定义node版本 解决方案 只需要在构建计划的编写过程中增加一个如下的 stage&#xff0c;具体 nodejs 版本下载地址可参考 https://nodejs.org/en/download/releases/ 这里。 stage(toggle Node.js version) {steps {sh rm -rf /usr/lib/node_modules…

车载诊断协议DoIP系列 —— 车辆以太网节点需求汇总

车载诊断协议DoIP系列 —— 车辆以太网节点需求汇总 我是穿拖鞋的汉子,魔都中坚持长期主义的汽车电子工程师(Wechat:gongkenan2013)。 老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 本就是小人物,输了就是输了,不要在意别人怎么看自己。江湖一碗茶,…

【前端工程化面试题】简单说一下 vite 的构建流程

首先需要知道 vite 的原理&#xff0c;请参考这篇文章。 vite 的构建流程一般是指的开发过程中的流程&#xff1a; 启动开发服务器&#xff1a;运行 vite 命令&#xff0c;启动开发服务器&#xff0c;在开发期间 vite 是一个服务器解析入口模块&#xff1a;在开发阶段 vite 的…