# 安装kubectl

# 安装指令

brew install kubectl
brew install kubectx
brew install kubens
1
2
3

# 安装kube

如果brew安装慢,是因为网络问题,我们可以手动下载。 https://hub.fastgit.org/ahmetb/kubectx/releases

# 安装配置

创建.kube目录

mkdir ~/.kube
1

将k8s配置加入到~/.kube/config

apiVersion: v1
clusters:
  - cluster:
        server: [K8S API地址]
        certificate-authority-data: [认证数据]
    name: [集群名字]
contexts:
  - context:
        cluster: [集群名字]
        user: [集群用户名]
        namespace: default
    name: [集群名字]
kind: Config
preferences: {}
users:
  - name: [集群用户名]
    user:
        client-certificate-data: [认证数据]
        client-key-data: [认证key]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 测试指令

# 查看集群列表
➜  ~ kubectx
[集群名字]

# 选择集群名称
➜  ~ kubectx [集群名字]
✔ Switched to context [集群名字].

# 查看命名空间列表
➜  ~ kubens           
default
kube-node-lease
kube-public
kube-system

# 选择命名空间
➜  ~ kubens default
✔ Active namespace is "default"

# 查看Pod信息
➜  ~ kubectl get pod                              
NAME                    READY   STATUS    RESTARTS   AGE
test-6d565dbb89-9456x   1/1     Running   0          16h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
上次更新: 5/20/2021, 11:12:30 PM