Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Application

Generic Helm chart for deploying stateless applications on Kubernetes. Supports Deployments, Jobs, and CronJobs along with common companion resources (Services, Ingress, RBAC, autoscaling, monitoring, certificates, and more).
Generic Helm chart for deploying applications on Kubernetes. Supports Deployments, StatefulSets, DaemonSets, Jobs, and CronJobs along with common companion resources (Services, Ingress, RBAC, autoscaling, monitoring, certificates, and more).

## Installing the Chart

Expand Down Expand Up @@ -82,11 +82,14 @@ Please refer to the [Contributing Guide](CONTRIBUTING.md) for details on how to
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| deployment.enabled | bool | `true` | Enable Deployment. |
| deployment.kind | string | `"Deployment"` | Define the kind of workload. Must specify either one of the following field when enabled: Deployment, StatefulSet, DaemonSet |
| deployment.additionalLabels | object, null | `nil` | Additional labels for Deployment. |
| deployment.podLabels | object, null | `nil` | Additional pod labels which are used in Service's Label Selector. |
| deployment.annotations | object, null | `nil` | Annotations for Deployment. |
| deployment.additionalPodAnnotations | object, null | `nil` | Additional pod annotations. |
| deployment.strategy.type | string | `"RollingUpdate"` | Type of deployment strategy. |
| deployment.strategy.type | string | `"RollingUpdate"` | Type of deployment strategy. Only for Deployments. |
| deployment.updateStrategy.type | string | `"RollingUpdate"` | Type of deployment.updateStrategy. Only works for StatefulSets and DaemonSets |
| deployment.podManagementPolicy | string | `"OrderedReady"` | Type of deployment.podManagementPolicy. Only works for StatefulSets. One of OrderedReady or Parallel |
| deployment.reloadOnChange | bool | `true` | Reload deployment if attached Secret/ConfigMap changes. |
| deployment.nodeSelector | object, null | `nil` | Select the node where the pods should be scheduled. |
| deployment.hostAliases | list, null | `nil` | Mapping between IP and hostnames that will be injected as entries in the pod's hosts files. |
Expand All @@ -97,7 +100,9 @@ Please refer to the [Contributing Guide](CONTRIBUTING.md) for details on how to
| deployment.envFrom | object, null | `nil` | Mount environment variables from ConfigMap or Secret to the pod. Use `nameSuffix` for resources managed by this chart (name will be prefixed with application name), or `name` to reference an existing external ConfigMap or Secret not managed by this chart. See the README "Consuming environment variable in application chart" section for more details. |
| deployment.env | object, null | `nil` | Environment variables to be added to the pod. See the README "Consuming environment variable in application chart" section for more details. |
| deployment.volumes | object, null | `nil` | Volumes to be added to the pod. Key is the name of the volume. Value is the volume definition. |
| deployment.volumeClaimTemplates | object, null | `nil` | VolumeClaimTemplates to be added to the pods. Key is the name of the volume. Value is the spec for volumeClaimTemplate. Use only for StatefulSets. |
| deployment.volumeMounts | object, null | `nil` | Mount path for Volumes. Key is the name of the volume. Value is the volume mount definition. |
| deployment.persistentVolumeClaimRetentionPolicy | object, null | `nil` | Rules on what to do with residual PVCs for StatefulSets. No-op for Deployments or DaemonSets. |
| deployment.priorityClassName | string, null | `""` | Define the priority class for the pod. |
| deployment.runtimeClassName | string, null | `""` | Set the runtimeClassName for the deployment's pods. |
| deployment.tolerations | list, null | `nil` | Taint tolerations for the pods. |
Expand Down Expand Up @@ -182,6 +187,18 @@ Please refer to the [Contributing Guide](CONTRIBUTING.md) for details on how to
| service.type | string | `"ClusterIP"` | Type of service. |
| service.clusterIP | string, null | `nil` | Fixed IP for a ClusterIP service. Set to `None` for an headless service |
| service.loadBalancerClass | string, null | `nil` | LoadBalancer class name for LoadBalancer type services. |
| headlessService.name | string, null | `nil` | Optional override for service name Defaults to application.name-headless |

