<p>This is my string in <code>values.yaml</code>:
<code>selectorLabels: { app.kubernetes.io/name: tinyurl }</code></p>
<p>Yaml file looks like below:</p>
<pre><code>name: test-dj-service
environment: prod
namespace: test-service
labels: { app.kubernetes.io/name: test-dj-service, environment: prod }
replicaCount: 1
selectorLabels: { app.kubernetes.io/name: tinyurl } &lt;---
</code></pre>

<p>I need to use <code>tinyurl</code> in the below code under values.</p>
<p>Note:- <code>tinyurl</code> is variable, it will keep changing with other names.</p>
<pre><code>
{‌{ - if .Values.affinity.podAntiAffinity.preferred == true }}
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                 matchExpressions:
                 - key: app.kubernetes.io/name
                   operator: In
                   values: {‌{ ---------- }} # need to pull the selectorLabels values here.
              topologyKey: &quot;kubernetes.io/hostname&quot;
{‌{- end }}
</code></pre>
<p>So how I can pull this variable into values.</p>

Gaurav Agnihotri
<p>In addition to @ShashankV's answer, you should also be able to construct your label selector using a <code>range</code> expression (in case you want to support arbitrary label selectors, with multiple labels that are read from your Values file):</p>
<pre><code>labelSelector:
  matchExpressions:
  {{- range $key, $value := .Values.selectorLabels }}
  - key: {{ $key | quote }}
    operator: In
    values: {‌{ $value | quote }}
  {{- end }}
</code></pre>
