solomem / DevOps

0 stars 0 forks source link

Kubernetes Basics #16

Open solomem opened 1 year ago

solomem commented 1 year ago

kustomization

Examples:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

commonLabels:
  app: myapp
  environment: production

resources:
- deployment.yaml
- service.yaml

configurations:
- overlays/production.yaml

---
apiVersion: kustomize.config.k8s.io/v1beta2
kind: Kustomization

resources:
- deployment.yaml
- service.yaml

patches:
- patches/production-patch.yaml

Explaination:

Both versions of the kustomization.yaml are using the same deployment.yaml and service.yaml resources but applying different patch files.

In the v1beta1 version of the kustomization.yaml, the configurations field is used to specify an overlay configuration file called overlays/production.yaml. This indicates that additional customizations or overlays defined in overlays/production.yaml will be applied to the base resources (deployment.yaml and service.yaml).

On the other hand, in the v1beta2 version of the kustomization.yaml, the patches field is used to specify a patch file called patches/production-patch.yaml. This indicates that the patch file patches/production-patch.yaml will be applied to the base resources.

So, while both versions of the kustomization.yaml use the same base resources (deployment.yaml and service.yaml), they apply different customizations by leveraging different mechanisms: overlays in v1beta1 and patches in v1beta2.

This allows you to apply different modifications to the same base resources, depending on the version of the kustomization.yaml you use.


Overlays vs Patches in Kustomization:

The main difference between overlays and patches in the context of Kustomize is how they are used to customize and modify Kubernetes resources.

Overlays:

Overlays provide a way to modify and extend existing resources using a separate overlay configuration file. Overlays are typically used in older versions of Kustomize (e.g., v1beta1). An overlay configuration file describes changes to be applied to the base resources, such as adding or overriding fields, changing labels or annotations, and modifying resource specifications. Overlays allow you to define multiple variations or configurations of your resources by applying different overlays to the same base resources.

Patches:

Patches are used to make specific changes to resources using patch files. Patches can be used in newer versions of Kustomize (e.g., v1beta2 and onwards). Patch files describe the specific modifications to be applied to the base resources, such as adding, modifying, or deleting specific fields, annotations, or labels. Patches are often used when you need more fine-grained control over the modifications applied to the base resources, targeting specific fields or sections within the resources. Both overlays and patches allow you to customize your Kubernetes resources, but they differ in their approach and syntax.

It's important to note that Kustomize has evolved over time, and the specific features and capabilities of overlays and patches may vary depending on the Kustomize version you are using. Newer versions may introduce additional features or improvements in how overlays and patches are used.