diff --git a/charts/microservice/examples/affinity.yaml b/charts/microservice/examples/affinity_az.values.yaml similarity index 65% rename from charts/microservice/examples/affinity.yaml rename to charts/microservice/examples/affinity_az.values.yaml index 5c71eaea..259ac98a 100644 --- a/charts/microservice/examples/affinity.yaml +++ b/charts/microservice/examples/affinity_az.values.yaml @@ -24,9 +24,23 @@ deployment: memory: 500Mi cpu: 500m affinity: - enabled: false # Set to false to disable podAntiAffinity + enabled: true # Set to false to disable podAntiAffinity + preferred: + enabled: false + required: + enabled: true + + hpa: + enabled: true + minReplicas: 1 + maxReplicas: 2 + targetCPU: 80 + targetMemory: 80 + topologySpreadConstraints: - enabled: false # Set to false to disable topologySpreadConstraints + enabled: true + whenUnsatisfiable: "DoNotSchedule" # Options: "DoNotSchedule", "ScheduleAnyway" + volumes: enabled: true configMaps: diff --git a/charts/microservice/examples/affinity_hosts.values.yaml b/charts/microservice/examples/affinity_hosts.values.yaml new file mode 100644 index 00000000..436ed086 --- /dev/null +++ b/charts/microservice/examples/affinity_hosts.values.yaml @@ -0,0 +1,53 @@ +global: + namespace: "default" + # replicacount: 5 + fullnameOverride: "webapp" + +deployment: + image: + name: nginx + tag: latest + pullPolicy: IfNotPresent + livenessProbe: + httpGet: + path: "/" + port: http + readinessProbe: + httpGet: + path: "/" + port: http + resources: + requests: + memory: 100Mi + cpu: 100m + limits: + memory: 500Mi + cpu: 500m + affinity: + enabled: true # Set to false to disable podAntiAffinity + preferred: + enabled: false + required: + enabled: true + topologyKey: "topology.kubernetes.io/hostname" + + hpa: + enabled: true + minReplicas: 1 + maxReplicas: 2 + targetCPU: 80 + targetMemory: 80 + + topologySpreadConstraints: + enabled: true + whenUnsatisfiable: "DoNotSchedule" # Options: "DoNotSchedule", "ScheduleAnyway" + topologyKey: "topology.kubernetes.io/hostname" + + volumes: + enabled: true + configMaps: + - name: index + mountPath: /usr/share/nginx/html + data: + index.html: | + Hello! Opstree diff --git a/charts/microservice/templates/deployment.yaml b/charts/microservice/templates/deployment.yaml index 021dcf38..542fdc13 100644 --- a/charts/microservice/templates/deployment.yaml +++ b/charts/microservice/templates/deployment.yaml @@ -100,23 +100,32 @@ spec: nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.deployment.affinity }} + {{- if .Values.deployment.affinity.enabled }} affinity: - {{- if .Values.deployment.affinity.enabled }} + {{- if or .Values.deployment.affinity.preferred.enabled .Values.deployment.affinity.required.enabled }} podAntiAffinity: + {{- if .Values.deployment.affinity.preferred.enabled }} preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 podAffinityTerm: labelSelector: matchLabels: app: {{ include "microservice.fullname" . }} - topologyKey: topology.kubernetes.io/zone + topologyKey: {{ .Values.deployment.affinity.topologyKey }} + {{- end }} + {{- if .Values.deployment.affinity.required.enabled }} + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchLabels: + app: {{ include "microservice.fullname" . }}-app + topologyKey: {{ .Values.deployment.affinity.topologyKey }} + {{- end }} {{- end }} {{- if .Values.deployment.topologySpreadConstraints.enabled }} topologySpreadConstraints: - maxSkew: 1 - topologyKey: "topology.kubernetes.io/zone" - whenUnsatisfiable: "DoNotSchedule" + topologyKey: {{ .Values.deployment.topologySpreadConstraints.topologyKey }} + whenUnsatisfiable: "{{ .Values.deployment.topologySpreadConstraints.whenUnsatisfiable }}" labelSelector: matchLabels: app: {{ include "microservice.fullname" . }} diff --git a/charts/microservice/values.yaml b/charts/microservice/values.yaml index e552c4a3..e14da40b 100644 --- a/charts/microservice/values.yaml +++ b/charts/microservice/values.yaml @@ -122,14 +122,13 @@ deployment: affinity: enabled: true - - topologySpreadConstraints: - enabled: true + preferred: + enabled: true hpa: enabled: true - minReplicas: 5 - maxReplicas: 6 + minReplicas: 2 + maxReplicas: 3 targetCPU: 80 targetMemory: 80