K8s - openeuler2203SP1安装 K8s + flannel

ops/2024/12/25 23:40:37/

环境说明

[root@master-1 ~]# uname -a
Linux master-1 5.10.0-136.12.0.86.oe2203sp1.x86_64 #1 SMP Tue Dec 27 17:50:15 CST 2022 x86_64 x86_64 x86_64 GNU/Linux

安装过程

1、安装 containerd

  1. 下载 tar 包

    # 确保没有使用官方仓库的containerd
    [root@localhost ~]# yum remove containerd -y
    [root@localhost ~]# wget https://github.com/containerd/containerd/releases/download/v1.7.16/containerd-1.7.16-linux-amd64.tar.gz
    [root@localhost ~]# tar -zxvf containerd-1.7.16-linux-amd64.tar.gz 
    [root@localhost ~]# mv bin/* /usr/local/bin/
    
  2. 编写 service 文件

    [root@localhost ~]# vi /usr/lib/systemd/system/containerd.service[Unit]
    Description=containerd container runtime
    Documentation=https://containerd.io
    After=network.target local-fs.target[Service]
    ExecStartPre=-/sbin/modprobe overlay
    ExecStart=/usr/local/bin/containerdType=notify
    Delegate=yes
    KillMode=process
    Restart=always
    RestartSec=5# Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNPROC=infinity
    LimitCORE=infinity# Comment TasksMax if your systemd version does not supports it.
    # Only systemd 226 and above support this version.
    TasksMax=infinity
    OOMScoreAdjust=-999[Install]
    WantedBy=multi-user.target
    
  3. 修改配置文件

    [root@localhost ~]# mkdir /etc/containerd/
    [root@localhost ~]# containerd config default > /etc/containerd/config.toml 
    # 将cgroup打开
    [root@localhost ~]# vi /etc/containerd/config.toml
    # 找到这一行配置,将false改为true
    139 SystemdCgroup = true
    # 修改sandbox镜像地址
    67 sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
    
  4. 启动服务

    [root@localhost ~]# systemctl daemon-reload
    [root@localhost ~]# systemctl enable --now containerd
    

2、安装 cni 插件

[root@localhost ~]# wget https://github.com/containernetworking/plugins/releases/download/v1.4.1/cni-plugins-linux-amd64-v1.4.1.tgz
[root@localhost ~]# mkdir -p /opt/cni/bin
[root@localhost ~]# tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.4.1.tgz

3、主机配置

[root@localhost ~]# hostnamectl set-hostname master-1
[root@localhost ~]# echo "127.0.0.1 master-1" >> /etc/hosts
[root@localhost ~]# echo "::1 master-1" >>/etc/hosts[root@master-1 ~]# modprobe bridge
[root@master-1 ~]# modprobe br_netfilter
[root@master-1 ~]# vi /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
[root@master-1 ~]# sysctl -p[root@master-1 ~]# setenforce 0
[root@master-1 ~]# sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
[root@master-1 ~]# systemctl disable --now firewalld[root@master-1 ~]# swapoff -a

在这里插入图片描述

4、搭建 K8s

  1. 配置 yum 源

    [root@master-1 ~]# sed -i "s/openEuler-22.03-LTS-SP1/openEuler-23.03/g" /etc/yum.repos.d/openEuler.repo
    
  2. yum 安装

    [root@master-1 ~]# yum install kubernet* cri-tools  -y
    [root@master-1 ~]# systemctl enable kubelet
    
  3. cri 配置

    [root@master-1 ~]# crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock --set image-endpoint=unix:///run/containerd/containerd.sock
    
  4. 查看版本并初始化

    [root@master-1 ~]# kubeadm version
    kubeadm version: &version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.0", GitCommit:"4ce5a8954017644c5420bae81d72b09b735c21f0", GitTreeState:"archive", BuildDate:"2023-03-28T11:09:13Z", GoVersion:"go1.19.4", Compiler:"gc", Platform:"linux/amd64"}[root@master-1 ~]# kubeadm init --kubernetes-version=v1.24.0 --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers
    
  5. 按照提示信息操作

    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.conf
    
  6. 查看节点状态

    [root@master-1 ~]# kubectl get nodes
    NAME       STATUS     ROLES           AGE   VERSION
    master-1   NotReady   control-plane   14m   v1.24.0
    

