<p>Currently we are using ${HOME}/bin/kustomize edit set nameprefix prefix1</p>
<p>But it is adding nameprefix to all of our resources like deployment.yaml and service.yaml.</p>
<p>We want to apply nameprefix to deployment.yaml only and not apply it to service.yaml</p>

<p>Posting for better visibility:</p>
<p><strong>If you are using</strong>:</p>
<pre><code>kustomize edit set nameprefix prefix1
</code></pre>
<p>This command will set <em><strong>namePrefix</strong></em>  inside your current <strong>kustomization</strong>.
As stated in the question - this is the way how it works,  <em><strong>namePrefix</strong></em> will be used for all specified resources inside <strong>kustomization.yaml</strong>.</p>
<p>Please consider the following scenario using the idea of an <strong>overlay</strong> and <strong>base</strong> with kustomization.</p>
<pre><code>Tested with:
kustomize/v4.0.1
</code></pre>
<p>Base declare resources and settings shared in common and overlay declare additional differences.</p>
<pre><code>.
├── base
│   ├── [deployment.yaml]  Deployment nginx
│   ├── [kustomization.yaml]  Kustomization 
│   └── [service.yaml]  Service nginx
└── prod
    ├── [kustomization.yaml]  Kustomization 
    └── kustomizeconfig
        └── [deploy-prefix-transformer.yaml]  PrefixSuffixTransformer customPrefixer
</code></pre>
<ul>
<li><strong>base</strong>: common files</li>
</ul>
<pre><code>#deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      run: nginx

#service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    run: nginx

#kustomization.yaml
resources:
- deployment.yaml
- service.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
</code></pre>
<ul>
<li><strong>overlay/prod</strong>: kustomization.yaml</li>
</ul>
<pre><code>
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ../../base
nameSuffix: -Suffix1
transformers:
- ./kustomizeconfig/deploy-prefix-transformer.yaml

</code></pre>
<ul>
<li><strong>overlay/prod/kustomizeconfig</strong>: deploy-prefix-transformer.yaml</li>
</ul>
<pre><code>apiVersion: builtin
kind: PrefixSuffixTransformer
metadata:
  name: customPrefixer
prefix: &quot;deploymentprefix-&quot;
fieldSpecs:
- kind: Deployment
  path: metadata/name
</code></pre>
<p>As you can see, using this structure and builtin plugin <strong>PrefixSuffixTransformer</strong> you can get the desired effect:</p>
<pre><code>kustomize build overlay/prod/
</code></pre>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    run: nginx
  name: nginx-Suffix1
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploymentprefix-nginx-Suffix1
spec:
  selector:
    matchLabels:
      run: nginx
</code></pre>
<p>This configuration (overlay/prod/kustomization.yaml) will apply <strong>nameSuffix: -Suffix1</strong> to all resources specified in <strong>base</strong> directory and using  <a href="https://kubectl.docs.kubernetes.io/guides/extending_kustomize/builtins/#example-8" rel="noreferrer"><strong>PrefixSuffixTransformer</strong></a> will add in this specific example <strong>prefix: &quot;deploymentprefix-&quot;</strong> to <strong>deployment.metadata.name</strong></p>
<pre><code>apiVersion: builtin
kind: PrefixSuffixTransformer
metadata:
  name: customPrefixer
prefix: &quot;deploymentprefix-&quot;
fieldSpecs:
- kind: Deployment
  path: metadata/name

 /kustomizeconfig/deploy-prefix-transformer.yaml

</code></pre>
