17 Jul 2023 08:45 PM
Trying to set up a filter using an annotation value for worker nodes in a K8S cluster .. the node currently has
$ kubectl get node ag1-sres-workload-01-md-0-85585fc84d-4q6h4 -o yaml
apiVersion: v1
kind: Node
metadata:
annotations:
cluster.x-k8s.io/cluster-name: xxx-xxx-xxx
cluster.x-k8s.io/cluster-namespace: default
cluster.x-k8s.io/machine: xxx-xxx-xxx-md-0-85585fc84d-4q6h4
cluster.x-k8s.io/owner-kind: MachineSet
cluster.x-k8s.io/owner-name: xxx-xxx-xxx-md-0-85585fc84d
csi.volume.kubernetes.io/nodeid: '{"csi.vsphere.vmware.com":"xxx-xxx-xxx-md-0-85585fc84d-4q6h4"}'
kubeadm.alpha.kubernetes.io/cri-socket: /var/run/containerd/containerd.sock
node.alpha.kubernetes.io/ttl: "0"
volumes.kubernetes.io/controller-managed-attach-detach: "true"
creationTimestamp: "2023-07-13T08:37:59Z"
labels:
beta.kubernetes.io/arch: amd64
beta.kubernetes.io/instance-type: xxxx.xxx.xxx.xxxx
beta.kubernetes.io/os: linux
kubernetes.io/arch: amd64
kubernetes.io/hostname: xxx-xxx-xxx-md-0-85585fc84d-4q6h4
kubernetes.io/os: linux
node.kubernetes.io/instance-type: vsphere-vm.cpu-16.mem-64gb.os-photon
name: ag1-sres-workload-01-md-0-85585fc84d-4q6h4
resourceVersion: "51487447"
uid: d6528bff-d96f-439e-8384-42a826066119
When I am in Data Explorer and get to Kubernetes nodes:Kubernetes labels I only see the labels and not the annotations. I'd like to be able to filter on the annotation cluster.x-k8s.io/owner-kind: MachineSet which I thought would appear as a label. How do I filter on the annotation ?
17 Jul 2023 10:15 PM
You can use kubectl with the -o jsonpath option to filter resources based on annotations. For example, to get all nodes with the annotation cluster.x-k8s.io/owner-kind: MachineSet, you can use the following command:
kubectl get nodes -o jsonpath='{.items[?(@.metadata.annotations.cluster\.x-k8s\.io/owner-kind=="MachineSet")].metadata.name}'
This command uses a jsonpath expression to filter the nodes based on the value of the cluster.x-k8s.io/owner-kind annotation.
17 Jul 2023 11:00 PM
Sorry, to clarify, I'm trying to filter in Data Explorer
30 May 2025 11:54 AM
Hey @PaulE , did you manage to find the solution to your problem? If so, it would be amazing if you've shared it with the rest of the Community! If not, let me know, and I'll look for some further assistance 😊