5、网络插件安装

  1. 下载 flannel yml

    [root@master-1 ~]# wget https://github.com/flannel-io/flannel/releases/download/v0.26.2/kube-flannel.yml
    
  2. 通过离线下载网站获取镜像

    https://pull.7ii.win/

  3. 导入 k8s.io 命名空间,需要通过 docker 进行转换

    [root@master-1 ~]# docker load < flannel-flannel-v0.26.2-amd64.tar
    [root@master-1 ~]# docker load < flannel-flannel-cni-plugin-v1.6.0-flannel1-amd64.tar[root@master-1 ~]# docker save -o flannel-flannel-cni-plugin-v1.6.0-flannel1-amd64.tar flannel/flannel-cni-plugin:v1.6.0-flannel1
    [root@master-1 ~]# docker save -o flannel-flannel-v0.26.2-amd64.tar flannel/flannel:v0.26.2[root@master-1 ~]# ctr -n k8s.io images import flannel-flannel-v0.26.2-amd64.tar
    [root@master-1 ~]# ctr -n k8s.io images import flannel-flannel-cni-plugin-v1.6.0-flannel1-amd64.tar
    
  4. 调整 yml 镜像拉取策略,在 image 下增加 imagePullPolicy: Never
    在这里插入图片描述

  5. 应用 yml

    [root@master-1 ~]# kubectl apply -f kube-flannel.yml
    
  6. yml 参考

    apiVersion: v1
    kind: Namespace
    metadata:labels:k8s-app: flannelpod-security.kubernetes.io/enforce: privilegedname: kube-flannel
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:labels:k8s-app: flannelname: flannelnamespace: kube-flannel
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:labels:k8s-app: flannelname: flannel
    rules:
    - apiGroups:- ""resources:- podsverbs:- get
    - apiGroups:- ""resources:- nodesverbs:- get- list- watch
    - apiGroups:- ""resources:- nodes/statusverbs:- patch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:labels:k8s-app: flannelname: flannel
    roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: flannel
    subjects:
    - kind: ServiceAccountname: flannelnamespace: kube-flannel
    ---
    apiVersion: v1
    data:cni-conf.json: |{"name": "cbr0","cniVersion": "0.3.1","plugins": [{"type": "flannel","delegate": {"hairpinMode": true,"isDefaultGateway": true}},{"type": "portmap","capabilities": {"portMappings": true}}]}net-conf.json: |{"Network": "10.244.0.0/16","EnableNFTables": false,"Backend": {"Type": "vxlan"}}
    kind: ConfigMap
    metadata:labels:app: flannelk8s-app: flanneltier: nodename: kube-flannel-cfgnamespace: kube-flannel
    ---
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:labels:app: flannelk8s-app: flanneltier: nodename: kube-flannel-dsnamespace: kube-flannel
    spec:selector:matchLabels:app: flannelk8s-app: flanneltemplate:metadata:labels:app: flannelk8s-app: flanneltier: nodespec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/osoperator: Invalues:- linuxcontainers:- args:- --ip-masq- --kube-subnet-mgrcommand:- /opt/bin/flanneldenv:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespace- name: EVENT_QUEUE_DEPTHvalue: "5000"image: docker.io/flannel/flannel:v0.26.2imagePullPolicy: Nevername: kube-flannelresources:requests:cpu: 100mmemory: 50MisecurityContext:capabilities:add:- NET_ADMIN- NET_RAWprivileged: falsevolumeMounts:- mountPath: /run/flannelname: run- mountPath: /etc/kube-flannel/name: flannel-cfg- mountPath: /run/xtables.lockname: xtables-lockhostNetwork: trueinitContainers:- args:- -f- /flannel- /opt/cni/bin/flannelcommand:- cpimage: docker.io/flannel/flannel-cni-plugin:v1.6.0-flannel1imagePullPolicy: Nevername: install-cni-pluginvolumeMounts:- mountPath: /opt/cni/binname: cni-plugin- args:- -f- /etc/kube-flannel/cni-conf.json- /etc/cni/net.d/10-flannel.conflistcommand:- cpimage: docker.io/flannel/flannel:v0.26.2imagePullPolicy: Nevername: install-cnivolumeMounts:- mountPath: /etc/cni/net.dname: cni- mountPath: /etc/kube-flannel/name: flannel-cfgpriorityClassName: system-node-criticalserviceAccountName: flanneltolerations:- effect: NoScheduleoperator: Existsvolumes:- hostPath:path: /run/flannelname: run- hostPath:path: /opt/cni/binname: cni-plugin- hostPath:path: /etc/cni/net.dname: cni- configMap:name: kube-flannel-cfgname: flannel-cfg- hostPath:path: /run/xtables.locktype: FileOrCreatename: xtables-lock

