K3S(Linux一键部署)

主 Master

curl -sfL https://get.k3s.io | sh -

国内加速

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn INSTALL_K3S_EXEC="server --flannel-backend none" K3S_TOKEN=12345 sh -

Agent 节点 请使用 K3S_URLK3S_TOKEN 环境变量运行安装脚本

curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -

国内加速

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -

export K3S_TOKEN="你的Token"
export K3S_URL="https://<你的Master主机IP>:6443"
curl -sfL https://cdn.rancher.cn/k3s/k3s-install.sh | sh -

卸载K3S

sh /usr/local/bin/k3s-uninstall.sh

!!!每台主机必须具有唯一的主机名。如果你的计算机没有唯一的主机名,请传递 K3S_NODE_NAME 环境变量,并为每个节点提供一个有效且唯一的主机名。

协议

端口

Source

Destination1

描述

TCP

2379-2380

Servers

Servers

Required only for HA with embedded etcd

TCP

6443

Agents

Servers

K3s supervisor and Kubernetes API Server

UDP

8472

All nodes

All nodes

Required only for Flannel VXLAN

TCP

10250

All nodes

All nodes

Kubelet metrics

UDP

51820

All nodes

All nodes

Required only for Flannel Wireguard with IPv4

UDP

51821

All nodes

All nodes

Required only for Flannel Wireguard with IPv6

TCP

5001

All nodes

All nodes

Required only for embedded distributed registry (Spegel)

TCP

6443

All nodes

All nodes

Required only for embedded distributed registry (Spegel)

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" sh -s - --flannel-backend none --token 12345
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --flannel-backend none" K3S_TOKEN=12345 sh -s -
curl -sfL https://get.k3s.io | K3S_TOKEN=12345 sh -s - server --flannel-backend none
# server is assumed below because there is no K3S_URL
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend none --token 12345" sh -s - 
curl -sfL https://get.k3s.io | sh -s - --flannel-backend none --token 12345

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="agent --server https://k3s.example.com --token mypassword" sh -s -
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="agent" K3S_TOKEN="mypassword" sh -s - --server https://k3s.example.com
curl -sfL https://get.k3s.io | K3S_URL=https://k3s.example.com sh -s - agent --token mypassword
curl -sfL https://get.k3s.io | K3S_URL=https://k3s.example.com K3S_TOKEN=mypassword sh -s - # agent is assumed because of K3S_URL

Master获取全部节点信息

kubectl get nodes -o wide

Master获取Token

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

K3s(OpenWrt部署二进制部署 需要cgroup)

# 从Github下载
LATEST_RELEASE=$(curl -sL -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/k3s-io/k3s/releases/latest" | grep -o '"tag_name": *"[^"]*"' | cut -d'"' -f4); ARCH=$(uname -m); FILE="k3s"; [ "$ARCH" = "aarch64" ] && FILE="k3s-arm64"; [ "$ARCH" = "armv7l" ] && FILE="k3s-armhf"; curl -sfL "https://github.com/k3s-io/k3s/releases/download/${LATEST_RELEASE}/${FILE}" -o /usr/bin/k3s && chmod +x /usr/bin/k3s


# 国内镜像加速下载
GH=https://gh-proxy.org
LATEST_RELEASE=$(curl -sL -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/k3s-io/k3s/releases/latest" | grep -o '"tag_name": *"[^"]*"' | cut -d'"' -f4); ARCH=$(uname -m); FILE="k3s"; [ "$ARCH" = "aarch64" ] && FILE="k3s-arm64"; [ "$ARCH" = "armv7l" ] && FILE="k3s-armhf"; curl -sfL "$GH/https://github.com/k3s-io/k3s/releases/download/${LATEST_RELEASE}/${FILE}" -o /usr/bin/k3s && chmod +x /usr/bin/k3s

# 运行k3s集群 Docker 运行时
k3s server --disable traefik --disable metrics-server --disable servicelb --https-listen-port 6443 --docker & 
# k3s集群状态
k3s kubectl cluster-info
# 查看节点
k3s kubectl get node
# 查看所有pod(pod可以理解成docker的容器)
k3s kubectl get pod -A