### Headless Service Parameters

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| headlessService.enabled | bool | `false` | Enable Headless Service for StatefulSet. |
| headlessService.additionalLabels | object, null | `nil` | Additional labels for headless service. |
| headlessService.annotations | object, null | `nil` | Annotations for headless service. |
| headlessService.ports | list | `[{"name":"http","port":8080,"protocol":"TCP","targetPort":8080}]` | Ports for applications service. |
| headlessService.ports[0].targetPort | int, string, null | `8080` | Target port on pods. Accepts port number or port name (IANA_SVC_NAME). |
| headlessService.publishNotReadyAddresses | bool, null | `nil` | Propagate SRV DNS records for Pods to enable peer discovery, by disregarding any indications of ready/not-ready for Pods. |

### Ingress Parameters

Expand Down
2 changes: 1 addition & 1 deletion README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Application

Generic Helm chart for deploying stateless applications on Kubernetes. Supports Deployments, Jobs, and CronJobs along with common companion resources (Services, Ingress, RBAC, autoscaling, monitoring, certificates, and more).
Generic Helm chart for deploying applications on Kubernetes. Supports Deployments, StatefulSets, DaemonSets, Jobs, and CronJobs along with common companion resources (Services, Ingress, RBAC, autoscaling, monitoring, certificates, and more).

## Installing the Chart

Expand Down
2 changes: 1 addition & 1 deletion application/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: application
description: Generic Helm chart for deploying stateless applications on Kubernetes
description: Generic Helm chart for deploying applications on Kubernetes
type: application
version: 9.3.1
keywords:
Expand Down
16 changes: 14 additions & 2 deletions application/ci/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ additionalLabels:
team: stakater

