kubectl客户端安装使用

二进制安装
kubectl for linux
1、下载最新版本
curl -LO “https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl”
需要特定版本:
curl -LO https://dl.k8s.io/release/v1.29.1/bin/linux/amd64/kubectl

2、验证kubectl命令(可选)
curl -LO “https://dl.k8s.io/release/ ( c u r l − L − s h t t p s : / / d l . k 8 s . i o / r e l e a s e / s t a b l e . t x t ) / b i n / l i n u x / a m d 64 / k u b e c t l . s h a 256 " V a l i d a t e t h e k u b e c t l b i n a r y a g a i n s t t h e c h e c k s u m f i l e : e c h o " (curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256" Validate the kubectl binary against the checksum file: echo " (curlLshttps://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"Validatethekubectlbinaryagainstthechecksumfile:echo"(cat kubectl.sha256) kubectl” | sha256sum --check

3、If valid, the output is:
kubectl: OK
4、安装 kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Note:
If you do not have root access on the target system, you can still install kubectl to the ~/.local/bin directory:

chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectl

and then append (or prepend) ~/.local/bin to $PATH

5、使用测试
kubectl version --client
kubectl version --client --output=yaml

二、远程连接k8s集群
1、查看k8s集群master的config文件,拷贝客户端linux主机。
1)k8s集群的master节点上面查看:cat $HOME/.kube/config
2)在linux主机上指定目录面创建一个.kube/config的文件

2、在非k8s集群主机使用kubectl命令查看k8s集群信息。
kubectl --kubeconfig=【指定config配置文件的路径】 get pods

kubectl --kubeconfig=/root/bhs/.kube/config get pods

安装参考文档:https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-other-package-management

  • 10
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值