安装
https://kubernetes.io/zh-cn/docs/tasks/tools/install-kubectl-linux/
kubectl 版本和集群版本之间的差异必须在一个小版本号内。 例如:v1.28 版本的客户端能与 v1.27、 v1.28 和 v1.29 版本的控制面通信。 用最新兼容版的 kubectl 有助于避免不可预见的问题。
shell 自动补全
1 | apt-get install bash-completion |
Bash、Fish 和 Zsh
1 | echo $SHELL |
中控机
commands
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs
crd
1 | ❯ kubectl get crd | grep traefik.containo.us | awk '{print $1}' |
pod
重启
1 | kubernetes-dashboard kubernetes-dashboard-6495566f7b-9p5mq 0/1 ImagePullBackOff 0 9m43s |
rollout restart
logs
tail
1 | ❯ kubectl logs --tail=10 kubernetes-dashboard-6495566f7b-9p5mq -n kubernetes-dashboard |
since
过去时间写入日志
1 | ❯ kubectl logs --since=23h09m pod/traefik-7d7459bcdc-swkl5 |
{“level”:”warning”,”msg”:”Error checking new version: Get "https://update.traefik.io/repos/traefik/traefik/releases\": dial tcp: lookup update.traefik.io on 10.96.1.10:53: server misbehaving”,”time”:”2023-10-16T00:11:12Z”}
since-time
指定日期的日志
1 | ❯ kubectl logs --since-time=2023-10-16T00:11:00Z pod/traefik-7d7459bcdc-swkl5 |
{“level”:”warning”,”msg”:”Error checking new version: Get "https://update.traefik.io/repos/traefik/traefik/releases\": dial tcp: lookup update.traefik.io on 10.96.1.10:53: server misbehaving”,”time”:”2023-10-16T00:11:12Z”}
krew
https://krew.sigs.k8s.io/docs/user-guide/setup/install/
把export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
添加到环境变量.bashrc
或.zshrc
网不好,使用代理
https://github.com/521xueweihan/GitHub520 hosts文件
1 | #v0.4.4 |
验证
1 | ❯ kubectl krew |
本地安装插件
1 | kubectl krew install --manifest=xx.yaml --archive=kubectl-xx_linux_amd64.zip |
https://krew.sigs.k8s.io/docs/developer-guide/custom-indexes/