0. 概述
kubectl 作为默认的 Kubernetes 命令行工具,具有的功能和选项非常多,所以我就最常用的一些功能和选项进行一个汇总。
1. 安装 kubectl
[[email protected].io]# curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
[[email protected].io]# curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
[[email protected].io]# echo "$(<kubectl.sha256) kubectl" | sha256sum --check
kubectl: OK
[[email protected].io]# sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
如果输出的字符串不一样,请重新下载。
2. 通过 label 过滤资源
[[email protected].io]# kubectl get pods -l environment=production,tier=frontend
3. 根据 label set 过滤
[[email protected].io]# kubectl get pods -l 'environment in (production, qa)'
[[email protected]g.io]# kubectl get pods -l 'environment,environment notin (frontend)'
4. 根据 label 组合过滤
[[email protected].io]# kubectl get pods -l 'environment in (production),tier in (frontend)'