docker run
安装的单容器Rancher Server
# 进入容器
docker exec -ti <容器ID> bash
# 集群ID,可通过浏览器地址栏查询
cluster_id=c-xxx
kubectl get secret c-${cluster_id} -n cattle-system -o=jsonpath='{.data.cluster}'
| base64 --decode | jq .metadata.state | awk '{print substr($0,2,length($0)-2)}'
> ${cluster_id}-kube-config.yml
sed -i 's/\n/
/g' ${cluster_id}-kube-config.yml &&
sed -i 's/\"/"/g' ${cluster_id}-kube-config.yml
Rancher HA
# 依赖工具: jq、awk
# local集群的kube配置文件
local_kube_config=xxx
# 集群ID,可通过浏览器地址栏查询
cluster_id=c-xxx
kubectl --kubeconfig=$local_kube_config get secret c-${cluster_id}
-n cattle-system
-o=jsonpath='{.data.cluster}' | base64 --decode |
jq .metadata.state | awk '{print substr($0,2,length($0)-2)}'
> ${cluster_id}-kube-config.yml
sed -i 's/\n/
/g' ${cluster_id}-kube-config.yml &&
sed -i 's/\"/"/g' ${cluster_id}-kube-config.yml
kubectl变量设置
方法1:
export KUBECONFIG=$(pwd)/${cluster_id}-kube-config.yml
说明:如果由多个集群,通过声明变量操作。
方法2:
cat ${cluster_id}-kube-config.yml> .kube/config
说明:将配置信息写入config文件中即可。