Skip to content

Commit

Permalink
Pod Affinity with hosts and zone changes
Browse files Browse the repository at this point in the history
  • Loading branch information
khushimalhoz committed Aug 5, 2024
1 parent 59ca5de commit 2709d63
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
53 changes: 53 additions & 0 deletions charts/microservice/examples/affinity_hosts.values.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 14 additions & 5 deletions charts/microservice/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}
Expand Down
9 changes: 4 additions & 5 deletions charts/microservice/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2709d63

Please sign in to comment.