一 根底信息
1.1 前提
- 本次装置的为 k3s 1.21.7+k3s1
- VM 版本为 RHEL 7.8, 7.9 或 8.2, 8.3, 8.4(K3s 官网要求)
- VM YUM 仓库:已配置对应版本的 RHEL 和 EPEL YUM 仓库
- VM 提供 root 权限
- 已配置 ntp(避免因为工夫不统一导致的诡异问题)
- 提供 Proxy 拜访互联网 K3s 相干域名;
- 端口要求,为了失常运行,K3s 须要在 K3s 节点和上游 Kubernetes 集群节点上凋谢一些端口。端口需要列出了不同集群类型的 K3s 和上游集群的所有必要端口。具体如下表:
K3S
协定 | 端口 | 源 | 目标 | 形容 |
---|---|---|---|---|
TCP | 6443 | K3s agent 节点 | K3s server 节点 | Kubernetes API Server |
UDP | 8472 | K3s server 和 agent 节点 | K3s server 和 agent 节点 | 仅对 Flannel VXLAN 须要 |
TCP | 10250 | K3s server 和 agent 节点 | K3s server 和 agent 节点 | Kubelet metrics |
✅ 胜利:
如果以上后期条件均已满足。
即能够通过「离线 - 有代理」形式进行装置。
1.2 VM 信息
ℹ️ 信息:
OS 配置 Proxy 过程略
1.2 Proxy 信息
ftp_proxy="http://192.168.0.1:8080"http_proxy="http://192.168.0.1:8080"https_proxy="http://192.168.0.1:8080"
proxy 须要 allow 的 doamin 如下:
域名 | 用处 |
---|---|
http://mirror.cnrancher.com | Rancher 国内组件源 |
https://registry.cn-hangzhou.... | Rancher 国内镜像源 |
https://dockerauth.cn-hangzho... | Rancher 国内镜像源 |
http://mirrors.aliyun.com | YUM 源 |
https://mirrors.aliyun.com | YUM 源 |
https://rpm.rancher.com | Rancher 源 |
评论:
以上的 allowed domain 可能不全,须要进一步补充。
二 「离线 - 有代理」形式装置
评论:
本次环境为:离线,有代理。
通过代理装置部署。
- 假如 K3s 所在主机 IP 地址为:192.168.0.101
- 假如须要装置在
/data
目录下
2.1 装置 K3S
(可选)创立公有仓库配置:
# mkdir -p /data/rancher/k3s# vi /data/rancher/k3s/registries.yaml
mirrors: docker.io: endpoint: - "https://registry.cn-hangzhou.aliyuncs.com" - "https://docker.mirrors.ustc.edu.cn"
装置 K3S:
# curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_SKIP_DOWNLOAD=false INSTALL_K3S_VERSION=v1.21.7+k3s1 K3S_KUBECONFIG_MODE="644" INSTALL_K3S_MIRROR=cn K3S_CLUSTER_INIT INSTALL_K3S_EXEC="--tls-san 192.168.0.101 --pause-image registry.cn-hangzhou.aliyuncs.com/rancher/pause:3.6 --private-registry '/data/rancher/k3s/registries.yaml' --data-dir /data/rancher/k3s --default-local-storage-path /data/rancher/k3s/storage --disable-cloud-controller" sh -s -
输入如下:
[INFO] Using v1.21.7+k3s1 as release[INFO] Downloading hash http://rancher-mirror.cnrancher.com/k3s/v1.21.7-k3s1/sha256sum-amd64.txt[INFO] Downloading binary http://rancher-mirror.cnrancher.com/k3s/v1.21.7-k3s1/k3s[INFO] Verifying binary download[INFO] Installing k3s to /usr/local/bin/k3sLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.combase | 3.6 kB 00:00:00epel | 4.7 kB 00:00:00extras | 2.9 kB 00:00:00updates | 2.9 kB 00:00:00(1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:00(2/2): epel/x86_64/primary_db | 7.0 MB 00:00:02Resolving Dependencies--> Running transaction check---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed--> Finished Dependency ResolutionDependencies Resolved============================================================================================================================================================= Package Arch Version Repository Size=============================================================================================================================================================Installing: yum-utils noarch 1.1.31-54.el7_8 base 122 kTransaction Summary=============================================================================================================================================================Install 1 PackageTotal download size: 122 kInstalled size: 337 kDownloading packages:yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : yum-utils-1.1.31-54.el7_8.noarch 1/1 Verifying : yum-utils-1.1.31-54.el7_8.noarch 1/1Installed: yum-utils.noarch 0:1.1.31-54.el7_8Complete!Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comrancher-k3s-common-stable | 2.9 kB 00:00:00rancher-k3s-common-stable/primary_db | 2.8 kB 00:00:00Resolving Dependencies--> Running transaction check---> Package k3s-selinux.noarch 0:0.5-1.el7 will be installed--> Processing Dependency: container-selinux < 2:2.164.2 for package: k3s-selinux-0.5-1.el7.noarch--> Processing Dependency: container-selinux >= 2.107-3 for package: k3s-selinux-0.5-1.el7.noarch--> Running transaction check---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed--> Finished Dependency ResolutionDependencies Resolved============================================================================================================================================================= Package Arch Version Repository Size=============================================================================================================================================================Installing: k3s-selinux noarch 0.5-1.el7 rancher-k3s-common-stable 15 kInstalling for dependencies: container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 kTransaction Summary=============================================================================================================================================================Install 1 Package (+1 Dependent package)Total download size: 55 kInstalled size: 124 kDownloading packages:(1/2): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00warning: /var/cache/yum/x86_64/$releasever/rancher-k3s-common-stable/packages/k3s-selinux-0.5-1.el7.noarch.rpm: Header V4 RSA/SHA1 Signature, key ID e257814a: NOKEYPublic key for k3s-selinux-0.5-1.el7.noarch.rpm is not installed(2/2): k3s-selinux-0.5-1.el7.noarch.rpm | 15 kB 00:00:00-------------------------------------------------------------------------------------------------------------------------------------------------------------Total 49 kB/s | 55 kB 00:00:01Retrieving key from https://rpm.rancher.io/public.keyImporting GPG key 0xE257814A: Userid : "Rancher (CI) <ci@rancher.com>" Fingerprint: c8cf f216 4551 26e9 b9c9 18be 925e a29a e257 814a From : https://rpm.rancher.io/public.keyRunning transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 1/2 Installing : k3s-selinux-0.5-1.el7.noarch 2/2 Verifying : k3s-selinux-0.5-1.el7.noarch 1/2 Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 2/2Installed: k3s-selinux.noarch 0:0.5-1.el7Dependency Installed: container-selinux.noarch 2:2.119.2-1.911c772.el7_8Complete![INFO] Creating /usr/local/bin/kubectl symlink to k3s[INFO] Creating /usr/local/bin/crictl symlink to k3s[INFO] Creating /usr/local/bin/ctr symlink to k3s[INFO] Creating killall script /usr/local/bin/k3s-killall.sh[INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh[INFO] env: Creating environment file /etc/systemd/system/k3s.service.env[INFO] systemd: Creating service file /etc/systemd/system/k3s.service[INFO] systemd: Enabling k3s unit[INFO] systemd: Starting k3s
运行实现后,应用以下命令查看 K3S 运行状态:
# systemctl status k3s.service● k3s.service - Lightweight Kubernetes Loaded: loaded (/etc/systemd/system/k3s.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2022-01-29 17:05:45 CST; 18s ago Docs: https://k3s.io Process: 19436 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS) Process: 19433 ExecStartPre=/sbin/modprobe br_netfilter (code=exited, status=0/SUCCESS) Main PID: 19442 (k3s-server) Tasks: 119 Memory: 586.7M CGroup: /system.slice/k3s.service ├─19442 /usr/local/bin/k3s server └─19557 containerdJan 29 17:06:03 example01 k3s[19442]: I0129 17:06:03.138349 19442 iptables.go:228] Adding iptables rule: -s 10.42.0.0/16 -d 10.42.0.0/16 -j RETURNJan 29 17:06:03 example01 k3s[19442]: I0129 17:06:03.140940 19442 iptables.go:228] Adding iptables rule: -d 10.42.0.0/16 -j ACCEPTJan 29 17:06:03 example01 k3s[19442]: I0129 17:06:03.142355 19442 iptables.go:228] Adding iptables rule: -s 10.42.0.0/16 ! -d 224.0.0.0...ASQUERADEJan 29 17:06:03 example01 k3s[19442]: I0129 17:06:03.145752 19442 iptables.go:228] Adding iptables rule: ! -s 10.42.0.0/16 -d 10.42.0.0...-j RETURNJan 29 17:06:03 example01 k3s[19442]: I0129 17:06:03.148358 19442 iptables.go:228] Adding iptables rule: ! -s 10.42.0.0/16 -d 10.42.0.0...ASQUERADEJan 29 17:06:03 example01 k3s[19442]: W0129 17:06:03.297662 19442 handler_proxy.go:101] no RequestInfo found in the contextJan 29 17:06:03 example01 k3s[19442]: E0129 17:06:03.297804 19442 controller.go:116] loading OpenAPI spec for "v1beta1.metrics.k8s.io" ...availableJan 29 17:06:03 example01 k3s[19442]: , Header: map[Content-Type:[text/plain; charset=utf-8] X-Content-Type-Options:[nosniff]]Jan 29 17:06:03 example01 k3s[19442]: I0129 17:06:03.297827 19442 controller.go:129] OpenAPI AggregationController: action for item v1b... Requeue.Jan 29 17:06:03 example01 k3s[19442]: I0129 17:06:03.551453 19442 request.go:668] Waited for 1.08111535s due to client-side throttling,...unt/tokenHint: Some lines were ellipsized, use -l to show in full.
应用如下命令查看 k3s 节点:
# k3s kubectl get nodeNAME STATUS ROLES AGE VERSIONexample01 Ready control-plane,master 3m37s v1.21.7+k3s1
ℹ️ 信息:
调整 K3S 装置目录后,k3s token 地位在:
/data/rancher/k3s/server/token
总结
至此,K3s 在离线-有代理条件下装置实现。
- Master 和 Server 地址:
192.168.0.101
- K3S API Server 地址:https://192.168.0.101:6443
- K3S kubeconfig 配置:位于
/etc/rancher/k3s/k3s.yaml
- K3S 存放数据的目录:
/data/rancher/k3s
- K3S 本地存储类的默认存储门路:
/data/rancher/k3s/storage
三人行, 必有我师; 常识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写.