Skip to content

Commit

Permalink
new chart for knowledge base (#12)
Browse files Browse the repository at this point in the history
* basic kb chart

* cleaned up ingress.yaml

* added values-test.yaml to template each file
  • Loading branch information
js-sub authored Aug 23, 2024
1 parent 96edf07 commit 9c66308
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 0 deletions.
6 changes: 6 additions & 0 deletions charts/knowledge-base/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: knowledge-base
description: Knowledge Base frontend and API/backend
type: application
version: 0.1.0
appVersion: "0.0.1"
51 changes: 51 additions & 0 deletions charts/knowledge-base/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "knowledge-base.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "knowledge-base.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 }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "knowledge-base.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "knowledge-base.labels" -}}
helm.sh/chart: {{ include "knowledge-base.chart" . }}
{{ include "knowledge-base.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "knowledge-base.selectorLabels" -}}
app.kubernetes.io/name: {{ include "knowledge-base.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
24 changes: 24 additions & 0 deletions charts/knowledge-base/templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "knowledge-base.fullname" . }}
labels:
{{- include "knowledge-base.labels" . | nindent 4 }}
data:
application.yml: |-
sophora:
client:
server-connection:
urls:
{{- range .Values.api.sophora.connection.urls }}
- {{ . | quote }}
{{- end }}
tool-info:
name: "knowledge-base-backend"
server:
port: 8181
spring:
groovy:
template:
check-template-location: false
76 changes: 76 additions & 0 deletions charts/knowledge-base/templates/deployment_api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ include "knowledge-base.fullname" . }}-api"
labels:
{{- include "knowledge-base.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "knowledge-base.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"
checksum/config: {{ include (print $.Template.BasePath "/config.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "knowledge-base.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Always
containers:
- name: "{{ .Chart.Name }}-api"
image: "{{ .Values.api.image.repository }}:{{ .Values.api.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.api.image.pullPolicy }}
volumeMounts:
- name: config
mountPath: "/workspace/application.yml"
subPath: "application.yml"
env:
- name: sophora.client.server-connection.username
valueFrom:
secretKeyRef:
key: {{ .Values.api.sophora.authentication.secret.usernameKey }}
name: {{ required "A valid secret name must be provided in .Values.api.sophora.authentication.secret.name" .Values.api.sophora.authentication.secret.name | quote }}
- name: sophora.client.server-connection.password
valueFrom:
secretKeyRef:
key: {{ .Values.api.sophora.authentication.secret.passwordKey }}
name: {{ required "A valid secret name must be provided in .Values.api.sophora.authentication.secret.name" .Values.api.sophora.authentication.secret.name | quote }}
ports:
- name: http
containerPort: 8181
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.api.container.resources | nindent 12 }}
volumes:
- name: config
configMap:
name: {{ include "knowledge-base.fullname" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
63 changes: 63 additions & 0 deletions charts/knowledge-base/templates/deployment_frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ include "knowledge-base.fullname" . }}-frontend"
labels:
{{- include "knowledge-base.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "knowledge-base.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "knowledge-base.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Always
containers:
- name: "{{ .Chart.Name }}-frontend"
image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
env:
- name: API_ADDRESS
value: {{ .Values.frontend.apiBaseAddress }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.frontend.container.resources | nindent 12 }}
volumes:
- name: config
configMap:
name: {{ include "knowledge-base.fullname" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
41 changes: 41 additions & 0 deletions charts/knowledge-base/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "knowledge-base.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "knowledge-base.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.ingressClassName }}
ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- 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:
- path: /
pathType: Prefix
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/knowledge-base/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "knowledge-base.fullname" . }}
labels:
{{- include "knowledge-base.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "knowledge-base.selectorLabels" . | nindent 4 }}
68 changes: 68 additions & 0 deletions charts/knowledge-base/values-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
frontend:
image:
repository: docker.subshell.com/labday/knowledge-base/kb-frontend
pullPolicy: Always
tag: "1.0.0"
container:
resources:
requests:
cpu: 999m
memory: 123Mi
limits:
cpu: 888m
memory: 4321Mi
apiBaseAddress: "test-api.address"

api:
image:
repository: docker.subshell.com/labday/knowledge-base/kb-api
pullPolicy: Always
tag: "1.0.0"
container:
resources:
requests:
cpu: 222m
memory: 42Mi
limits:
cpu: 333m
memory: 1337Mi
sophora:
connection:
urls:
- "http://sophora-server1"
- "http://sophora-server2"
authentication:
secret:
name: "knowledge-base-sophora-credentials"
usernameKey: "sophora-user"
passwordKey: "sophora-password"

imagePullSecrets: []
nameOverride: "testNameOverride"
fullnameOverride: "fullTestNameOverride"

podAnnotations:
my/test/annotation: "foo"
my/other/annotation: "bar"

service:
type: ClusterIP
port: 80

ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: frontend.knowledge-base.test
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

nodeSelector: {}

tolerations: []

affinity: {}
Loading

0 comments on commit 9c66308

Please sign in to comment.