From c9139aa85085eb134566b5f9c3b2cce0dfa009a0 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 14 Nov 2024 08:13:40 +0100 Subject: [PATCH] Initial --- Chart.yaml | 7 ++ README.md | 130 ++++++++++++++++++++++++++++++++++++++ templates/_helpers.tpl | 17 +++++ templates/deployment.yaml | 31 +++++++++ templates/ingress.yaml | 38 +++++++++++ templates/pvc.yaml | 15 +++++ templates/service.yaml | 16 +++++ values.yaml | 37 +++++++++++ 8 files changed, 291 insertions(+) create mode 100644 Chart.yaml create mode 100644 README.md create mode 100644 templates/_helpers.tpl create mode 100644 templates/deployment.yaml create mode 100644 templates/ingress.yaml create mode 100644 templates/pvc.yaml create mode 100644 templates/service.yaml create mode 100644 values.yaml diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..79afa0b --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,7 @@ +# Chart.yaml +apiVersion: v2 +name: basic-app +description: A basic Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/README.md b/README.md new file mode 100644 index 0000000..2b9eb06 --- /dev/null +++ b/README.md @@ -0,0 +1,130 @@ +# Basic Application Helm Chart + +## Overview +This Helm chart deploys a basic application on a Kubernetes cluster with the following components: +- A deployment with configurable replicas +- A persistent volume claim for data storage +- A service for internal communication +- An ingress for external access with TLS support + +## Prerequisites +- Kubernetes 1.19+ +- Helm 3.0+ +- PV provisioner support in the underlying infrastructure +- Ingress controller (e.g., nginx-ingress) + +## Installation + +### Add the repository +```bash +# If hosted in a Helm repository +helm repo add my-repo https://charts.example.com +helm repo update +``` + +### Install the chart +```bash +# Using default values +helm install my-release . + +# Using custom values file +helm install my-release . -f values.yaml + +# Using --set +helm install my-release . --set ingress.hosts[0].host=example.com +``` + +## Uninstallation +```bash +helm uninstall my-release +``` + +## Configuration + +The following table lists the configurable parameters of the chart and their default values. + +| Parameter | Description | Default | +|-----------|-------------|---------| +| `replicaCount` | Number of replicas | `1` | +| `image.repository` | Image repository | `nginx` | +| `image.tag` | Image tag | `latest` | +| `image.pullPolicy` | Image pull policy | `IfNotPresent` | +| `service.type` | Kubernetes service type | `ClusterIP` | +| `service.port` | Kubernetes service port | `80` | +| `ingress.enabled` | Enable ingress | `true` | +| `ingress.className` | Ingress class name | `nginx` | +| `ingress.annotations` | Ingress annotations | `{}` | +| `ingress.hosts[0].host` | Hostname | `chart-example.local` | +| `ingress.hosts[0].paths[0].path` | Path | `/` | +| `ingress.hosts[0].paths[0].pathType` | Path type | `Prefix` | +| `ingress.tls.enabled` | Enable TLS | `true` | +| `ingress.tls.secretName` | TLS secret name | `chart-example-tls` | +| `persistence.enabled` | Enable persistence | `true` | +| `persistence.accessMode` | PVC access mode | `ReadWriteOnce` | +| `persistence.size` | PVC size | `1Gi` | +| `persistence.storageClass` | PVC storage class | `""` | + +### Ingress Annotations Examples + +For NGINX ingress controller: +```yaml +ingress: + annotations: + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" +``` + +For cert-manager SSL certificates: +```yaml +ingress: + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-prod" +``` + +## TLS Configuration + +To use TLS, create a TLS secret in the namespace: + +```bash +kubectl create secret tls chart-example-tls \ + --cert=path/to/tls.cert \ + --key=path/to/tls.key +``` + +Then enable it in values.yaml: +```yaml +ingress: + tls: + enabled: true + secretName: chart-example-tls + hosts: + - chart-example.local +``` + +## Persistence + +The chart mounts a Persistent Volume at `/data`. The volume is created using dynamic volume provisioning. + +## Upgrading + +```bash +# Upgrade using values file +helm upgrade my-release . -f values.yaml + +# Upgrade with --set flag +helm upgrade my-release . --set replicaCount=3 +``` + +## Limitations +- The chart has been tested on Kubernetes 1.19+ +- Persistent volume provisioning support in underlying infrastructure +- Ingress controller must be present in the cluster + +## Contributing +If you find any issues with this chart or want to contribute improvements: +1. Fork the repository +2. Create a new branch for your changes +3. Submit a pull request + +## License +This Helm chart is licensed under the MIT License. diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000..ca8536b --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,17 @@ +{/* +Common labels +*/}} +{{- define "basic-app.labels" -}} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} +app.kubernetes.io/name: {{ .Chart.Name }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "basic-app.selectorLabels" -}} +app.kubernetes.io/name: {{ .Chart.Name }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/templates/deployment.yaml b/templates/deployment.yaml new file mode 100644 index 0000000..0194f64 --- /dev/null +++ b/templates/deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} + labels: + {{- include "basic-app.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "basic-app.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "basic-app.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: 80 + protocol: TCP + volumeMounts: + - name: data + mountPath: /data + volumes: + - name: data + persistentVolumeClaim: + claimName: {{ .Release.Name }}-pvc + diff --git a/templates/ingress.yaml b/templates/ingress.yaml new file mode 100644 index 0000000..be9bc40 --- /dev/null +++ b/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Release.Name }} + labels: + {{- include "basic-app.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + ingressClassName: {{ .Values.ingress.className }} + {{- if and .Values.ingress.tls .Values.ingress.tls.enabled }} + tls: + - hosts: + {{- range .Values.ingress.tls.hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .Values.ingress.tls.secretName }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ $.Release.Name }} + port: + number: {{ $.Values.service.port }} + {{- end }} + {{- end }} +{{- end }} + diff --git a/templates/pvc.yaml b/templates/pvc.yaml new file mode 100644 index 0000000..2c680cb --- /dev/null +++ b/templates/pvc.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }}-pvc + labels: + {{- include "basic-app.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.persistence.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.size }} + {{- if .Values.persistence.storageClass }} + storageClassName: {{ .Values.persistence.storageClass }} + {{- end }} diff --git a/templates/service.yaml b/templates/service.yaml new file mode 100644 index 0000000..3782f5f --- /dev/null +++ b/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }} + labels: + {{- include "basic-app.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 80 + protocol: TCP + name: http + selector: + {{- include "basic-app.selectorLabels" . | nindent 4 }} + diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..745148c --- /dev/null +++ b/values.yaml @@ -0,0 +1,37 @@ +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + tag: "latest" + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: true + className: nginx + hosts: + - host: chart-example.local + paths: + - path: / + pathType: Prefix + +persistence: + enabled: true + accessMode: ReadWriteOnce + size: 1Gi + storageClass: "" + + +ingress: + tls: + enabled: true + secretName: chart-example-tls + hosts: + - chart-example.local + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + # cert-manager.io/cluster-issuer: "letsencrypt-prod"