简体   繁体   English

如何使用 kubectl 描述 Kube.netes 集群?

[英]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 并使用jsonpathjq来过滤您需要的信息。

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.

相关问题 如何使用 Fargate 创建 AWS Kube.netes 集群 (EKS)? - How to create a AWS Kubernetes cluster (EKS) using Fargate? 如何使用 terraform 限制 kube.netes 集群上的磁盘使用 - How to limit disk usage on kubernetes cluster using terraform 来自 kubectl logs 命令的 Kube.netes 日志与 GKE 集群中的 /var/log/containers 不同 - Kubernetes logs from kubectl logs command is different to /var/log/containers in GKE cluster 无法使用 Kops 验证 Kube.netes 集群 - Unable to validate Kubernetes cluster using Kops 如何让 kubectl 登录到 AWS EKS 集群? - How do you get kubectl to log in to an AWS EKS cluster? 如何设置 kube.netes 集群的 pod 启动顺序? - How to set the startup order of pods of a kubernetes cluster? kube.netes 集群管理员如何创建 VolumeSnapshotContents? - How does a kubernetes cluster administrator create VolumeSnapshotContents? kubectl 描述未知的速记标志 -o - kubectl describe unknown shorthand flag -o 如何使用 kubectl 在 Google Kube.netes Engine (GKE) 集群之间切换? - How can I switch between Google Kubernetes Engine (GKE) clusters with kubectl? 如何使用 kubectl 检查应用程序的容器/pod 是否分布到 AWS EKS 集群中的不同可用区? - How to use kubectl to check the containers/pods of an application are spread to different AZs in an AWS EKS cluster?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM