I want to check the Kubernetes configuration - how many nodes, etc. I tried the following command.
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. But it returns <none>
for all the pods' nodes.
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?
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.kubernetes.io/zone
is merged with the name of the pods scheduled on that particular node.
NOTE: I have used lowercase k
in the label key topology\.kubernetes\.io/zone
; however, in your case, it's uppercase K
in the question. 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.