Customization Examples
The following are examples of using Kustomize to change the output of the Helm chart.
Setting the External Traffic Policy on RS Gateway Service
global.services.externalTrafficPolicy
property. This example
hypothesizes that the Helm property does not exist. The following patch sets the External Traffic Policy of RS Gateway
to Local
. (The default value is Cluster
.)
resources:
- chartoutput.yaml
patchesStrategicMerge:
- |-
apiVersion: v1
kind: Service
metadata:
name: rsgateway-ag1
spec:
externalTrafficPolicy: Local
The kustomization.yaml file defines the resources being patched (the output of the Helm chart) and the fields being updated.
This can be executed with the following command assuming the kustomize-via-kubectl.sh and kustomization.yaml files are in the current directory.
helm install ag1 matrixx/matrixx -n matrixx --post-renderer ./kustomize-via-binary.sh
Use a command similar to the following to verify the change without installing. Note
that you can no longer use the --show-only
option of the template command
as everything is now in one file. The --dry-run
option is used instead.
$ helm install ag1 matrixx/matrixx -n matrixx --dry-run --post-renderer ./kustomize-via-binary.sh | grep "externalTrafficPolicy" -A 12 -B 15
---
apiVersion: v1
kind: Service
metadata:
labels:
app: rsgateway
app.kubernetes.io/instance: ag1
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: rsgateway
app.kubernetes.io/part-of: MATRIXX
app.kubernetes.io/version: 5230-SNAPSHOT
helm.sh/chart: rsgateway-5230.0.81924
mtx-type: proxy
name: rsgateway-ag1
spec:
externalTrafficPolicy: Local
ports:
- name: http
port: 8080
protocol: TCP
targetPort: http
selector:
app: rsgateway
app.kubernetes.io/instance: ag1
app.kubernetes.io/name: rsgateway
sessionAffinity: ClientIP
type: ClusterIP
---
Setting the Node Port of the RS Gateway Service
With the MATRIXX Helm chart, it is possible to set the service port type to
NodePort
. For example:
$ helm template ag1 matrixx/matrixx -n matrixx --show-only charts/rsgateway/templates/service.yaml --set rsgateway.service.type=NodePort
---
# Source: matrixx/charts/rsgateway/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: rsgateway
app.kubernetes.io/instance: ag1
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: rsgateway
app.kubernetes.io/part-of: MATRIXX
app.kubernetes.io/version: 5230-SNAPSHOT
helm.sh/chart: rsgateway-5230.0.81924
mtx-type: proxy
name: rsgateway-ag1
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: http
selector:
app: rsgateway
app.kubernetes.io/instance: ag1
app.kubernetes.io/name: rsgateway
sessionAffinity: ClientIP
type: NodePort
By default, Kubernetes assigns the NodePort
to use, but this can be
user-specified if needed. The Helm chart does not give an option to do this, but you can
make this change with Kustomize. The following patch assigns port 12345 as the
NodePort
.
resources:
- chartoutput.yaml
patchesStrategicMerge:
- |-
apiVersion: v1
kind: Service
metadata:
name: rsgateway-ag1
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: http
nodePort: 12345
The kustomization.yaml defines the resources being patched (the
output of the Helm chart) and the updated fields. In the ports
list of the
service, include a new nodePort
attribute. Note that all fields in the port
list entry are repeated, as lists are replaced and not merged.
This can be executed with the following command assuming the kustomize-via-kubectl.sh and kustomization.yaml files are in the current working directory.
helm install ag1 matrixx/matrixx -n matrixx --set rsgateway.service.type=NodePort --post-renderer ./kustomize-via-kubectl.sh
The following command can be used to verify the change without installing. Note that
you can no longer use the --show-only
option of the template command as
everything is now in one file. The --dry-run
option is used instead.
$ helm install ag1 matrixx/matrixx -n matrixx --set rsgateway.service.type=NodePort --dry-run --post-renderer ./kustomize-via-binary.sh | grep "nodePort: 12345" -B 16 -A 10
apiVersion: v1
kind: Service
metadata:
labels:
app: rsgateway
app.kubernetes.io/instance: ag1
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: rsgateway
app.kubernetes.io/part-of: MATRIXX
app.kubernetes.io/version: 5230-SNAPSHOT
helm.sh/chart: rsgateway-5230.0.81924
mtx-type: proxy
name: rsgateway-ag1
spec:
ports:
- name: http
nodePort: 12345
port: 8080
protocol: TCP
targetPort: http
selector:
app: rsgateway
app.kubernetes.io/instance: ag1
app.kubernetes.io/name: rsgateway
sessionAffinity: ClientIP
type: NodePort
---