Patches List
Patches List
- Example
api-depl.yamlfile:apiVersion: apps/v1 kind: Deployment metadata: name: api-deployment spec: replicas: 1 selector: matchLabels: component: api template: metadata: labels: component: api spec: containers: - name: nginx image: nginx -
The
containerssection above expects a list, that’s why you see the-beforename: nginx -
This is using a Replace List with Json6902
kustomization.yaml: ``` patches:- target:
kind: Deployment
name: api-deployment
patch: |-
- op: replace path: /spec/template/spec/containers/0 value: name: haproxy image: haproxy ```
- target:
kind: Deployment
name: api-deployment
patch: |-
-
The
pathto a container -
This is the first container, therefore it will have an index of
0. -
Changes the
containersnameandimagetohaproxy. - How to replace a list using the Strategic Merge Path
kustomization.yaml
patches:
- label-patch.yaml
- The
label-patch.yamlfile looks like this:apiVersion: apps/v1 kind: Deployment metadata: name: api-deployment spec: template: spec: containers: - name: nginx image: haproxy -
How to add an item to a list using a Json6902 patch.
-
We have the same deployment configuration, this will be the
nginxcontainer. - We want to add a second container to this list:
```
containers:
- name: nginx image: ngin ```
- This is the
kustomization.yamlfile: ``` patches:- target:
kind: Deployment
name: api-deployment
patch: |-
- op: add path: /spec/template/spec/containers/- value: name: haproxy image: haproxy ```
- target:
kind: Deployment
name: api-deployment
patch: |-
-
The operation is set to
add. -
At the end of the
path, we have a-. The dash means to add it at the end of the list. If we wanted to add the containers to the front of the list, this would be a zero. - The final configuration would look like this:
containers:
- name: nginx
image: ngin
-
Adding an item to a list using a Strategic Merge Patch:
kustomization.yaml: ``` patches:- label-patch.yaml ```
- The
label-patch.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-deployment
spec:
template:
spec:
containers:
- name: haproxy
image: haproxy
-
How to delete an item from a list using a Json6902 patch.
- We have two containers and the one with the name of
databaseneeds to be deleted: ``` containers:- name: web image: nginx
- name: database image: mongo ```
kustomization.yamlfile: ``` patches:- target:
kind: Deployment
name: api-deployment
patch: |-
- op: remove path: /spec/template/spec/containers/1 ```
- target:
kind: Deployment
name: api-deployment
patch: |-
-
We want to remove the second one, so therefore we use an index of
1. -
How to delete an item using a Strategic Merge Patch:
kustomization.yaml:
patches:
- label-patch.yaml
label-patch.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-deployment
spec:
template:
spec:
containers:
- $patch: delete
name: database
- The
$patchdirective is the delete directive which specifies the container to delete