[英]How to describe a Kubernetes cluster using kubectl?
I want to check the Kube.netes configuration - how many nodes, etc. I tried the following command.我想检查 Kube.netes 配置 - 有多少节点等。我尝试了以下命令。
kubectl describe cluster
error: the server doesn't have a resource type "cluster"
BTW, I tried to use the following command to check the AZ of the nodes of the pods.顺便说一句,我尝试使用以下命令来检查 pod 节点的 AZ。 But it returns
<none>
for all the pods' nodes.但它为所有 pod 的节点返回
<none>
。
kubectl get pods -o=custom-columns=NAME:.metadata.name,ZONE:.metadata.labels.'topology\.Kubernetes\.io/zone'
How to use kubectl
to find the AZs of the pods?如何使用
kubectl
查找 pod 的可用区?
I could be missing the point of your question, but if you just need the nodes, you could do我可能会错过你的问题,但如果你只需要节点,你可以做
kubectl get nodes
and then接着
kubectl describe node {node-name}
to get further details of an individual node获取单个节点的更多详细信息
You could also combine the output from kubectl get nodes
and either use jsonpath
or jq
to filter the information you need.您还可以结合
kubectl get nodes
中的 output 并使用jsonpath
或jq
来过滤您需要的信息。
Here are my nodes showing zone info(made up) in the cluster:这是我的节点显示集群中的区域信息(组成):
kubectl get node -Ltopology.kubernetes.io/zone
NAME STATUS ROLES AGE VERSION ZONE
development-kube-controller-1 Ready control-plane 48d v1.24.6 zone
development-kube-worker-1 Ready <none> 48d v1.24.6 zone-A
development-kube-worker-2 Ready <none> 48d v1.24.6 zone-B
Using the awk
command, the label topology.kube.netes.io/zone
is merged with the name of the pods scheduled on that particular node.使用
awk
命令,label topology.kube.netes.io/zone
与计划在该特定节点上的 pod 的名称合并。
NOTE : I have used lowercase k
in the label key topology\.kube.netes\.io/zone
;注意:我在 label key
topology\.kube.netes\.io/zone
中使用了小写的k
; however, in your case, it's uppercase K
in the question.但是,在您的情况下,问题中的
K
是大写的。 You might want to calibrate your command.您可能想要校准您的命令。
kubectl describe node |awk '/topology.kubernetes.io\/zone/{zone=$1;next} /^ Namespace/{flag=1; getline; next} /^Allocated resources:/{flag=0} flag{print $2, zone}' |column -t
calico-node-swz7j topology.kubernetes.io/zone=zone
coredns-74d6c5659f-4mpcp topology.kubernetes.io/zone=zone
dns-autoscaler-59b8867c86-w4dls topology.kubernetes.io/zone=zone
kubernetes-dashboard-648989c4b4-b4k7h topology.kubernetes.io/zone=zone-A
kubernetes-metrics-scraper-84bbbc8b75-x72pf topology.kubernetes.io/zone=zone-A
nginx-proxy-development-kube-worker-1 topology.kubernetes.io/zone=zone-A
nodelocaldns-xt6hr topology.kubernetes.io/zone=zone-A
metallb-controller-94c85f6db-6j8j5 topology.kubernetes.io/zone=zone-A
metallb-speaker-4fz99 topology.kubernetes.io/zone=zone-A
argocd-application-controller-0 topology.kubernetes.io/zone=zone-B
argocd-applicationset-controller-5bff759d68-kk7tx topology.kubernetes.io/zone=zone-B
argocd-dex-server-59c59b5d96-7z7th topology.kubernetes.io/zone=zone-B
argocd-notifications-controller-6df97c8577-26z9m topology.kubernetes.io/zone=zone-B
argocd-redis-684fb8c6dd-bxb25 topology.kubernetes.io/zone=zone-B
argocd-repo-server-79d8c5f7b4-fnh7g topology.kubernetes.io/zone=zone-B
PS: You can print $1
in the awk
command to print the namespace, in case of filtering based on namespace is needed. PS:可以在
awk
命令中打印$1
来打印命名空间,以防需要根据命名空间进行过滤。
Try this command试试这个命令
kubectl cluster-info
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.