Ubuntu server22.04 ,kubernetes(k8s)1.24.0,congtainerd 1.6.4安装笔记

Posted 寂静的星空

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu server22.04 ,kubernetes(k8s)1.24.0,congtainerd 1.6.4安装笔记相关的知识,希望对你有一定的参考价值。

闲来无事写个新版本的安装记录

ip规划

角色

IP

master1

192.168.0.221

node1

192.168.0.222

node2

192.168.0.223

node3

192.168.0.224

k8s-node-01

192.168.0.245

时间同步

apt-get install ntpdate -y

ntpdate time.windows.com

允许 iptables 检查桥接流量

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf

br_netfilter

EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

EOF

sudo sysctl --system

Ubuntu 18.04 下关闭 swap 的操作

关闭swap

swapoff -a # 临时

sed -ri s/.*swap.*/#&/ /etc/fstab # 永久

安装 Docker

也可以参考其它过程安装

apt-get install docker.io

如果需要配置为开机启动,可执行以下命令

systemcd enable docker

systemcd start docker

配置docker加速器

mkdir -p /etc/docker

tee /etc/docker/daemon.json <<-EOF

"registry-mirrors": ["https://1e60esib.mirror.aliyuncs.com"],

"exec-opts": ["native.cgroupdriver=systemd"],

"log-driver": "json-file",

"log-opts":

"max-size": "100m"

EOF

systemctl daemon-reload

systemctl restart docker

安装docker-ce ,containerd.io

1 安装

削除旧的版本

$ sudo apt-get remove docker docker-engine docker.io containerd runc

$sudo apt-get update

安装相关支持

sudo apt-get install \\

apt-transport-https \\

ca-certificates \\

curl \\

gnupg \\

lsb-release

添加证书

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

$ echo \\

"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \\

$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装

$ sudo apt-get update

$ sudo apt-get install containerd.io docker-ce docker-ce-cli

配置containerd

生成containerd默认配置文件

mkdir -p /etc/containerd

containerd config default | sudo tee /etc/containerd/config.toml

修改配置文件

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

grep SystemdCgroup -B 11 /etc/containerd/config.toml

老版本要手动追加这个参数SystemdCgroup = true
显示内容

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]

BinaryName = ""

CriuImagePath = ""

CriuPath = ""

CriuWorkPath = ""

IoGid = 0

IoUid = 0

NoNewKeyring = false

NoPivotRoot = false

Root = ""

ShimCgroup = ""

SystemdCgroup = true

配置容器镜像加速器

sed -i s#endpoint = ""#endpoint = "https://xx4bwyg2.mirror.aliyuncs.com"#g /etc/containerd/config.toml && \\

grep endpoint -B 5 /etc/containerd/config.toml

sed -i s#sandbox_image = "k8s.gcr.io/pause:*"#sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.6"#g /etc/containerd/config.toml && \\

grep sandbox_image /etc/containerd/config.toml

重启服务器加载配置

systemctl daemon-reload

systemctl restart containerd.service

安装 K8S

安装 K8S软件包

更新 apt 包索引并安装使用 Kubernetes apt 仓库所需要的包:

sudo apt-get update

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

下载 Google Cloud 公开签名秘钥:

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

添加 Kubernetes apt 仓库:

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

阿里云源安装可以忽略上边的

apt-get update && apt-get install -y apt-transport-https

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

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list

deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main

EOF

更新 apt 包索引,安装 kubelet、kubeadm 和 kubectl,并锁定其版本:

apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

部署Kubernetes Master

6.1 创建kubeadm配置文件

导出默认初始化配置

kubeadm config print init-defaults > kubeadm-config.yaml

vi kubeadm-config.yaml

apiVersion: kubeadm.k8s.io/v1beta3

bootstrapTokens:

  • groups:
  • system:bootstrappers:kubeadm:default-node-token

token: abcdef.0123456789abcdef

ttl: 24h0m0s

usages:

  • signing
  • authentication

kind: InitConfiguration

localAPIEndpoint:

advertiseAddress: 192.168.0.221

bindPort: 6443

nodeRegistration:

criSocket: /run/containerd/containerd.sock

imagePullPolicy: IfNotPresent

name: master

taints: null


apiServer:

timeoutForControlPlane: 4m0s

apiVersion: kubeadm.k8s.io/v1beta3

certificatesDir: /etc/kubernetes/pki

clusterName: kubernetes

controllerManager:

dns:

etcd:

local:

dataDir: /var/lib/etcd

imageRepository: registry.aliyuncs.com/google_containers

kind: ClusterConfiguration

kubernetesVersion: 1.24.0

networking:

dnsDomain: cluster.local

serviceSubnet: 10.96.0.0/12

scheduler:

在master1节点执行

kubeadm init --config kubeadm-init.yaml

#如何根据配置文件,列出和拉取镜像

kubeadm config images list --config kubeadm-config.yaml
kubeadm config images pull --config kubeadm-config.yaml

不懂得可以留言,作者看到会回不过作者不怎么登陆这个玩意

以上是关于Ubuntu server22.04 ,kubernetes(k8s)1.24.0,congtainerd 1.6.4安装笔记的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu-Server 22.04安装详细过程-图文版

树莓派4B+Ubuntu22.04 Server安装ROS2 Humble

G006-OS-LIN-UBUN-02 Ubuntu Server 22.04 安装

How to Install & Configure VNC Server on Ubuntu 22.04 or 20.04

Ubuntu server22.04 ,kubernetes(k8s)1.24.0,congtainerd 1.6.4安装笔记

Ubuntu22.04 + TigerVNC