Rancher执行kubectl命令
Rancher部署成功后执行kubectl命令只能在控制台执行,无法在宿主机直接执行很不方便。
配置步骤:
1.在宿主机上下载kubectl 二进制文件
[root@devops-k8s19-38 ~]# curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 45.3M 100 45.3M 0 0 2803k 0 0:00:16 0:00:16 --:--:-- 2809k
[root@devops-k8s19-38 ~]# chmod +x ./kubectl
[root@devops-k8s19-38 ~]# sudo mv ./kubectl /usr/local/bin/kubectl
如果服务器上下载不了kubectl可去github release页面下载最新版kubectl,再上传至服务器
2.复制集群的kubeconfig文件
进入集群仪表盘,选中集群进入,复制kubeconfig文件中全部内容
3.在安装好kubectl的机器上配置kubeconfig ,将复制的文件内容全部保存在config文件中
[root@devops-k8s19-38 ~]# mkdir ~/.kube [root@devops-k8s19-38 ~]# vim ~/.kube/config
4. 测试是否可以执行kubectl 命令
[root@devops-k8s19-38 ~]# kubectl get ns NAME STATUS AGE cattle-system Active 24h default Active 24h fleet-system Active 24h ingress-nginx Active 24h kube-node-lease Active 24h kube-public Active 24h kube-system Active 24h security-scan Active 24h [root@devops-k8s19-38 ~]# [root@devops-k8s19-38 ~]# [root@devops-k8s19-38 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION devops-k8s19-38 Ready controlplane,etcd,worker 25h v1.19.10 devops-k8s19-39 Ready worker 24h v1.19.10 devops-k8s19-40 Ready worker 24h v1.19.10 [root@devops-k8s19-38 ~]#