- 进入master节点
- 使用root账户
- cd ~
-
vim install_kubectl.sh
内容如下
#!/bin/bash
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
- 安装kubectl
./install_kubectl.sh
- 进入rancher的k8s集群页面:
config文件复制保存
在客户端的主机上面新建文kube的文件夹
[root@localhost ~]# mkdir -p /root/.kube/
[root@localhost ~]# cd /root/.kube/
### 把刚才复制保存的config文件放到下面对应的路径下
[root@localhost ~]# vi config
执行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客户端完成