<p>I am currently working on a side project with Go. I'm trying to get the information about the pods running on the cluster.</p>
<p>I can reach the pods according to the namespace value, but in order to reach the working pods with the metadata.labels.applicationGroup value in the service.yaml file, I need to obtain this value first.</p>
<p>I added below a part of my service.yaml file.</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: metadata-name
  labels:
    service: service-name
    applicationGroup: beta --&gt; this field
spec:
  replicas: 1
  selector:
    matchLabels:
      service: service-name
  template:
    metadata:
      labels:
        service: service-name
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.8
        ports:
        - containerPort: 80
...
</code></pre>
<p>Right now, I can access information pods with &quot;default&quot; namespaces.</p>
<pre><code>func getPodsInfo() (string, error) {

  var kubeConfig *string

  if home := homedir.HomeDir(); home != &quot;&quot; {
    kubeConfig = flag.String(&quot;kubeConfig&quot;, filepath.Join(home, &quot;.kube&quot;, &quot;config&quot;), &quot;(optional) absolute path to the kubeConfig file&quot;)
  } else {
    kubeConfig = flag.String(&quot;kubeConfig&quot;, &quot;&quot;, &quot;absolute path to the kubeConfig file&quot;)
  }
  flag.Parse()

  config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, *kubeConfig)
  if err != nil {
    err = fmt.Errorf(&quot;error occured when build config from flags: %s&quot;, err.Error())
    return &quot;&quot;, err
  }

  clientSet, err := kubernetes.NewForConfig(config)
  if err != nil {
    err = fmt.Errorf(&quot;error occured when build client set from config: %s&quot;, err.Error())
    return &quot;&quot;, err
  }
  /*
    listOptions := meta.ListOptions{
      FieldSelector: &quot;metadata.labels.applicationGroup=alpha&quot;,
    }
  */
  pods, err := clientSet.CoreV1().Pods(&quot;default&quot;).List(context.TODO(), metav1.ListOptions{})
  if err != nil {
    err = fmt.Errorf(&quot;error occured when get pods info from k8s: %s&quot;, err.Error())
    return &quot;&quot;, err
  }

  podsInfo, err := json.Marshal(&amp;pods)
  if err != nil {
    err = fmt.Errorf(&quot;error occured when json marshal: %s&quot;, err.Error())
    return &quot;&quot;, err
  }

  return string(podsInfo), nil
}
</code></pre>
<p>I tried to FieldSelector, but FieldSelector has supported some fields.</p>
<pre><code>listOptions := meta.ListOptions{
    FieldSelector: &quot;metadata.labels.applicationGroup=alpha&quot;,
}
</code></pre>
<p>And I got the below error.</p>
<p><code>field label not supported: metadata.labels.applicationGroup</code></p>
<p>You can check this <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/" rel="nofollow noreferrer">link</a> for the supported fields.</p>
<p>To my question, how can I reach the metadata.labels.applicationGroup value with cilent_go, and which function should I use to reach pods working with this value?</p>

kubilay
<p>Just use LabelSelector instead of FieldSelector</p>
<pre><code>listOptions := meta.ListOptions{
    LabelSelector: &quot;applicationGroup=alpha&quot;,
}
</code></pre>
<p>UPD: If you want to use it for pods you should set applicationGroup on pod template</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: metadata-name
  labels:
    service: service-name
spec:
  replicas: 1
  selector:
    matchLabels:
      service: service-name
  template:
    metadata:
      labels:
        service: service-name
        applicationGroup: beta
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.8
        ports:
        - containerPort: 80
</code></pre>
