Skip to content

Commit

Permalink
initial commit of a very generic kubernetes app helm chart :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebot committed Mar 30, 2024
1 parent 2e06a21 commit d8f67d9
Show file tree
Hide file tree
Showing 8 changed files with 939 additions and 46 deletions.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ Because sometimes you don't want to write a whole helm chart for a simple app. T

## How?

Because this chart is basically just the stock helm chart, you can use it like any other. It defaults to just deploying the nginx container, but you can change that. In fact, you can change basically everything. We even let you disable the default service, and have an option to deploy a cronjob/job instead of (or in addition to) a deployment.
Because this chart is basically just the stock helm chart, you can use it like any other. It defaults to just deploying the nginx container, but you can change that. In fact, you can change basically everything. We even let you disable the default service, and have an option to deploy a Job instead of (or in addition to) a Deployment.


### Changing the default deployment

Here's how to get started using your own docker container

```yaml
Expand All @@ -30,18 +32,35 @@ deployment:
tag: "latest"
```
### Enabling the ingress
#### Disabling the deployment
Sometimes you just need a job...
```yaml
ingress:
deployment:
enabled: false
```
## Enabling a job
```yaml
job:
enabled: true
image:
# -- provide this only if you're not hosting on hub.docker.com (docker.io)
registry: ""
# -- this can be set to any docker repo
repository: "mydockercontainer"
# -- docker image tag to pull
tag: "latest"
```
### Disabling the deployment
### Enabling the ingress
```yaml
deployment:
enabled: false
ingress:
enabled: true
```
### Disabling the service
Expand Down
6 changes: 6 additions & 0 deletions charts/generic-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ version: 0.1.0
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

maintainers:
- name: JesseBot
url: https://github.com/jessebot
- name: cloudymax
url: https://github.com/cloudymax
661 changes: 661 additions & 0 deletions charts/generic-app/LICENSE

Large diffs are not rendered by default.

