I have a kubernetes deployment script as a template for project deployment. But I have different project for this script and each project need a new namespace and annotation and environment variable.
Now I create properties file for each project and write a shell script that when I deploy the project, the properties of this project will replace the variable in the template and then deploy this deployment scriplt. As below
minReplicas: ${HYBRIS_MIN_REPLICA}
maxReplicas: ${HYBRIS_MAX_REPLICA}
hybris.scaler.replica.max=3
hybris.scaler.replica.min=2
Do we have any good ways to implement such things for custom the kubernetes script as a template
You can use Helm it is a package manger for kubernetes which give you the ability to have templates for your deployment or whatever scripts or config for kubernetes. and you can have different values for some variables in your deployment script. you can read about Values file and control flows which written in a _helper scripts with the following format:
{{ if PIPELINE }}
# Do something
{{ else if OTHER PIPELINE }}
# Do something else
{{ else }}
# Default case
{{ end }}
Values.yaml
hybris:
scaler:
replica:
max: 3
min: 2
delpoyment.yaml
apiVersion: apps/v1
kind: Deployment
metadata: name
labels: test
spec:
replicas: {{ .Values.hybris.scaler.replica.min }}
This will help if you read about it.