k3s离线安装

  一、K3s 是一个完全兼容的 Kubernetes 发行版。简单一点就是阉割版的k8s,但是使用方式是一样的。

  二、准备机器

master:192.168.5.200
worker:192.168.5.200

  修改hostname

hostnamectl set-hostname <hostname>

  关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

  关闭selinux

sed -i 's/enforcing/disabled/' /etc/selinux/config

  三、安装:k3s使用v1.25.16+k3s4版本

  1)准备文件

  install.sh:https://github.com/k3s-io/k3s/blob/v1.25.16%2Bk3s4/install.sh

  k3s:https://github.com/k3s-io/k3s/releases/tag/v1.25.16%2Bk3s4

  镜像k3s-airgap-images-amd64.tar.gz:https://github.com/k3s-io/k3s/releases/tag/v1.25.16%2Bk3s4

  

   2)执行脚本

cp k3s /usr/local/bin/
chmod +x /usr/local/bin/k3s
mkdir -p /var/lib/rancher/k3s/agent/images/
cp k3s-airgap-images-amd64.tar.gz /var/lib/rancher/k3s/agent/images/
chmod +x install.sh

  docker安装:

cp k3s /usr/local/bin/
chmod +x /usr/local/bin/k3s
docker load -i  k3s-airgap-images-amd64.tar.gz
chmod +x install.sh

  3)master 安装

INSTALL_K3S_SKIP_DOWNLOAD=true ./install.sh

  使用docker作为容器:

INSTALL_K3S_SKIP_DOWNLOAD=true ./install.sh --docker

  如何出现错误:

  

   解决警告: 

yum install -y container-selinux selinux-policy-base
yum install -y https://rpm.rancher.io/k3s/latest/common/centos/7/noarch/k3s-selinux-0.2-1.el7_8.noarch.rpm

  或者

INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_SELINUX_WARN=true ./install.sh --docker

  解决方式查找官网:

  http://docs.rancher.cn/docs/k3s/installation/install-options/_index

  http://docs.rancher.cn/docs/k3s/advanced/_index#selinux-%E6%94%AF%E6%8C%81

  4)worker安装

  a、在master查看token

cat /var/lib/rancher/k3s/server/token

   b、安装agent

INSTALL_K3S_SKIP_DOWNLOAD=true K3S_URL=https://<SERVER_IP>:6443 K3S_TOKEN=<YOUR_TOKEN> ./install.sh

 docker安装:

INSTALL_K3S_SKIP_DOWNLOAD=true K3S_URL=https://<SERVER_IP>:6443 K3S_TOKEN=<YOUR_TOKEN> ./install.sh

  

   5)master查看是否正常

kubectl get nodes

  

  四、配置镜像加速

  在/etc/rancher/k3s下添加registries.yaml

mkdir -p /etc/rancher/k3s
vi /etc/rancher/k3s/registries.yaml

  加入:

mirrors:
  docker.io:
    endpoint:
      - "https://zo5eqsmr.mirror.aliyuncs.com"

  保存后重启:

systemctl restart k3s

  检测:

cat /var/lib/rancher/k3s/agent/etc/containerd/config.toml

  

posted @ 2024-01-03 18:19  小不点丶  阅读(917)  评论(0编辑  收藏  举报