deployment:
kind: StatefulSet
dnsConfig:
options:
- name: ndots
value: "1"
dnsPolicy: ClusterFirst
strategy:
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
# maxSurge: 25%
maxUnavailable: 25%
reloadOnChange: true
hostAliases:
Expand Down Expand Up @@ -99,6 +100,17 @@ deployment:
volumeMounts:
volume-name:
mountPath: /path1
volume-claim-template-name:
mountPath: /path2
volumeClaimTemplates:
volume-claim-template-name:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
persistentVolumeClaimRetentionPolicy:
whenDeleted: Delete
whenScaled: Retain
tolerations:
- key: dedicated
operator: Equal
Expand Down
36 changes: 34 additions & 2 deletions application/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{{- if .Values.deployment.enabled }}
{{- $kindsWithHeadlessService := list "StatefulSet" -}}
{{- $kindsWithPodManagementPolicy := list "StatefulSet" -}}
{{- $kindsWithReplicas := list "Deployment" "StatefulSet" -}}
{{- $kindsWithStrategy := list "Deployment" -}}
{{- $kindsWithUpdateStrategy := list "DaemonSet" "StatefulSet" -}}
{{- $kindsWithVolumeClaimTemplates := list "StatefulSet" -}}
---
apiVersion: apps/v1
kind: Deployment
kind: {{ .Values.deployment.kind | default "Deployment" }}
metadata:
labels:
{{- include "application.labels" $ | nindent 4 }}
Expand All @@ -20,13 +26,26 @@ metadata:
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
spec:
{{- if and (has .Values.deployment.kind $kindsWithHeadlessService) ((.Values.headlessService).enabled) }}
serviceName: {{ .Values.headlessService.name | default (printf "%s-headless" (include "application.name" .)) }}
{{- end }}
{{- if has .Values.deployment.kind $kindsWithReplicas }}
{{- if not (eq .Values.deployment.replicas nil) }}
replicas: {{ .Values.deployment.replicas }}
{{- end }}
{{- end }}
selector:
matchLabels:
{{ include "application.selectorLabels" . | indent 6 }}
{{- if .Values.deployment.strategy }}
{{- if has .Values.deployment.kind $kindsWithPodManagementPolicy }}
{{- with .Values.deployment.podManagementPolicy }}
podManagementPolicy: {{ . }}
{{- end }}
{{- end }}
{{- if and (has .Values.deployment.kind $kindsWithUpdateStrategy) .Values.deployment.updateStrategy }}
updateStrategy:
{{ toYaml .Values.deployment.updateStrategy | indent 4 }}
{{- else if and (has .Values.deployment.kind $kindsWithStrategy) .Values.deployment.strategy }}
strategy:
{{ toYaml .Values.deployment.strategy | indent 4 }}
{{- end }}
Expand Down Expand Up @@ -344,4 +363,17 @@ spec:
{{- if not (kindIs "invalid" .Values.deployment.minReadySeconds) }}
minReadySeconds: {{ .Values.deployment.minReadySeconds }}
{{- end }}
{{- if and (has .Values.deployment.kind $kindsWithVolumeClaimTemplates) .Values.deployment.volumeClaimTemplates }}
volumeClaimTemplates:
{{- range $key, $value := .Values.deployment.volumeClaimTemplates }}
- metadata:
name: {{ $key }}
spec:
{{ include "application.tplvalues.render" ( dict "value" $value "context" $ ) | indent 6 }}
{{- end }}
{{- if .Values.deployment.persistentVolumeClaimRetentionPolicy }}
persistentVolumeClaimRetentionPolicy:
{{ toYaml .Values.deployment.persistentVolumeClaimRetentionPolicy | indent 4 }}
{{- end }}
{{- end }}
{{- end }}
27 changes: 27 additions & 0 deletions application/templates/headlessservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- if (.Values.headlessService).enabled }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.headlessService.name | default (printf "%s-headless" (include "application.name" .)) }}
namespace: {{ template "application.namespace" $ }}
labels:
{{- include "application.labels" $ | nindent 4 }}
{{- if .Values.headlessService.additionalLabels }}
{{- toYaml .Values.headlessService.additionalLabels | nindent 4 }}
{{- end }}
{{- if .Values.headlessService.annotations }}
annotations:
{{- include "application.tplvalues.render" ( dict "value" .Values.headlessService.annotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
Comment thread
davidkim83 marked this conversation as resolved.
clusterIP: None
type: ClusterIP
{{- if .Values.headlessService.publishNotReadyAddresses }}
publishNotReadyAddresses: {{ .Values.headlessService.publishNotReadyAddresses | default false }}
{{- end }}
selector:
{{ include "application.selectorLabels" . | indent 4 }}
ports:
{{ toYaml .Values.headlessService.ports | indent 4 }}
{{- end }}
2 changes: 1 addition & 1 deletion application/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ metadata:
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
kind: {{ .Values.deployment.kind }}
name: {{ template "application.name" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/vpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ metadata:
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
kind: {{ .Values.deployment.kind }}
name: {{ template "application.name" . }}
resourcePolicy:
containerPolicies:
Expand Down
30 changes: 22 additions & 8 deletions application/tests/__snapshot__/common_test.yaml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ should match snapshot:
schedule: '* * * 8 *'
11: |
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
annotations:
reloader.stakater.com/auto: "true"
Expand All @@ -334,17 +334,16 @@ should match snapshot:
name: application
namespace: NAMESPACE
spec:
persistentVolumeClaimRetentionPolicy:
whenDeleted: Delete
whenScaled: Retain
podManagementPolicy: OrderedReady
replicas: 2
revisionHistoryLimit: 2
selector:
matchLabels:
app.kubernetes.io/name: application
application.stakater.com/workload-class: serving
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations:
Expand Down Expand Up @@ -486,6 +485,8 @@ should match snapshot:
successThreshold: 1
timeoutSeconds: 1
volumeMounts:
- mountPath: /path2
name: volume-claim-template-name
- mountPath: /path1
name: volume-name
- command:
Expand Down Expand Up @@ -589,6 +590,19 @@ should match snapshot:
secretName: secret-name
- emptyDir: {}
name: volume-name
updateStrategy:
rollingUpdate:
maxUnavailable: 25%
type: RollingUpdate
volumeClaimTemplates:
- metadata:
name: volume-claim-template-name
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
12: |
apiVersion: endpointmonitor.stakater.com/v1alpha1
kind: EndpointMonitor
Expand Down Expand Up @@ -1302,7 +1316,7 @@ should match snapshot:
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
name: application
21: |
apiVersion: networking.k8s.io/v1
Expand Down Expand Up @@ -1855,7 +1869,7 @@ should match snapshot:
memory: 1Gi
targetRef:
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
name: application
updatePolicy:
updateMode: Auto
1 change: 1 addition & 0 deletions application/tests/common_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ values:
capabilities:
apiVersions:
# TODO: auto add all/used apiVersions
- apps/v1
- batch/v1
- batch/v1/CronJob
- policy/v1
Expand Down
16 changes: 15 additions & 1 deletion application/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,18 @@ tests:
path: spec.template.spec.containers
content:
name: sidecar
any: true
any: true

- it: workload type defaults to Deployment if not set
asserts:
- equal:
path: kind
value: Deployment

- it: sets correct workload type if given
set:
deployment.kind: StatefulSet
asserts:
- equal:
path: kind
value: StatefulSet
Loading