Providing Feedback

Provide feedback at the survey

TL;DR
  • Customize arbitrary fields from arbitrary Resources in a Base.

Customizing Resource Fields

Motivation

It is often necessary for users to want to modify arbitrary fields from a Base, such as resource reservations for Pods, replicas on Deployments, etc. Overlays and patches can be used by Variants to specify fields values which will override the Base field values.

Customizing Arbitrary Fields with Overlays

Arbitrary fields may be added, changed, or deleted by supplying Overlays against the Resources provided by the Base. Overlays are sparse Resource definitions that allow arbitrary customizations to be performed without requiring a base to expose the customization as a template.

Overlays require the Group, Version, Kind and Name of the Resource to be specified, as well as any fields that should be set on the base Resource. Overlays are applied using StrategicMergePatch.

Use Case: Different Environments (test, dev, staging, canary, prod) require fields such as replicas or resources to be overridden.

Input: The kustomization.yaml file and overlay

# kustomization.yaml
bases:
- ../base
patchesStrategicMerge:
- overlay.yaml
# overlay.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  # override replicas
  replicas: 3
  template:
    spec:
      containers:
      - name: nginx
        # override resources
        resources:
          limits:
            cpu: "1"
          requests:
            cpu: "0.5"

Base:

# ../base/kustomization.yaml
resources:
- deployment.yaml
# ../base/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources:
          limits:
            cpu: "0.2"
          requests:
            cpu: "0.1"

Applied: The Resource that is Applied to the cluster

# Overlayed Base Resource
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  # replicas field has been added
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        # resources have been overridden
        resources:
          limits:
            cpu: "1"
          requests:
            cpu: "0.5"

Merge Semantics for Overlays

Overlays use the same merge semantics as Applying Resource Config to cluster. One difference is that there is no Last Applied Resource Config when merging overlays, so fields may only be deleted if they are explicitly set to nil.

Customizing Arbitrary Fields with JsonPatch

Arbitrary fields may be added, changed, or deleted by supplying JSON Patches against the Resources provided by the base.

Use Case: Different Environments (test, dev, staging, canary, prod) require fields such as replicas or resources to be overridden.

JSON Patches are RFC 6902 patches that are applied to resources. Patches require the Group, Version, Kind and Name of the Resource to be specified in addition to the Patch. Patches offer a number of powerful imperative operations for modifying the base Resources.

Input: The kustomization.yaml file

# kustomization.yaml
bases:
- ../base
patchesJson6902:
- target:
    group: apps
    version: v1
    kind: Deployment
    name: nginx-deployment
  path: patch.yaml
# patch.yaml
- op: add
  path: /spec/replicas
  value: 3
# ../base/kustomization.yaml
resources:
- deployment.yaml
# ../base/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx

Applied: The Resource that is Applied to the cluster

# Patched Base Resource
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  # replicas field has been added
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx

results matching ""

    No results matching ""