二进制安装
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 "
(curl−L−shttps://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