k8s

rancher使用代理添加集群

环境

内网集群,需要使用跳板机做代理,添加到公网rancher中。

内网机器:192.168.1.1
跳板机:192.168.1.2
公网rancher:1.2.3.4

步骤

官网文档中,写明了如何在使用代理的情况下注册集群。
https://ranchermanager.docs.rancher.com/zh/how-to-guides/new-user-guides/kubernetes-clusters-in-rancher-setup/register-existing-clusters

file

导入集群

添加环境变量:

HTTP_PROXY:192.168.1.2:3128
HTTPS_PROXY:192.168.1.2:3128
NO_PROXY:127.0.0.1,localhost

file

使用上篇文章中的四层代理,修改公网ip地址和端口即可。

file

在公网机器上查看32444端口,不存在。需要修改rancher-svc为nodePort。

file

修改后:

file

修改导入命令中的公网地址1.2.3.4:32444192.168.1.2:3128

curl --insecure -sfL https://192.168.1.2:3128/v3/import/7c9h247mrrzbg2m9zpdw694px2spbn79zvbxhjq8n4w4khmkxd6cft_c-m-ncs76rvp.yaml | kubectl apply -f -

file

默认生成的deploy中CATTLE_SERVER使用的是公网地址,需要修改为内网地址。

file

- name: CATTLE_SERVER
          value: https://192.168.1.2:3128

仍然无法启动,删除env中的HTTPS_PROXY后,pod启动成功。

- name: CATTLE_SERVER
          value: https://192.168.1.2:3128
- name: NO_PROXY
          value: 127.0.0.1,localhost

日志报错:"Failed to connect to proxy. Empty dialer response" error="dial tcp 1.2.3.4:32444: i/o timeout"

file

进入容器查看env,curl代理地址通的,说明env已经生效了。但还是用的公网地址连接。

curl https://192.168.1.2:3128 -k

查看deployment,挂载了cattle-credentials的secret,查看secret,把url用base64解密,确认为公网地址1.2.3.4:31244。

file

修改secret中的url为内网地址,

echo 'https://192.168.1.2:3128' | base64

file

报错信息是:"parse \"http://192.168.1.2:3128\\n\": net/url: invalid control character in URL"

file

试了很多次都不行,使用在线网站加密。https://stackoverflow.org.cn/base64/。 删除后面的Cg==,保存。重启pod。

file

URL没有报错了,但是证书报错了:"Certificate chain is not complete, please check if all needed intermediate certificates are included in the server certificate (in the correct order) and if the cacerts setting in Rancher either contains the correct CA certificate (in the case of using self signed certificates) or is empty (in the case of using a certificate signed by a recognized CA). Certificate information is displayed above. error: Get \"https://192.168.1.2:3128\": x509: certificate signed by unknown authority (possibly because of \"x509: ECDSA verification failure\" while trying to verify candidate authority certificate \"dynamiclistener-ca\")"

file

参考这篇issue:https://github.com/rancher/rancher/issues/36632

我的rancher server是helm部署的,使用的ingress,导致证书不一致。

file

可能的解决方案是把rancher换成单节点docker部署,我这里暂未替换。

分类: k8s
0 0 投票数
文章评分
订阅评论
提醒
guest

0 评论
内联反馈
查看所有评论

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部
0
希望看到您的想法,请您发表评论x