Skip to content

Commit

Permalink
Added pod affinity if the default ReadWriteOnce is used.
Browse files Browse the repository at this point in the history
If `accessMode` `ReadWriteOnce` is used, then the volume
can only be accessed in a write mode from a single node.
This means that all pods which require write access to
the volume need to be co-located to the same node.
Failing that typically leads to a difficult to untangle
locked volume mount situation where containers are stuck
in `ContainerCreating`.

This change adds the necessary pod affinities if the related
access modes are set in the `values.yaml`.
  • Loading branch information
keskival committed Dec 10, 2022
1 parent ae892d5 commit e51d535
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions templates/deployment-sidekiq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,21 @@ spec:
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with (default (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity) .affinity) }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or (eq "ReadWriteOnce" $context.Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" $context.Values.mastodon.persistence.system.accessMode) }}
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/part-of
operator: In
values:
- rails
topologyKey: kubernetes.io/hostname
{{- end }}
{{- with (default (default $context.Values.affinity $context.Values.mastodon.sidekiq.affinity) .affinity) }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if (not $context.Values.mastodon.s3.enabled) }}
volumes:
- name: assets
Expand Down
17 changes: 14 additions & 3 deletions templates/deployment-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,21 @@ spec:
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with (default .Values.affinity .Values.mastodon.web.affinity) }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or (eq "ReadWriteOnce" .Values.mastodon.persistence.assets.accessMode) (eq "ReadWriteOnce" .Values.mastodon.persistence.system.accessMode) }}
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/part-of
operator: In
values:
- rails
topologyKey: kubernetes.io/hostname
{{- end }}
{{- with (default .Values.affinity .Values.mastodon.web.affinity) }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
Expand Down

0 comments on commit e51d535

Please sign in to comment.