kubectl是管理kubernetes的轻量级工具,可以极大提高管理效率。
别名和自动补全,编辑 bashrc或者zshrc
$vim ~./bashrcalias k="kubectl"complete -F __start_kubectl k$vim ~./zshrcalias k="kubectl"complete -F __start_kubectl k
kubectl
的帮助文档使用方便,如果命令使用方法不清楚,可以直接输入k <command> --help
$k label -h----------------------------Examples:# Update pod 'foo' with the label 'unhealthy' and the value 'true'.kubectl label pods foo unhealthy=true# Update pod 'foo' with the label 'status' and the value 'unhealthy', overwriting any existing value.kubectl label --overwrite pods foo status=unhealthy# Update all pods in the namespacekubectl label pods --all status=unhealthy# Update a pod identified by the type and name in "pod.json"kubectl label -f pod.json status=unhealthy# Update pod 'foo' only if the resource is unchanged from version 1.kubectl label pods foo status=unhealthy --resource-version=1# Update pod 'foo' by removing a label named 'bar' if it exists.# Does not require the --overwrite flag.kubectl label pods foo bar-
查看系统资源的基本命令
$ k get pods$ k get nodes$ k get services# You can sort too$ k get pods --sort-by=.status.startTime# Get with a label selector$ k get pods -l app=kombucha-service# Watch over time$ k get pods -l app=kombucha-service --watch# View the events$ k get events# Describe the pod$ k describe pod <pod-name>$ k api-resources
系统调试与故障排查
# Follow the logs of a pod$ k logs -f <pod-name> -c <container-name># For only the tail, use `--tail=n`$ k logs <pod-name> -c <container-name> --tail=50# Multiple pods at once$ k logs -l foo=bar
文章转载自linuxcmd,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




