导入集群

进入之后选择导入已有集群,随后进入此页面,点击创建

对于自签证书选择第二项,复制,然后在k3s-server节点执行

问题

error: no objects passed to apply

这里的问题主要是无法连接到部署Rancher的主机,无法获取yaml文件导致的。可以将yaml文件直接下载到k3s-server,再手动执行kubectl apply -f {xxx}.yaml

(针对配置了--tls-san参数 - 自签证书)可能会执行失败,提示域名rancher.k3s.cn 不识别(前面的证书域名以及对应ip)

更新资源的字段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(because the cert was made by myself,so i need configured the hosts, otherwise it does not know my cert's domain name,unless you used ip instead of domain name)
kubectl -n cattle-system patch deployments rancher --patch '{
"spec": {
"template": {
"spec": {
"hostAliases": [
{
"hostnames":
[
"rancher.k3s.cn"
],
"ip": "192.168.56.100"
}
]
}
}
}
}'
kubectl -n cattle-system patch deployments cattle-cluster-agent --patch '{
"spec": {
"template": {
"spec": {
"hostAliases": [
{
"hostnames":
[
"rancher.k3s.cn"
],
"ip": "192.168.56.100"
}
]
}
}
}
}'

(针对helm安装方式)出现[Ready False [Disconnected] Cluster agent is not connected]问题

参考: https://github.com/rancher/rancher/issues/36589

1
2
3
4
# 得到<REPLACE_WITH_CLUSTERID>
kubectl get clusters.management.cattle.io
# 替换<REPLACE_WITH_CLUSTERID>
kubectl patch clusters.management.cattle.io <REPLACE_WITH_CLUSTERID> -p '{"status":{"agentImage":"dummy"}}' --type merge

查看启动情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@k3s-node1 ca]# kubectl get pods -n cattle-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cattle-cluster-agent-56855585c4-h4jj9 1/1 Running 0 13m 10.42.2.10 k3s-node3 <none> <none>
cattle-cluster-agent-56855585c4-n76gp 1/1 Running 0 13m 10.42.1.8 k3s-node2 <none> <none>
helm-operation-dpvhn 0/2 Completed 0 24m 10.42.2.3 k3s-node3 <none> <none>
helm-operation-l9psd 0/2 Completed 0 14m 10.42.2.8 k3s-node3 <none> <none>
helm-operation-xvmzb 0/2 Completed 0 24m 10.42.2.4 k3s-node3 <none> <none>
helm-operation-zqhk8 0/2 Completed 0 24m 10.42.2.5 k3s-node3 <none> <none>
rancher-8754895f9-9g58q 1/1 Running 0 26m 10.42.1.3 k3s-node2 <none> <none>
rancher-webhook-6979fbd4bf-zh8gt 1/1 Running 0 24m 10.42.1.6 k3s-node2 <none> <none>
[root@k3s-node1 ca]# kubectl logs cattle-cluster-agent-56855585c4-h4jj9 -n cattle-system
INFO: Environment: CATTLE_ADDRESS=10.42.2.10 CATTLE_CA_CHECKSUM=5ae946e89c419fd7f06d394c4a883abddda422c9912c2eb9c00e443072adaa3f CATTLE_CLUSTER=true CATTLE_CLUSTER_AGENT_PORT=tcp://10.43.76.16:80 CATTLE_CLUSTER_AGENT_PORT_443_TCP=tcp://10.43.76.16:443 CATTLE_CLUSTER_AGENT_PORT_443_TCP_ADDR=10.43.76.16 CATTLE_CLUSTER_AGENT_PORT_443_TCP_PORT=443 CATTLE_CLUSTER_AGENT_PORT_443_TCP_PROTO=tcp CATTLE_CLUSTER_AGENT_PORT_80_TCP=tcp://10.43.76.16:80 CATTLE_CLUSTER_AGENT_PORT_80_TCP_ADDR=10.43.76.16 CATTLE_CLUSTER_AGENT_PORT_80_TCP_PORT=80 CATTLE_CLUSTER_AGENT_PORT_80_TCP_PROTO=tcp CATTLE_CLUSTER_AGENT_SERVICE_HOST=10.43.76.16 CATTLE_CLUSTER_AGENT_SERVICE_PORT=80 CATTLE_CLUSTER_AGENT_SERVICE_PORT_HTTP=80 CATTLE_CLUSTER_AGENT_SERVICE_PORT_HTTPS_INTERNAL=443 CATTLE_CLUSTER_REGISTRY= CATTLE_FEATURES=embedded-cluster-api=false,fleet=false,monitoringv1=false,multi-cluster-management=false,multi-cluster-management-agent=true,provisioningv2=false,rke2=false CATTLE_INTERNAL_ADDRESS= CATTLE_IS_RKE=false CATTLE_K8S_MANAGED=true CATTLE_NODE_NAME=cattle-cluster-agent-56855585c4-h4jj9 CATTLE_SERVER=https://rancher.k3s.cn CATTLE_SERVER_VERSION=v2.6.2
INFO: Using resolv.conf: search cattle-system.svc.cluster.local svc.cluster.local cluster.local nameserver 10.43.0.10 options ndots:5
INFO: https://rancher.k3s.cn/ping is accessible
INFO: rancher.k3s.cn resolves to 192.168.56.103
INFO: Value from https://rancher.k3s.cn/v3/settings/cacerts is an x509 certificate
time="2022-02-28T01:47:19Z" level=info msg="Listening on /tmp/log.sock"
time="2022-02-28T01:47:19Z" level=info msg="Rancher agent version v2.6.2 is starting"
time="2022-02-28T01:47:19Z" level=info msg="Connecting to wss://rancher.k3s.cn/v3/connect/register with token starting with js9fmwx7h5vtftr2rwljnwcbv7p"
time="2022-02-28T01:47:19Z" level=info msg="Connecting to proxy" url="wss://rancher.k3s.cn/v3/connect/register"
time="2022-02-28T01:47:19Z" level=info msg="Starting /v1, Kind=Service controller"

不需要被 Rancher 管理导入的集群该怎么做?

如果导入集群从 Rancher UI 删除了,这个集群就不受 Rancher 管理了。集群本身不会受到影响,并可以使用导入到 Rancher 之前的方法访问集群。

删除导入集群的步骤如下:

  1. 全局视图,进入集群菜单。
  2. 选择需要删除的导入集群,单击更多 (...) > 删除
  3. 单击删除

结果: 导入集群从 Rancher 中删除,在 Rancher 之外集群正常运行。