Centos 7 kubectl 客户端连接rancher里面的k8s
1 centos7 安装最新版本的kubectl
脚本如下:install_kubectl.sh
#!/bin/bash
# make sunny sunnylinux@foxmail.com
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
sleep 5
yum install -y kubectl kubelet kubeadm
systemctl enable kubelet
systemctl start kubelet
2 获取rancher上面的k8s集群的config文件
进入rancher的k8s集群页面:
点击右上角的Kubeconfig文件复制保存
在客户端的主机上面新建文kube的文件夹
[root@localhost ~]# mkdir -p /root/.kube/
root@localhost ~]# cd /root/.kube/
把刚才复制保存的config文件放到下面对应的路径下
[root@localhost ~]# vi config
[root@localhost .kube]# ls
cache config
[root@localhost .kube]#
执行kubectl get nodes
[root@localhost .kube]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node3 Ready controlplane,etcd,worker 189d v1.17.4
node4 Ready controlplane,etcd,worker 189d v1.17.4
Centos7 建立k8s客户端完成