Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pod Affinity #224

Closed
wants to merge 17 commits into from
3 changes: 3 additions & 0 deletions charts/microservice/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ appVersion: "0.1.2"
maintainers:
- name: ashwani-opstree
- name: tripathishikha1
- name: khushimalhoz


38 changes: 38 additions & 0 deletions charts/microservice/examples/affinity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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: false # Set to false to disable podAntiAffinity
topologySpreadConstraints:
enabled: false # Set to false to disable topologySpreadConstraints
volumes:
enabled: true
configMaps:
- name: index
mountPath: /usr/share/nginx/html
data:
index.html: |
Hello! Opstree

1 change: 0 additions & 1 deletion charts/microservice/examples/deploy-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ deployment:
data:
index.html: |
Hello! Opstree

26 changes: 21 additions & 5 deletions charts/microservice/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,25 @@ spec:
{{- end }}
{{- with .Values.deployment.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.deployment.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- if .Values.deployment.affinity.enabled }}
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: {{ include "microservice.fullname" . }}
topologyKey: topology.kubernetes.io/zone
{{- end }}
{{- if .Values.deployment.topologySpreadConstraints.enabled }}
topologySpreadConstraints:
- maxSkew: 1
topologyKey: "topology.kubernetes.io/zone"
whenUnsatisfiable: "DoNotSchedule"
labelSelector:
matchLabels:
app: {{ include "microservice.fullname" . }}
minDomains: 2
{{- end }}
{{- end }}

10 changes: 7 additions & 3 deletions charts/microservice/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,16 @@ deployment:

tolerations: []

affinity: {}
affinity:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this setting as default in the deployment helm template. If someone wants to override the default setting, he can use these parameters to override.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done the changes
To make the affinity and tolerations
in deployment.yaml
affinity:
{{- toYaml (merge .Values.deployment.affinity (default dict .Values.deployment.affinity)) | nindent 8 }}
tolerations:
{{- toYaml (merge .Values.deployment.tolerations (default dict .Values.deployment.tolerations)) | nindent 8 }}

affinity and tolerations settings have default values defined in values.yaml, and these settings can be overridden by user-specified values. The merge function combines the defaults with the user-provided values, ensuring that the user can override the default settings if needed.

enabled: true

topologySpreadConstraints:
enabled: true

hpa:
enabled: true
minReplicas: 1
maxReplicas: 1
minReplicas: 5
maxReplicas: 6
targetCPU: 80
targetMemory: 80

Expand Down
Loading