<p>Is there any option to reference service's property from another entity, Like Config Map or Deployment? To be more specific I want to put service's name in ConfigMap, not by myself, but rather to link it programmatically.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1 
kind: ConfigMap 
metadata:
  name: config-map 
  namespace: ConfigMap-Namespace 

Data:
  ServiceName: &lt;referenced-service-name&gt; 

--- 

apiVersion: v1 
kind: Service 
metadata:
 name: service-name           /// that name I want to put in ConfigMap.
 namespace: ConfigMap-Namespace 
spec:
   .... 

</code></pre>
<p>Thanks...</p>

CraZyCoDer
<p>Using plain <code>kubectl</code>, there is no way to dynamically fill in content like this.  There are very limited exceptions around injecting values into environment variables in Pods (and PodSpecs inside other objects) but a ConfigMap must contain fixed content.</p>
<p>In this example, the Service object name is fixed, and I'd just embed the same fixed string into the ConfigMap.</p>
<p>If you were using a templating engine like <a href="https://helm.sh" rel="nofollow noreferrer">Helm</a> then you could call the same template code to render the Service name in both places.  For example:</p>
<pre class="lang-yaml prettyprint-override"><code>{{- define &quot;service.name&quot; -}}
{{ .Release.Name }}-service
{{- end -}}
---
apiVersion: v1
kind: Service
metadata: 
  name: {{ include &quot;service.name&quot; . }}
...
---
apiVersion: v1
kind: ConfigMap
metadata: { ... }
data:
  serviceName: {{ include &quot;service.name&quot; . }}
</code></pre>
