feat: add charts template and normalize oxicloud's chart with it
This commit is contained in:
parent
abd0e9bb4d
commit
8597cf5730
25 changed files with 749 additions and 249 deletions
13
k8s/charts/_template/.helmignore
Normal file
13
k8s/charts/_template/.helmignore
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Patterns to ignore when building packages.
|
||||
# This supports shell glob matching.
|
||||
*.tgz
|
||||
.env
|
||||
.git
|
||||
.git_cache
|
||||
.idea
|
||||
*.md
|
||||
docs/*
|
||||
tmp/*
|
||||
vendor/*
|
||||
.travis.yml
|
||||
.testignore
|
||||
16
k8s/charts/_template/Chart.yaml
Normal file
16
k8s/charts/_template/Chart.yaml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
apiVersion: v2
|
||||
name: chart
|
||||
description: A Helm chart template with standardized structure
|
||||
type: application
|
||||
version: 0.1.0
|
||||
appVersion: "latest"
|
||||
annotations:
|
||||
artifacthub.io/images: |
|
||||
- name: chart
|
||||
image: nginx:latest
|
||||
artifacthub.io/changes: |
|
||||
- kind: added
|
||||
description: Initial chart template
|
||||
artifacthub.io/maintainers: |
|
||||
- name: catalin
|
||||
email: catalin@example.com
|
||||
105
k8s/charts/_template/README.md
Normal file
105
k8s/charts/_template/README.md
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
# chart
|
||||
|
||||
A Helm chart template with standardized structure for self-hosted services.
|
||||
|
||||
## TL;DR
|
||||
|
||||
```bash
|
||||
helm install chart oci://git.roboces.dev/catalin/fukuops/chart --version 1.0.0 -n apps-roboces
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Kubernetes 1.19+
|
||||
- Helm 3+
|
||||
- A NFS storage class (default: `truenas-nfs-csi`) - only if persistence is enabled
|
||||
- An existing `Secret` with credentials if required (see `secret.existingSecretName`)
|
||||
|
||||
## Configuration
|
||||
|
||||
### Basic Configuration
|
||||
|
||||
```yaml
|
||||
service:
|
||||
type: LoadBalancer
|
||||
port: 80
|
||||
ingress:
|
||||
enabled: true
|
||||
className: "traefik"
|
||||
hosts:
|
||||
- host: chart.example.com
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
```
|
||||
|
||||
### With Persistence
|
||||
|
||||
```yaml
|
||||
persistence:
|
||||
enabled: true
|
||||
storageClass: "truenas-nfs-csi"
|
||||
accessMode: ReadWriteMany
|
||||
size: 10Gi
|
||||
```
|
||||
|
||||
### With Secrets
|
||||
|
||||
```yaml
|
||||
secret:
|
||||
existingSecretName: chart-secrets
|
||||
```
|
||||
|
||||
## Values Reference
|
||||
|
||||
| Key | Type | Default | Description |
|
||||
|-----|------|---------|-------------|
|
||||
| `replicaCount` | int | `1` | Number of replicas |
|
||||
| `image.repository` | string | `nginx` | Image repository |
|
||||
| `image.pullPolicy` | string | `IfNotPresent` | Image pull policy |
|
||||
| `image.tag` | string | `.Chart.AppVersion` | Image tag |
|
||||
| `service.type` | string | `LoadBalancer` | Service type |
|
||||
| `service.port` | int | `80` | Service port |
|
||||
| `service.targetPort` | int | `80` | Container port |
|
||||
| `ingress.enabled` | bool | `false` | Enable ingress |
|
||||
| `ingress.className` | string | `traefik` | Ingress class |
|
||||
| `persistence.enabled` | bool | `false` | Enable persistence |
|
||||
| `persistence.storageClass` | string | `truenas-nfs-csi` | Storage class |
|
||||
| `persistence.accessMode` | string | `ReadWriteMany` | Access mode |
|
||||
| `persistence.size` | string | `1Gi` | PVC size |
|
||||
| `persistence.name` | string | `chart-data` | PVC name |
|
||||
| `secret.existingSecretName` | string | `""` | Existing secret name |
|
||||
| `resources` | object | `{}` | Container resources |
|
||||
| `livenessProbe` | object | (see values.yaml) | Liveness probe |
|
||||
| `readinessProbe` | object | (see values.yaml) | Readiness probe |
|
||||
| `nodeSelector` | object | `{}` | Node selector |
|
||||
| `tolerations` | array | `[]` | Tolerations |
|
||||
| `affinity` | object | `{}` | Affinity rules |
|
||||
|
||||
## Persistence
|
||||
|
||||
When persistence is enabled, a PVC named `chart-data` is created. The PVC uses the `truenas-nfs-csi` storage class by default with `ReadWriteMany` access mode.
|
||||
|
||||
## Secret Management
|
||||
|
||||
The chart looks for an existing `Secret` with the name specified in `secret.existingSecretName`. If not provided, no secret is mounted.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Pod not starting
|
||||
|
||||
```bash
|
||||
kubectl get pvc -n apps-roboces -l app.kubernetes.io/name=chart
|
||||
```
|
||||
|
||||
### Check logs
|
||||
|
||||
```bash
|
||||
kubectl logs chart-0 -n apps-roboces
|
||||
```
|
||||
|
||||
### Verify configmap
|
||||
|
||||
```bash
|
||||
kubectl get configmap chart-config -n apps-roboces -o yaml
|
||||
```
|
||||
37
k8s/charts/_template/templates/_helpers.tpl
Normal file
37
k8s/charts/_template/templates/_helpers.tpl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
{{/* Expand the name of the chart. */}}
|
||||
{{- define "name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/* Create a default fully qualified app name. */}}
|
||||
{{- define "fullname" -}}
|
||||
{{- if .Values.fullnameOverride }}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||
{{- if contains $name .Release.Name }}
|
||||
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{/* Common labels */}}
|
||||
{{- define "labels" -}}
|
||||
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{ include "selectorLabels" . }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{/* Selector labels */}}
|
||||
{{- define "selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/* Chart name as the PVC name */}}
|
||||
{{- define "pvcName" -}}
|
||||
{{- .Values.persistence.name | default (printf "%s-data" (include "name" .)) }}
|
||||
{{- end }}
|
||||
12
k8s/charts/_template/templates/configmap.yaml
Normal file
12
k8s/charts/_template/templates/configmap.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{{- if .Values.config }}
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ include "fullname" . }}-config
|
||||
labels:
|
||||
{{- include "labels" . | nindent 4 }}
|
||||
data:
|
||||
{{- range $key, $value := .Values.config }}
|
||||
{{ $key }}: {{ $value | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
68
k8s/charts/_template/templates/deployment.yaml
Normal file
68
k8s/charts/_template/templates/deployment.yaml
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "fullname" . }}
|
||||
labels:
|
||||
{{- include "labels" . | nindent 4 }}
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "selectorLabels" . | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
{{- include "selectorLabels" . | nindent 8 }}
|
||||
spec:
|
||||
containers:
|
||||
- name: {{ .Chart.Name }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: {{ .Values.service.targetPort }}
|
||||
protocol: TCP
|
||||
{{- if .Values.config }}
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: {{ include "fullname" . }}-config
|
||||
{{- end }}
|
||||
{{- if .Values.secret.existingSecretName }}
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: {{ .Values.secret.existingSecretName }}
|
||||
{{- end }}
|
||||
{{- if .Values.persistence.enabled }}
|
||||
volumeMounts:
|
||||
- name: {{ include "pvcName" . }}
|
||||
mountPath: /data
|
||||
{{- end }}
|
||||
{{- with .Values.resources }}
|
||||
resources:
|
||||
{{- toYaml . | nindent 12 }}
|
||||
{{- end }}
|
||||
{{- with .Values.livenessProbe }}
|
||||
livenessProbe:
|
||||
{{- toYaml . | nindent 12 }}
|
||||
{{- end }}
|
||||
{{- with .Values.readinessProbe }}
|
||||
readinessProbe:
|
||||
{{- toYaml . | nindent 12 }}
|
||||
{{- end }}
|
||||
{{- if not .Values.persistence.enabled }}
|
||||
volumes:
|
||||
- name: {{ include "pvcName" . }}
|
||||
emptyDir: {}
|
||||
{{- end }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
41
k8s/charts/_template/templates/ingress.yaml
Normal file
41
k8s/charts/_template/templates/ingress.yaml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{{- if .Values.ingress.enabled }}
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: {{ include "fullname" . }}
|
||||
labels:
|
||||
{{- include "labels" . | nindent 4 }}
|
||||
{{- with .Values.ingress.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- if .Values.ingress.className }}
|
||||
ingressClassName: {{ .Values.ingress.className }}
|
||||
{{- end }}
|
||||
{{- if .Values.ingress.tls }}
|
||||
tls:
|
||||
{{- range .Values.ingress.tls }}
|
||||
- hosts:
|
||||
{{- range .hosts }}
|
||||
- {{ . | quote }}
|
||||
{{- end }}
|
||||
secretName: {{ .secretName }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
rules:
|
||||
{{- range .Values.ingress.hosts }}
|
||||
- host: {{ .host | quote }}
|
||||
http:
|
||||
paths:
|
||||
{{- range .paths }}
|
||||
- path: {{ .path }}
|
||||
pathType: {{ .pathType | default "Prefix" }}
|
||||
backend:
|
||||
service:
|
||||
name: {{ include "fullname" $ }}
|
||||
port:
|
||||
number: {{ $.Values.service.port }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
17
k8s/charts/_template/templates/pvc.yaml
Normal file
17
k8s/charts/_template/templates/pvc.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{{- if .Values.persistence.enabled }}
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: {{ include "pvcName" . }}
|
||||
labels:
|
||||
{{- include "labels" . | nindent 4 }}
|
||||
spec:
|
||||
accessModes:
|
||||
- {{ .Values.persistence.accessMode | default "ReadWriteMany" }}
|
||||
{{- if .Values.persistence.storageClass }}
|
||||
storageClassName: {{ .Values.persistence.storageClass }}
|
||||
{{- end }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.persistence.size | default "1Gi" }}
|
||||
{{- end }}
|
||||
13
k8s/charts/_template/templates/secret.yaml
Normal file
13
k8s/charts/_template/templates/secret.yaml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{{- if and .Values.secret.enabled (not .Values.secret.existingSecretName) .Values.secret.data }}
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: {{ include "fullname" . }}-secret
|
||||
labels:
|
||||
{{- include "labels" . | nindent 4 }}
|
||||
type: Opaque
|
||||
data:
|
||||
{{- range $key, $value := .Values.secret.data }}
|
||||
{{ $key }}: {{ $value | b64enc | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
15
k8s/charts/_template/templates/service.yaml
Normal file
15
k8s/charts/_template/templates/service.yaml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ include "fullname" . }}
|
||||
labels:
|
||||
{{- include "labels" . | nindent 4 }}
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- port: {{ .Values.service.port }}
|
||||
targetPort: http
|
||||
protocol: TCP
|
||||
name: http
|
||||
selector:
|
||||
{{- include "selectorLabels" . | nindent 4 }}
|
||||
60
k8s/charts/_template/values.yaml
Normal file
60
k8s/charts/_template/values.yaml
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
replicaCount: 1
|
||||
|
||||
image:
|
||||
repository: nginx
|
||||
pullPolicy: IfNotPresent
|
||||
tag: ""
|
||||
|
||||
service:
|
||||
type: LoadBalancer
|
||||
port: 80
|
||||
targetPort: 80
|
||||
|
||||
ingress:
|
||||
enabled: false
|
||||
className: "traefik"
|
||||
annotations: {}
|
||||
hosts:
|
||||
- host: chart.example.com
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
tls: []
|
||||
|
||||
config: {}
|
||||
|
||||
persistence:
|
||||
enabled: false
|
||||
storageClass: "truenas-nfs-csi"
|
||||
accessMode: ReadWriteMany
|
||||
size: 1Gi
|
||||
name: "chart-data"
|
||||
|
||||
resources: {}
|
||||
|
||||
livenessProbe:
|
||||
tcpSocket:
|
||||
port: 80
|
||||
initialDelaySeconds: 30
|
||||
timeoutSeconds: 15
|
||||
successThreshold: 1
|
||||
failureThreshold: 3
|
||||
periodSeconds: 10
|
||||
|
||||
readinessProbe:
|
||||
tcpSocket:
|
||||
port: 80
|
||||
initialDelaySeconds: 15
|
||||
timeoutSeconds: 2
|
||||
successThreshold: 1
|
||||
failureThreshold: 3
|
||||
periodSeconds: 10
|
||||
|
||||
nodeSelector: {}
|
||||
tolerations: []
|
||||
affinity: {}
|
||||
|
||||
secret:
|
||||
enabled: true
|
||||
existingSecretName: ""
|
||||
data: {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue