cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Filters and Kubernetes Annotations visibility

PaulE
Observer

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 ? 

2 REPLIES 2

Iplinsky
Advisor

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.

Dynatrace Certified

Sorry, to clarify, I'm trying to filter in Data Explorer 

Featured Posts