一、k3s离线部署
准备工作
1. 准备节点
2. 安装Docker
3. k3s官网 中下载部署文件。
- k3s二进制文件: k3s
- 安装脚本: install.sh
- 依赖镜像:k3s-airgap-images-amd64.tar
部署步骤
k3s1.18.5
提取码: u65h
1. 导入镜像:
sudo docker load -i k3s-airgap-images-amd64.tar
2. 修改文件权限:
sudo chmod a+x k3s install.sh
sudo cp k3s /usr/local/bin/k3s
3. 安装
- master节点:
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='--docker' ./install.sh --disable=traefik
//解决自动负载均衡问题
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC="--docker --write-kubeconfig ~/.kube/config --write-kubeconfig-mode 666 --tls-san 192.168.185.253 --kube-apiserver-arg service-node-port-range=1-65000 --kube-apiserver-arg advertise-address=192.168.185.253 --kube-apiserver-arg external-hostname=192.168.185.253" ./install.sh --disable=traefik
--enable-aggregator-routing = true #解决metrics问题
cat /var/lib/rancher/k3s/server/node-token #记录该token
- node节点:
#token为记录的主节点token, server为主节点IP或有效DNS,添加--docker意思为选择Docker作为容器运行时
INSTALL_K3S_SKIP_DOWNLOAD=true K3S_URL=https://'SERVER':6443 K3S_TOKEN='TOKEN' ./install.sh --docker
--node-ip value, -i value 为结点分配ip
--node-external-ip value 为结点暴露的ip
--flannel-iface=ens10 选网卡,要选择同一网段的网卡
4. 检查是否安装成功:
- 查看节点信息:
kubectl get nodes
- 查看Pod信息:
kubectl get pods --all-namespaces
5. 卸载k3s
直接执行/usr/local/bin/k3s-uninstall.sh
问题解决:
1.出现kubernetes cluster unreachable:
echo “export KUBECONFIG=/etc/rancher/k3s/k3s.yaml” >> ~/.bash_profile
source ~/.bash_profile
2.出现The connection to the server localhost:8080 was refused - did you specify the right host or port?:
- 将master节点中的【/etc/rancher/k3s/k3s.yam】文件拷贝到node节点相同目录下,然后执行问题一步骤
3.出现/etc/rancher/k3s/k3s.yaml not fount
- 可能是k3s.yaml的权限不够,将其设置为666
二、相关配制
k3s配制文件目录
/etc/rancher/
k3s初始化文件
vim /etc/systemd/system/k3s.service
systemctl daemon-reload
service k3s restart
设置不部署traefik
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
Wants=network-online.target
After=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
EnvironmentFile=/etc/systemd/system/k3s.service.env
KillMode=process
Delegate=yes
service-node-port-range=1-65535
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s \
server \
'--docker' \
# 添加一下命令,设置不部署traefik,这个注释要去掉
# '--disable' \
# 'traefik'