您可以通过 Kubernetes 命令行工具 kubectl 从本地客户端机器连接到 TKE 集群。
这里是官方文档https://cloud.tencent.com/document/product/457/8438
写这篇的意义主要记录一些小问题,以及单个客户端如何连接多个TKE集群
这个一看就知道是国内下载不了系列,请发挥您的智慧下载吧,这里我是添加了国内源直接yum -y install kubectl-1.10.5 如不加版本默认下载最新版本
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.13/bin/linux/amd64/kubectl
注:v1.8.13可根据需求替换成业务所需的kubectl版本。 关于版本的事情不得不多说一句,尽量跟着自己集群的版本走,我在实验的过程中下了最新的kubectl1.11的,有些指令不识别了。
这里一路跟着教程走就行了
方法一:单次 kubectl 操作请求,附带证书信息
该方法适用于单次操作集群,不将容器集群的证书信息保存到机器上。
请求方法,kubectl 命令格式:
kubectl get node -s "域名信息/外网访问地址" --username=用户名 --password=密码 --certificate-authority=证书路径
示例:
kubectl get node -s "https://cls-66668888.ccs.tencent-cloud.com" --username=admin --password=6666o9oIB2gHD88882quIfLMy6666 --certificate-authority=/etc/kubernetes/cluster-ca.crt
如果用的是内网访问地址,将会出现Unable to connect to the server: i/o timeout
,这里如果有读者了解的可以在评论中指出
[root@VM_0_7_centos ~]# kubectl get node -s "cls-h5dfwr4g.ccs.tencent-cloud.com" --username=xxxx --password=xxxx --certificate-authority=/etc/kubernetes/cluster-ca.crt
Unable to connect to the server: dial tcp 10.0.0.12:80: i/o timeout
[root@VM_0_7_centos ~]# cat /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 VM_0_7_centos VM_0_7_centos
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
# The following lines are desirable for IPv6 capable hosts
::1 VM_0_7_centos VM_0_7_centos
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
10.0.0.12 cls-h5dfwr4g.ccs.tencent-cloud.com
到此就可以正确的获取到集群的信息了
[root@VM_0_7_centos ~]# kubectl get node -s "https://cls-h5dfwr4g.ccs.tencent-cloud.com" --username=admin --password=XyUi2kzTM7yhPiynfrDnuhBdX0Uzinvi --certificate-authority=/etc/kubernetes/cluster-ca.crt
NAME STATUS ROLES AGE VERSION
10.0.0.4 Ready <none> 5h v1.10.5-qcloud
10.0.0.5 Ready <none> 4h v1.10.5-qcloud
至于操作多个集群,就是把域名信息换了,账户密码换了还有证书换了。
如果想修改 kubectl 配置文件,且多集群的请继续往下看
该方法适用于长期通过 kubectl 操作集群, 一次配置,只要文件不修改就长期有效。
背景:假设我有两个集群,一个是生产集群,一个是测试集群,我想通过kubectl操作多个集群请往下配置:
首先配置生产集群的链接
kubectl config set-credentials produce-admin --username=admin --password=6666o9oIB2gHD88882quIfLMy6666
kubectl config set-cluster produce-cluster --server=https://cls-66668888.ccs.tencent-cloud.com --certificate-authority=/etc/kubernetes/cluster-ca.crt
kubectl config set-context produce-system --cluster=produce-cluster --user=produce-admin
配置的格式以及含义
kubectl config set-credentials NAME [--username=basic_user] [--password=basic_password]
kubectl config set-cluster NAME [--server=server] [--certificate-authority=path/to/certficate/authority]
kubectl config set-context NAME [--cluster=cluster_nickname] [--user=user_nickname] [--namespace=namespace]
set-credentials 在kubeconfig配置文件中设置一个用户项。
set-cluster 在kubeconfig配置文件中设置一个集群项。
set-context 在kubeconfig配置文件中设置一个环境项。
配置完,切换环境项
kubectl config use-context produce-system
这样直接输入kubectl get node即可查看produce-system集群的信息。
那么第二个集群只需照葫芦画瓢创建第二个环境再用use-context切换即可
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。