kubectl
...
Nodes
k8s查看节点CPU消耗情况,可以用kubectl top命令,但是会出现
kubectl top nodes
error: Metrics API not available
退而求之
kubectl describe node <node-name> | tail -n 8
memory 13640Mi (33%) 25916Mi (64%)
ephemeral-storage 0 (0%) 0 (0%)
hugepages-1Gi 0 (0%) 0 (0%)
hugepages-2Mi 0 (0%) 0 (0%)
Events: <none>
kubectl 是操作 Kubernetes 集群的命令行工具。通过 kubectl 可以部署和管理应用,查看各种资源,创建、删除和更新各种组件。
常见的操作可以使用以下 kubectl 命令完成:
kubectl get - 列出资源
kubectl get nodes
kubectl get pods
kubectl get pods | grep <xxx>
# 查找非Running状态的pod
kubectl get pods -A --field-selector=status.phase!=Running
kubectl describe - 显示有关资源的详细信息
# 显示指定node的详细信息
kubectl describe node <node_name>
kubectl describe node <node_name> | grep IP
# 日志相关
# 打印 pod 和其中容器的日志
kubectl logs --help
kubectl logs <pod-name>
# 查看实时日志,持续输出
kubectl logs -f <pod-name>
# 查看最新20条实时日志,持续输出
kubectl logs -f --tail=20 <pod-name>
# 查看从指定时间之后的日志
kubectl logs --since=1h <pod-name>
#
kubectl exec - 在 pod 中的容器上执行命令
todo:
--kubeconfiig=./config-1 get deployment nginx -o yaml | grep nginx或image
--kubeconfiig=./config-2 get deployment nginx -o yaml | grep nginx或image
--kubeconfiig=./config-m get deployment nginx -o yaml | grep nginx或image
可以使用这些命令查看应用程序的部署时间,当前状态,运行位置以及配置。