Answers: <p>They do two completely different and distinct things.</p>
  <p>&quot;Replacements&quot; are used to &quot;copy fields from one source into any number of specified targets&quot;. You can't do that with a patch (a patch cannot copy data from an existing resource).</p>
  <p>A patch is used to apply arbitrary transformations to a YAML document. You can use patches to do things like add, replace, or delete attributes in your resources. You can merge new entries into a list. You can't do that with replacements.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-06-26T00:04:18.560Z
Answers: 2024-06-26T00:04:18.560Z
Answers: larsks
Body: <p>Kustomize supports two ways to modify live kubernetes manifests:</p>
  <ul>
  <li><strong>patches</strong>: <a href="https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patches/" rel="nofollow noreferrer">upstream docs</a></li>
  </ul>
  <blockquote>
  <p>Patches (also called overlays) add or override fields on resources. They are provided using the patches Kustomization field.</p>
  </blockquote>
  <ul>
  <li><strong>replacements</strong>: <a href="https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/replacements/" rel="nofollow noreferrer">upstream docs</a></li>
  </ul>
  <blockquote>
  <p>Replacements are used to copy fields from one source into any number of specified targets.</p>
  </blockquote>
  <p>They seemingly serve the same purpose.</p>
  <p>What are the differences between them? In which situations one is recommended over the other?</p>
  
Tags: <kubernetes><kustomize>
Title: kubernetes kustomize: replacements vs patches
UserDisplayName: thiagowfx
ThreadText: # kubernetes kustomize: replacements vs patches
  
  (Asked by: username_0 on 2024-06-25)
  
  Kustomize supports two ways to modify live kubernetes manifests:
  
  * **patches**: [upstream docs](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patches/)
  
  > Patches (also called overlays) add or override fields on resources. They are provided using the patches Kustomization field.
  
  * **replacements**: [upstream docs](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/replacements/)
  
  > Replacements are used to copy fields from one source into any number of specified targets.
  
  They seemingly serve the same purpose.
  
  What are the differences between them? In which situations one is recommended over the other?
  
  **Tags:** kubernetes, kustomize
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-06-26. Score: 3 | Accepted answer
  
  They do two completely different and distinct things.
  
  "Replacements" are used to "copy fields from one source into any number of specified targets". You can't do that with a patch (a patch cannot copy data from an existing resource).
  
  A patch is used to apply arbitrary transformations to a YAML document. You can use patches to do things like add, replace, or delete attributes in your resources. You can merge new entries into a list. You can't do that with replacements.
  
  
  ---
  
  