客户端操作
centos7 系统:

[root@k8s ~]# cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enable=1
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
[root@k8s ~]# yum list kubectl --showduplicates | sort -r

这里使用的版本是1.20.4,最好与集群版本一直,可使用kubectl get node查看

[root@k8s ~]# yum install kubectl-1.20.4-0 -y
[root@k8s ~]# mkdir ~/.kube

scp到master节点,我这里master节点hosts表域名是k8s-master,用户是student

[root@k8s ~]# scp student@k8s-master:/home/studnet/.kube/* ~/.kube
[root@k8s ~]# echo "export KUBECONFIG=$HOME/.kube/admin.conf" >> ~/.bash_profile
[root@k8s ~]# echo "source <(kubectl completion bash)" >> ~/.bash_profile
[root@k8s ~]# source ~/.bash_profile
[root@k8s ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master.lab.example.com Ready master 13d v1.20.4
k8s-node1.lab.example.com Ready <none> 13d v1.20.4
k8s-node2.lab.example.com Ready <none> 13d v1.20.4

ubuntu系统:

k8s@k8s:~$ sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
sudo bash -c "echo deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main \
>> /etc/apt/sources.list.d/kubernetes.list"
k8s@k8s:~$ sudo apt-get update
k8s@k8s:~$ sudo apt-cache policy kubelet
k8s@k8s:~$ sudo apt-get install kubectl=1.20.4-00 -y
k8s@k8s:~$ mkdir ~/.kube
k8s@k8s:~$ scp student@k8s-master:/home/student/.kube/* ~/.kube
k8s@k8s:~$ echo "export KUBECONFIG=$HOME/.kube/admin.conf" >> ~/.bash_profile
k8s@k8s:~$ echo "source <(kubectl completion bash)" >> ~/.bash_profile
k8s@k8s:~$ source ~/.bash_profile
k8s@k8s:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master.lab.example.com Ready master 13d v1.20.4
k8s-node1.lab.example.com Ready <none> 13d v1.20.4
k8s-node2.lab.example.com Ready <none> 13d v1.20.4
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