From cb04b737add6fd45d1a826faafd8bf66fc462a69 Mon Sep 17 00:00:00 2001 From: pushthat Date: Sun, 31 Mar 2019 18:19:40 +0200 Subject: [PATCH] [ADD] helm chart --- charts/sonic/.helmignore | 21 ++++++ charts/sonic/Chart.yaml | 5 ++ charts/sonic/README.md | 9 +++ charts/sonic/templates/NOTES.txt | 19 ++++++ charts/sonic/templates/_helpers.tpl | 32 +++++++++ charts/sonic/templates/ingress.yaml | 38 +++++++++++ charts/sonic/templates/service.yaml | 19 ++++++ charts/sonic/templates/sonicConfig.yaml | 62 +++++++++++++++++ charts/sonic/templates/statefullSet.yaml | 86 ++++++++++++++++++++++++ charts/sonic/values.yaml | 47 +++++++++++++ 10 files changed, 338 insertions(+) create mode 100644 charts/sonic/.helmignore create mode 100644 charts/sonic/Chart.yaml create mode 100644 charts/sonic/README.md create mode 100644 charts/sonic/templates/NOTES.txt create mode 100644 charts/sonic/templates/_helpers.tpl create mode 100644 charts/sonic/templates/ingress.yaml create mode 100644 charts/sonic/templates/service.yaml create mode 100644 charts/sonic/templates/sonicConfig.yaml create mode 100644 charts/sonic/templates/statefullSet.yaml create mode 100644 charts/sonic/values.yaml diff --git a/charts/sonic/.helmignore b/charts/sonic/.helmignore new file mode 100644 index 00000000..f0c13194 --- /dev/null +++ b/charts/sonic/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/charts/sonic/Chart.yaml b/charts/sonic/Chart.yaml new file mode 100644 index 00000000..58ed86a8 --- /dev/null +++ b/charts/sonic/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "v1.1.9" +description: Sonic is a fast, lightweight and schema-less search backend. It ingests search texts and identifier tuples that can then be queried against in a microsecond's time. +name: sonic-helm-chart +version: 0.1.0 diff --git a/charts/sonic/README.md b/charts/sonic/README.md new file mode 100644 index 00000000..976a816b --- /dev/null +++ b/charts/sonic/README.md @@ -0,0 +1,9 @@ +# Sonic + +**Sonic is a fast, lightweight and schema-less search backend. It ingests search texts and identifier tuples that can then be queried against in a microsecond's time.** + +![Sonic](https://valeriansaliou.github.io/sonic/images/banner.jpg) + +Sonic Helm chart for Kubernetes + +The chart is not perfect, the sonic configuration must be done on the template itself templates/sonicConfig.yaml diff --git a/charts/sonic/templates/NOTES.txt b/charts/sonic/templates/NOTES.txt new file mode 100644 index 00000000..ab0202ab --- /dev/null +++ b/charts/sonic/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "sonic-helm-chart.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ include "sonic-helm-chart.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "sonic-helm-chart.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "sonic-helm-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/charts/sonic/templates/_helpers.tpl b/charts/sonic/templates/_helpers.tpl new file mode 100644 index 00000000..0a9f89d3 --- /dev/null +++ b/charts/sonic/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "sonic-helm-chart.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 "sonic-helm-chart.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 "sonic-helm-chart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/charts/sonic/templates/ingress.yaml b/charts/sonic/templates/ingress.yaml new file mode 100644 index 00000000..059b48d5 --- /dev/null +++ b/charts/sonic/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "sonic-helm-chart.fullname" . -}} +{{- $ingressPath := .Values.ingress.path -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app.kubernetes.io/name: {{ include "sonic-helm-chart.name" . }} + helm.sh/chart: {{ include "sonic-helm-chart.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- with .Values.ingress.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} +{{- end }} diff --git a/charts/sonic/templates/service.yaml b/charts/sonic/templates/service.yaml new file mode 100644 index 00000000..a6fd2629 --- /dev/null +++ b/charts/sonic/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "sonic-helm-chart.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "sonic-helm-chart.name" . }} + helm.sh/chart: {{ include "sonic-helm-chart.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "sonic-helm-chart.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/sonic/templates/sonicConfig.yaml b/charts/sonic/templates/sonicConfig.yaml new file mode 100644 index 00000000..4cea3fe8 --- /dev/null +++ b/charts/sonic/templates/sonicConfig.yaml @@ -0,0 +1,62 @@ +kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ include "sonic-helm-chart.fullname" . }} +data: + sonic.cfg: |- + # Sonic + # Fast, lightweight and schema-less search backend + # Configuration file + # Example: https://github.com/valeriansaliou/sonic/blob/master/config.cfg + + [server] + + log_level = "error" + + [channel] + + inet = "0.0.0.0:1491" + tcp_timeout = 300 + + auth_password = "SecretPassword" + + [channel.search] + + query_limit_default = 10 + query_limit_maximum = 100 + query_alternates_try = 4 + + suggest_limit_default = 5 + suggest_limit_maximum = 20 + + [store] + + [store.kv] + + path = "./data/store/kv/" + + retain_word_objects = 1000 + + [store.kv.pool] + + inactive_after = 1800 + + [store.kv.database] + + compress = true + parallelism = 2 + max_files = 100 + max_compactions = 1 + max_flushes = 1 + + [store.fst] + + path = "./data/store/fst/" + + [store.fst.pool] + + inactive_after = 300 + + [store.fst.graph] + + diff --git a/charts/sonic/templates/statefullSet.yaml b/charts/sonic/templates/statefullSet.yaml new file mode 100644 index 00000000..6aca6326 --- /dev/null +++ b/charts/sonic/templates/statefullSet.yaml @@ -0,0 +1,86 @@ + +apiVersion: apps/v1beta2 +kind: StatefulSet +metadata: + name: {{ include "sonic-helm-chart.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "sonic-helm-chart.name" . }} + helm.sh/chart: {{ include "sonic-helm-chart.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: {{ include "sonic-helm-chart.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "sonic-helm-chart.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["sonic" ,"-c", "/etc/config/sonic.cfg"] + volumeMounts: + {{- if .Values.persistence.enabled }} + - name: data + mountPath: /var/lib/sonic/store/ + {{ end }} + - name: sonic-config + mountPath: /etc/config + ports: + - name: sonic + containerPort: 1491 + protocol: TCP + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} + + volumes: + - name: sonic-config + configMap: + name: {{ include "sonic-helm-chart.fullname" . }} + + +{{- if .Values.persistence.enabled }} + volumeClaimTemplates: + - metadata: + name: data + annotations: + {{- range $key, $value := .Values.persistence.annotations }} + {{ $key }}: {{ $value }} + {{- end }} + spec: + accessModes: + {{- range .Values.persistence.accessModes }} + - {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} + {{- if .Values.persistence.storageClass }} + {{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" + {{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" + {{- end }} + {{- end }} +{{- else }} + - name: data + emptyDir: {} +{{- end }} diff --git a/charts/sonic/values.yaml b/charts/sonic/values.yaml new file mode 100644 index 00000000..2d65c472 --- /dev/null +++ b/charts/sonic/values.yaml @@ -0,0 +1,47 @@ +# Default values for sonic-helm-chart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +sonic: + password: "SecretPassword" + +image: + repository: valeriansaliou/sonic + tag: v1.1.9 + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 1491 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + path: / + hosts: + - chart-example.local + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +persistence: + enabled: true + # storageClass: "-" + accessModes: + - ReadWriteOnce + size: 8Gi + annotations: {} + +resources: {} + +nodeSelector: {} + +tolerations: [] + +affinity: {}