72 changes: 44 additions & 28 deletions charts/generic-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,28 @@ A generic Helm chart for Kubernetes for when you have a docker container and don

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| deployment.affinity | object | `{}` | |
| deployment.autoscaling.enabled | bool | `false` | |
| deployment.autoscaling.maxReplicas | int | `100` | |
| deployment.autoscaling.minReplicas | int | `1` | |
| deployment.autoscaling.targetCPUUtilizationPercentage | int | `80` | |
| deployment.enabled | bool | `true` | |
| deployment.env | object | `{}` | |
| deployment.envFrom | object | `{}` | |
| deployment.image.pullPolicy | string | `"IfNotPresent"` | |
| deployment.image.registry | string | `"docker.io"` | |
| deployment.image.repository | string | `"nginx"` | |
| deployment.image.tag | string | `"latest"` | |
| deployment.imagePullSecrets | list | `[]` | |
| deployment.initcontainers | object | `{}` | |
| deployment.livenessProbe.enabled | bool | `true` | |
| deployment.livenessProbe.httpGet.path | string | `"/"` | |
| deployment.livenessProbe.httpGet.port | string | `"http"` | |
| deployment.nodeSelector | object | `{}` | |
| deployment.podAnnotations | object | `{}` | |
| deployment.podLabels | object | `{}` | |
| deployment.podSecurityContext | object | `{}` | |
| deployment.readinessProbe.enabled | bool | `true` | |
| deployment.readinessProbe.httpGet.path | string | `"/"` | |
| deployment.readinessProbe.httpGet.port | string | `"http"` | |
| deployment.replicaCount | int | `1` | |
| deployment.resources | object | `{}` | |
| deployment.securityContext | object | `{}` | |
| deployment.tolerations | list | `[]` | |
| deployment.affinity | object | `{}` | affinity settings for the deployment |
| deployment.autoscaling | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | autoscaling for the deployment |
| deployment.containerCommand | list | `[]` | command to pass to docker container |
| deployment.enabled | bool | `true` | enable the deployment vs job vs cronjob |
| deployment.env | list | `[]` | env list for deployment main container |
| deployment.envFrom | list | `[]` | env from list for deployment main container |
| deployment.image.pullPolicy | string | `"IfNotPresent"` | image pull policy, set to Always if using latest and it changes frequently |
| deployment.image.registry | string | `"docker.io"` | docker registry if not using docker.io |
| deployment.image.repository | string | `"nginx"` | docker repo |
| deployment.image.tag | string | `"latest"` | Overrides the image tag whose default is latest |
| deployment.imagePullSecrets | list | `[]` | optional image pull secrets |
| deployment.initcontainers | object | `{}` | extra init containers for the default deployment |
| deployment.livenessProbe | object | `{"enabled":true,"httpGet":{"path":"/","port":"http"}}` | livenessProbe for the deployment |
| deployment.nodeSelector | object | `{}` | node selector for deployment |
| deployment.podAnnotations | object | `{}` | extra pod annotations for the deployment |
| deployment.podLabels | object | `{}` | extra pod labels for the deployment |
| deployment.podSecurityContext | object | `{}` | pod securityContext deployment's main container |
| deployment.readinessProbe | object | `{"enabled":true,"httpGet":{"path":"/","port":"http"}}` | readinessProbe for the deployment |
| deployment.replicaCount | int | `1` | replica count if not using autoscaling |
| deployment.resources | object | `{}` | resources for the deployment |
| deployment.securityContext | object | `{}` | securityContext whole deployment |
| deployment.tolerations | list | `[]` | tolerations of taints on a node |
| deployment.volumeMounts | list | `[]` | Additional volumeMounts on the output Deployment definition. |
| deployment.volumes | list | `[]` | Additional volumes on the output Deployment definition. |
| fullnameOverride | string | `""` | |
Expand All @@ -46,6 +40,28 @@ A generic Helm chart for Kubernetes for when you have a docker container and don
| ingress.hosts[0].paths[0].path | string | `"/"` | |
| ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | |
| ingress.tls | list | `[]` | |
| job.affinity | object | `{}` | affinity settings for the job |
| job.containerCommand | list | `[]` | command to pass to docker container |
| job.enabled | bool | `false` | enable a job |
| job.env | list | `[]` | env list for job main container |
| job.envFrom | list | `[]` | env from list for job main container |
| job.image.pullPolicy | string | `"IfNotPresent"` | image pull policy, set to Always if using latest and it changes frequently |
| job.image.registry | string | `"docker.io"` | docker registry if not using docker.io |
| job.image.repository | string | `"nginx"` | docker repo |
| job.image.tag | string | `"latest"` | Overrides the image tag whose default is latest |
| job.imagePullSecrets | list | `[]` | optional image pull secrets |
| job.initcontainers | object | `{}` | extra init containers for the default job |
| job.nodeSelector | object | `{}` | node selector for job |
| job.podAnnotations | object | `{}` | extra pod annotations for the job |
| job.podLabels | object | `{}` | extra pod labels for the job |
| job.podSecurityContext | object | `{}` | pod securityContext job's main container |
| job.replicaCount | int | `1` | replica count if not using autoscaling |
| job.resources | object | `{}` | resources for the job |
| job.restartPolicy | string | `"never"` | restart policy if the job fails; can be never, or always |
| job.securityContext | object | `{}` | securityContext whole job |
| job.tolerations | list | `[]` | tolerations of taints on a node |
| job.volumeMounts | list | `[]` | Additional volumeMounts on the output job definition. |
| job.volumes | list | `[]` | Additional volumes on the output job definition. |
| nameOverride | string | `""` | |
| service.enabled | bool | `true` | |
| service.port | int | `80` | |
Expand Down
6 changes: 5 additions & 1 deletion charts/generic-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
labels:
{{- include "generic-app.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
{{- if not .Values.deployment.autoscaling.enabled }}
replicas: {{ .Values.deployment.replicaCount }}
{{- end }}
selector:
Expand Down Expand Up @@ -42,6 +42,10 @@ spec:
{{- toYaml .Values.deployment.securityContext | nindent 12 }}
image: "{{ .Values.deployment.image.registry }}/{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.deployment.image.pullPolicy }}
{{- with .Values.deployment.containerCommand }}
command:
{{- toYaml . | nindent 12}}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
Expand Down
14 changes: 7 additions & 7 deletions charts/generic-app/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.autoscaling.enabled }}
{{- if .Values.deployment.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
Expand All @@ -10,23 +10,23 @@ spec:
apiVersion: apps/v1
kind: Deployment
name: {{ include "generic-app.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
minReplicas: {{ .Values.deployment.autoscaling.minReplicas }}
maxReplicas: {{ .Values.deployment.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- if .Values.deployment.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
averageUtilization: {{ .Values.deployment.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- if .Values.deployment.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
averageUtilization: {{ .Values.deployment.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
89 changes: 89 additions & 0 deletions charts/generic-app/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{- if .Values.job.enabled }}
apiVersion: apps/v1
kind: Job
metadata:
name: {{ include "generic-app.fullname" . }}
labels:
{{- include "generic-app.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "generic-app.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.job.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "generic-app.labels" . | nindent 8 }}
{{- with .Values.job.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
restartPolicy: {{ .Values.job.restartPolicy }}
{{- with .Values.job.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "generic-app.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.job.podSecurityContext | nindent 8 }}

{{- if .Values.job.initContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.job.securityContext | nindent 12 }}
image: "{{ .Values.job.image.registry }}/{{ .Values.job.image.repository }}:{{ .Values.job.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.job.image.pullPolicy }}
{{- with .Values.job.containerCommand }}
command:
{{- toYaml . | nindent 12}}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
{{- if .Values.job.livenessProbe.enabled }}
livenessProbe:
{{- toYaml .Values.job.livenessProbe | nindent 12 }}
{{- end }}
{{- if .Values.job.readinessProbe.enabled }}
readinessProbe:
{{- toYaml .Values.job.readinessProbe | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.job.resources | nindent 12 }}
{{- with .Values.job.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.job.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.job.envFrom }}
envFrom:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.job.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.job.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.job.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.job.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
Loading

0 comments on commit d8f67d9

Please sign in to comment.