6、安装结果

[root@master-1 ~]# kubectl get nodes
NAME       STATUS   ROLES           AGE     VERSION
master-1   Ready    control-plane   7m38s   v1.24.0
[root@master-1 ~]#
[root@master-1 ~]#
[root@master-1 ~]# kubectl get pods -A
NAMESPACE      NAME                               READY   STATUS    RESTARTS   AGE
kube-flannel   kube-flannel-ds-rtwp4              1/1     Running   0          98s
kube-system    coredns-74586cf9b6-cdr5n           1/1     Running   0          7m22s
kube-system    coredns-74586cf9b6-hhn72           1/1     Running   0          7m22s
kube-system    etcd-master-1                      1/1     Running   0          7m36s
kube-system    kube-apiserver-master-1            1/1     Running   0          7m36s
kube-system    kube-controller-manager-master-1   1/1     Running   0          7m36s
kube-system    kube-proxy-27tnv                   1/1     Running   0          7m22s
kube-system    kube-scheduler-master-1            1/1     Running   0          7m36s

参考

解决无法拉取flannel镜像:https://blog.csdn.net/qq_46274911/article/details/138486623


http://www.ppmy.cn/ops/144963.html

相关文章

如何处理对象的创建和销毁?

概念 处理对象的创建和销毁是软件开发中的核心问题&#xff0c;尤其是在确保资源管理、性能优化和代码清晰性方面。以下是一些常用的方法和设计模式&#xff0c;用于有效管理对象的创建和销毁。 方法 构造函数和析构函数 在C等语言中&#xff0c;使用构造函数和析构函数是最…

自动屏蔽频繁访问IP,提升服务器安全:实战脚本解析

在当前的数字化时代&#xff0c;服务器安全成为了一个不可忽视的重要环节。无论是企业网站还是个人博客&#xff0c;都面临着来自各方的潜在威胁。其中&#xff0c;恶意访问和频繁登录尝试更是让管理员头疼不已。本文将为大家介绍如何通过脚本自动屏蔽频繁访问和尝试SSH登录的I…

ubuntu,自动休眠后,程序自动暂停。如何破?

昨天挂机想让出图&#xff0c;今天一看&#xff0c;不错&#xff0c;有一张。原来是机器休眠了&#xff0c;暂停了。 在Ubuntu系统中&#xff0c;当计算机进入休眠状态后&#xff0c;所有正在运行的应用程序都会被暂停&#xff0c;包括图形处理程序。为了避免这种情况&#xf…

Docker环境下数据库持久化与多实例扩展实践指南

引言 在Docker容器化技术中&#xff0c;数据库的持久化和多实例管理是两个关键问题。本文将详细介绍如何在Docker中实现数据库的持久化&#xff0c;并有效地管理多个数据库实例。 数据库持久化实现步骤 1. 创建Docker卷 Docker卷是实现数据持久化的关键。以下是创建Docker卷…

Flutter 实现全局悬浮按钮学习

Flutter 代码如何实现了一个全局悬浮按钮&#xff0c;当点击按钮时&#xff0c;会显示一个可以拖动并且通过长按可以移除的悬浮控件。 前置知识点学习 Offset Offset 是 Flutter 中的一个类&#xff0c;用于表示二维平面中的位置或位移。它通常用于描述坐标系中的一个点&…

《C 语言 Socket 网络编程:深入剖析与实战》

目录 一、引言 二、Socket 网络编程基础 &#xff08;一&#xff09;Socket 概念 &#xff08;二&#xff09;网络协议与 Socket 类型 &#xff08;三&#xff09;IP 地址与端口号 三、C 语言 Socket 编程实战步骤 &#xff08;一&#xff09;TCP 服务器端编程 &#x…

南海区2021年C++甲组真题第3题——Excel地址

题目描述 Excel单元格的地址表示很有趣&#xff0c;它使用字母来表示列号。 比如&#xff1a; A表示第1列&#xff0c; B表示第2列&#xff0c; Z表示第26列&#xff0c; AA表示第27列&#xff0c; AB表示第28列&#xff0c; BA表示第53列&#xff0c; ... 当然Excel的最大列…

day14-补充静态网卡配置

修改网络模式&#xff0c;修改静态ip&#xff0c;动态ip获取方式 查看当前的上网信息 1.确保你的机器&#xff0c;是连接的网络的&#xff0c;是插上了网线的。&#xff08;模拟了物理服务器的软件是什么&#xff1f;看你的虚拟的机器&#xff08;vmware&#xff09;&#xf…