1.Rancher 导入已存在的k8s集群:
1.1 Rancher界面配置:
登录Rancher,进入如下界面:
点击 导入已有集群 如下图:
选择导入任意Kubernetes集群 填写集群名称,点击创建。
1.2 k8s集群加入命令:
在要加入的集群上执行如下命令:
# 编辑/etc/hosts文件:
[root@yan-master1 ~]# vim /etc/hosts
10.121.218.210 rancher.my.org #添加
#根据生成情况执行如下命令:
[root@yan-master1 ~]# curl --insecure -sfL https://rancher.my.org/v3/import/m5xfh58s2qgvptkgts76wkcmqv7rtzzhlsbnpjb8tjcfrh26pzw5cv_c-m-pv5xxgdv.yaml | kubectl apply -f -
clusterrole.rbac.authorization.k8s.io/proxy-clusterrole-kubeapiserver created
clusterrolebinding.rbac.authorization.k8s.io/proxy-role-binding-kubernetes-master created
namespace/cattle-system created
serviceaccount/cattle created
clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding created
secret/cattle-credentials-da9bc0d created
clusterrole.rbac.authorization.k8s.io/cattle-admin created
deployment.apps/cattle-cluster-agent created
service/cattle-cluster-agent created
如果你没有内部DNS服务器而是通过添加/etc/hosts主机别名的方式指定的Rancher server域名,那么不管通过哪种方式(自定义、导入、Host驱动等)创建K8S集群,K8S集群运行起来之后,因为cattle-cluster-agent Pod和cattle-node-agent无法通过DNS记录找到Rancher server,最终导致无法通信。
可以通过给cattle-cluster-agent Pod和cattle-node-agent添加主机别名(/etc/hosts),让其可以正常通信(前提是IP地址可以互通)。
注意:替换以下命令中的域名和ip
cattle-cluster-agent pod
[root@yan-master1 ~]# kubectl -n cattle-system patch deployments cattle-cluster-agent --patch '{
"spec": {
"template": {
"spec": {
"hostAliases": [
{
"hostnames":
[
"rancher.my.org"
],
"ip": "10.121.218.210"
}
]
}
}
}
}'
deployment.apps/cattle-cluster-agent patched
添加成功。