Centos 安装kubectl 连接rancher

  1. 进入master节点
  2. 使用root账户
  3. cd ~
  4. vim install_kubectl.sh 内容如下
#!/bin/bash
cat < /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
  1. 安装kubectl./install_kubectl.sh
  2. 进入rancher的k8s集群页面:

点击右上角的Kube
F68F4801-AE93-4B49-9945-6693E8CBFCA6.png

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客户端完成

你可能感兴趣的:(Centos 安装kubectl 连接rancher)