Skip to content

Commit

Permalink
[stable/coredns] Chart updates (helm#23284)
Browse files Browse the repository at this point in the history
* [stable/coredns] Add ability to customize, preStopHook, podAnnotations, rolllingUpdate specs, terminationGracePeriodSeconds to coredns. Add optional HPA definition as a alternative to proportional autoscaler.

Signed-off-by: Adam Hamsik <[email protected]>

* Fix helm lint run

Signed-off-by: Adam Hamsik <[email protected]>

* Update documentation, add custom labels to HPA.

Signed-off-by: Adam Hamsik <[email protected]>

* Fix rollingupdate variable name.

Signed-off-by: Adam Hamsik <[email protected]>

Co-authored-by: Martin Dojcak <[email protected]>
  • Loading branch information
haad and dojci authored Jul 28, 2020
1 parent 99447d7 commit 9fcfb8b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 7 deletions.
2 changes: 1 addition & 1 deletion stable/coredns/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: coredns
version: 1.13.1
version: 1.13.2
appVersion: 1.7.0
description: CoreDNS is a DNS server that chains plugins and provides Kubernetes DNS Services
keywords:
Expand Down
13 changes: 13 additions & 0 deletions stable/coredns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ The command removes all the Kubernetes components associated with the chart and
| `extraVolumeMounts` | Optional array of volumes to mount inside the CoreDNS container | [] |
| `extraSecrets` | Optional array of secrets to mount inside the CoreDNS container | [] |
| `customLabels` | Optional labels for Deployment(s), Pod, Service, ServiceMonitor objects | {} |
| `rollingUpdate.maxUnavailable` | Maximum number of unavailable replicas during rolling update | `1` |
| `rollingUpdate.maxSurge` | Maximum number of pods created above desired number of pods | `25%` |
| `podDisruptionBudget` | Optional PodDisruptionBudget | {} |
| `podAnnotations` | Optional Pod only Annotations | {} |
| `terminationGracePeriodSeconds` | Optional duration in seconds the pod needs to terminate gracefully. | 30 |
| `preStopSleep` | Definition of Kubernetes preStop hook executed before Pod termination | {} |
| `hpa.enabled` | Enable Hpa autoscaler instead of proportional one | `false` |
| `hpa.minReplicas` | Hpa minimum number of CoreDNS replicas | `1` |
| `hpa.maxReplicas` | Hpa maximum number of CoreDNS replicas | `2` |
| `hpa.metrics` | Metrics definitions used by Hpa to scale up and down | {} |
| `autoscaler.enabled` | Optionally enabled a cluster-proportional-autoscaler for CoreDNS | `false` |
| `autoscaler.coresPerReplica` | Number of cores in the cluster per CoreDNS replica | `256` |
| `autoscaler.nodesPerReplica` | Number of nodes in the cluster per CoreDNS replica | `16` |
Expand Down Expand Up @@ -144,3 +153,7 @@ This also creates a ServiceAccount, ClusterRole, and ClusterRoleBinding for
the autoscaler deployment.

`replicaCount` is ignored if this is enabled.

By setting `hpa.enabled = true` a [Horizontal Pod Autoscaler](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/)
is enabled for Coredns deployment. This can scale number of replicas based on meitrics
like CpuUtilization, MemoryUtilization or Custom ones.
2 changes: 1 addition & 1 deletion stable/coredns/templates/deployment-autoscaler.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.autoscaler.enabled }}
{{- if and (.Values.autoscaler.enabled) (not .Values.hpa.enabled) }}
---
apiVersion: apps/v1
kind: Deployment
Expand Down
22 changes: 17 additions & 5 deletions stable/coredns/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 10%
maxUnavailable: {{ .Values.rollingUpdate.maxUnavailable }}
maxSurge: {{ .Values.rollingUpdate.maxSurge }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name | quote }}
Expand All @@ -39,16 +39,22 @@ spec:
{{- end }}
app.kubernetes.io/name: {{ template "coredns.name" . }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
{{- if .Values.customLabels }}
{{ toYaml .Values.customLabels | indent 8 }}
{{- end }}
{{- if .Values.customLabels }}
{{ toYaml .Values.customLabels }}
{{- end }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- if .Values.isClusterService }}
scheduler.alpha.kubernetes.io/critical-pod: ''
scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
{{- end }}
{{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations }}
{{- end }}
spec:
{{- if .Values.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- end }}
serviceAccountName: {{ template "coredns.serviceAccountName" . }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName | quote }}
Expand Down Expand Up @@ -106,6 +112,12 @@ spec:
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
{{- if .Values.preStopSleep }}
lifecycle:
preStop:
exec:
command: ["/usr/bin/sleep", "{{ .Values.preStopSleep }}"]
{{- end }}
volumes:
- name: config-volume
configMap:
Expand Down
29 changes: 29 additions & 0 deletions stable/coredns/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if and (.Values.hpa.enabled) (not .Values.autoscaler.enabled) }}
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ template "coredns.fullname" . }}
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- if .Values.isClusterService }}
k8s-app: {{ .Chart.Name | quote }}
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "CoreDNS"
{{- end }}
app.kubernetes.io/name: {{ template "coredns.name" . }}
{{- if .Values.customLabels }}
{{ toYaml .Values.customLabels | indent 4 }}
{{- end }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "coredns.fullname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
metrics:
{{ toYaml .Values.hpa.metrics | indent 4 }}
{{- end }}
36 changes: 36 additions & 0 deletions stable/coredns/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ resources:
cpu: 100m
memory: 128Mi

## Create HorizontalPodAutoscaler object.
##
# autoscaling:
# minReplicas: 1
# maxReplicas: 10
# metrics:
# - type: Resource
# resource:
# name: cpu
# targetAverageUtilization: 60
# - type: Resource
# resource:
# name: memory
# targetAverageUtilization: 60

rollingUpdate:
maxUnavailable: 1
maxSurge: 25%

# Under heavy load it takes more that standard time to remove Pod endpoint from a cluster.
# This will delay termination of our pod by `preStopSleep`. To make sure kube-proxy has
# enough time to catch up.
# preStopSleep: 5
terminationGracePeriodSeconds: 30

podAnnotations: {}
# cluster-autoscaler.kubernetes.io/safe-to-evict: "false"

serviceType: "ClusterIP"

prometheus:
Expand Down Expand Up @@ -165,6 +193,14 @@ extraSecrets: []
# Custom labels to apply to Deployment, Pod, Service, ServiceMonitor. Including autoscaler if enabled.
customLabels: {}

## Alternative configuration for HPA deployment if wanted
#
hpa:
enabled: false
minReplicas: 1
maxReplicas: 2
metrics: {}

## Configue a cluster-proportional-autoscaler for coredns
# See https://github.com/kubernetes-incubator/cluster-proportional-autoscaler
autoscaler:
Expand Down

0 comments on commit 9fcfb8b

Please sign in to comment.