From bda9e4e351488ece3708b2e45eeb153c4bbaab19 Mon Sep 17 00:00:00 2001 From: liyang Date: Mon, 16 Oct 2023 20:10:08 +0800 Subject: [PATCH] feat: add greptimedb standalone chart (#66) * feat: add greptimedb standalone chart * refactor: use statefulset deploy greptimedb * feat: add more values * chore: ready for review * chore: default disable monitoring * feat: add readme * refactor: delete prometheus port * refactor: greptimedb standalone storage configure * refactor: use greptimedb config default values --- .github/chart-test.yaml | 1 + charts/greptimedb-standalone/.helmignore | 23 +++ charts/greptimedb-standalone/Chart.yaml | 6 + charts/greptimedb-standalone/README.md | 20 +++ .../templates/_helpers.tpl | 62 +++++++ .../templates/podmonitor.yaml | 26 +++ .../templates/service.yaml | 31 ++++ .../templates/serviceaccount.yaml | 13 ++ .../templates/statefulset.yaml | 137 ++++++++++++++ charts/greptimedb-standalone/values.yaml | 170 ++++++++++++++++++ 10 files changed, 489 insertions(+) create mode 100644 charts/greptimedb-standalone/.helmignore create mode 100644 charts/greptimedb-standalone/Chart.yaml create mode 100644 charts/greptimedb-standalone/README.md create mode 100644 charts/greptimedb-standalone/templates/_helpers.tpl create mode 100644 charts/greptimedb-standalone/templates/podmonitor.yaml create mode 100644 charts/greptimedb-standalone/templates/service.yaml create mode 100644 charts/greptimedb-standalone/templates/serviceaccount.yaml create mode 100644 charts/greptimedb-standalone/templates/statefulset.yaml create mode 100644 charts/greptimedb-standalone/values.yaml diff --git a/.github/chart-test.yaml b/.github/chart-test.yaml index 2772345..87389c9 100644 --- a/.github/chart-test.yaml +++ b/.github/chart-test.yaml @@ -3,3 +3,4 @@ chart-dirs: charts: - charts/greptimedb-operator - charts/greptimedb + - charts/greptimedb-standalone diff --git a/charts/greptimedb-standalone/.helmignore b/charts/greptimedb-standalone/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/greptimedb-standalone/.helmignore @@ -0,0 +1,23 @@ +# 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 +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/greptimedb-standalone/Chart.yaml b/charts/greptimedb-standalone/Chart.yaml new file mode 100644 index 0000000..164c0d8 --- /dev/null +++ b/charts/greptimedb-standalone/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: greptimedb-standalone +description: A Helm chart for deploying standalone greptimedb. +type: application +version: 0.1.0-alpha.1 +appVersion: 0.4.0 diff --git a/charts/greptimedb-standalone/README.md b/charts/greptimedb-standalone/README.md new file mode 100644 index 0000000..fb34dbd --- /dev/null +++ b/charts/greptimedb-standalone/README.md @@ -0,0 +1,20 @@ +# Overview + +Helm chart for [GreptimeDB](https://github.com/GreptimeTeam/greptimedb) standalone mode. + +## How to install + +```console +# Add charts repo. +helm repo add greptime https://greptimeteam.github.io/helm-charts/ +helm repo update + +# Install greptimedb standalone in default namespace. +helm install greptimedb-standalone greptime/greptimedb-standalone -n default --devel +``` + +## How to uninstall + +```console +helm uninstall greptimedb-standalone -n default +``` diff --git a/charts/greptimedb-standalone/templates/_helpers.tpl b/charts/greptimedb-standalone/templates/_helpers.tpl new file mode 100644 index 0000000..f2fe3a7 --- /dev/null +++ b/charts/greptimedb-standalone/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "greptimedb-standalone.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 "greptimedb-standalone.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 "greptimedb-standalone.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "greptimedb-standalone.labels" -}} +helm.sh/chart: {{ include "greptimedb-standalone.chart" . }} +{{ include "greptimedb-standalone.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "greptimedb-standalone.selectorLabels" -}} +app.kubernetes.io/name: {{ include "greptimedb-standalone.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "greptimedb-standalone.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "greptimedb-standalone.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/greptimedb-standalone/templates/podmonitor.yaml b/charts/greptimedb-standalone/templates/podmonitor.yaml new file mode 100644 index 0000000..462c020 --- /dev/null +++ b/charts/greptimedb-standalone/templates/podmonitor.yaml @@ -0,0 +1,26 @@ +{{- if .Values.monitoring.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ include "greptimedb-standalone.fullname" . }} + namespace: {{ .Release.Namespace }} + {{- with .Values.monitoring.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.monitoring.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + podMetricsEndpoints: + - interval: {{ .Values.monitoring.interval }} + port: http + path: /metrics + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + {{- include "greptimedb-standalone.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/greptimedb-standalone/templates/service.yaml b/charts/greptimedb-standalone/templates/service.yaml new file mode 100644 index 0000000..f5e072b --- /dev/null +++ b/charts/greptimedb-standalone/templates/service.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "greptimedb-standalone.fullname" . }} + labels: + {{- include "greptimedb-standalone.labels" . | nindent 4 }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - name: http + port: {{ .Values.httpPort }} + targetPort: {{ .Values.httpPort }} + protocol: TCP + - name: grpc + port: {{ .Values.grpcPort }} + targetPort: {{ .Values.grpcPort }} + protocol: TCP + - name: mysql + port: {{ .Values.mysqlPort }} + targetPort: {{ .Values.mysqlPort }} + protocol: TCP + - name: postgres + port: {{ .Values.postgresPort }} + targetPort: {{ .Values.postgresPort }} + protocol: TCP + selector: + {{- include "greptimedb-standalone.selectorLabels" . | nindent 4 }} diff --git a/charts/greptimedb-standalone/templates/serviceaccount.yaml b/charts/greptimedb-standalone/templates/serviceaccount.yaml new file mode 100644 index 0000000..fb5abec --- /dev/null +++ b/charts/greptimedb-standalone/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "greptimedb-standalone.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "greptimedb-standalone.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/greptimedb-standalone/templates/statefulset.yaml b/charts/greptimedb-standalone/templates/statefulset.yaml new file mode 100644 index 0000000..e45ba20 --- /dev/null +++ b/charts/greptimedb-standalone/templates/statefulset.yaml @@ -0,0 +1,137 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "greptimedb-standalone.fullname" . }} + namespace: {{ $.Release.Namespace }} + labels: + {{- include "greptimedb-standalone.labels" . | nindent 4 }} + {{- if not (empty .Values.annotations) }} + annotations: + {{- with .Values.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} +spec: + replicas: 1 + updateStrategy: + rollingUpdate: + partition: 0 + serviceName: {{ include "greptimedb-standalone.fullname" . }} + {{- if and (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) (.Values.persistence.enableStatefulSetAutoDeletePVC) (.Values.persistence.enabled) }} + persistentVolumeClaimRetentionPolicy: + whenDeleted: Delete + whenScaled: Delete + {{- end }} + selector: + matchLabels: + {{- include "greptimedb-standalone.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "greptimedb-standalone.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "greptimedb-standalone.serviceAccountName" . }} + {{- if .Values.image.pullSecrets }} + imagePullSecrets: + {{- range .Values.image.pullSecrets }} + - name: {{ . }} + {{- end }} + {{- end }} + {{- if .Values.securityContext }} + securityContext: + {{- toYaml .Values.securityContext | nindent 8 }} + {{- end }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + containers: + - name: {{ include "greptimedb-standalone.fullname" . }} + image: {{ printf "%s/%s:%s" .Values.image.registry .Values.image.repository .Values.image.tag }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - greptime + - standalone + - start + {{- if .Values.command }} + {{- toYaml .Values.command | nindent 12 }} + {{- end }} + {{- if .Values.args }} + args: + {{- toYaml .Values.args | nindent 12 }} + {{- end }} + ports: + - containerPort: {{ .Values.httpPort }} + name: http + protocol: TCP + - containerPort: {{ .Values.grpcPort }} + name: grpc + protocol: TCP + - containerPort: {{ .Values.mysqlPort }} + name: mysql + protocol: TCP + - containerPort: {{ .Values.postgresPort }} + name: postgres + protocol: TCP + {{- if .Values.env }} + env: + {{- range $key, $val := .Values.env }} + - name: {{ $key }} + value: {{ $val | quote }} + {{- end }} + {{- end }} + {{- with .Values.envFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + - name: data + mountPath: /tmp/greptimedb + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.dnsConfig }} + dnsConfig: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.persistence.enabled }} + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: data + spec: + accessModes: + - ReadWriteOnce + {{- with .Values.persistence.storageClass }} + storageClassName: {{ if (eq "-" .) }}""{{ else }}{{ . }}{{ end }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} + {{- with .Values.persistence.selector }} + selector: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} diff --git a/charts/greptimedb-standalone/values.yaml b/charts/greptimedb-standalone/values.yaml new file mode 100644 index 0000000..deaac9a --- /dev/null +++ b/charts/greptimedb-standalone/values.yaml @@ -0,0 +1,170 @@ +image: + registry: docker.io + # The image repository + repository: greptime/greptimedb + # The image tag + tag: "v0.4.0" + # The image pull policy for the controller + pullPolicy: IfNotPresent + # The image pull secrets. + pullSecrets: [] + +# Overrides the chart's name +nameOverride: "" + +# Provide a name to substitute for the full names of resources +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +command: [] + +args: [] + +env: + GREPTIMEDB_STANDALONE__HTTP__ADDR: "0.0.0.0:4000" +# GREPTIMEDB_STANDALONE__HTTP__TIMEOUT: "120s" + +# GREPTIMEDB_STANDALONE__WAL__FILE_SIZE: "128MB" +# GREPTIMEDB_STANDALONE__WAL__PURGE_THRESHOLD: "2GB" +# GREPTIMEDB_DATANODE__WAL__DIR: "/tmp/greptimedb/wal" + +# # configure to use local storage. +# GREPTIMEDB_STANDALONE__STORAGE__TYPE: "File" +# GREPTIMEDB_STANDALONE__STORAGE__DATA_HOME: "/tmp/greptimedb" + +# # configure to use s3 storage. +# GREPTIMEDB_STANDALONE__STORAGE__TYPE: "S3" +# GREPTIMEDB_STANDALONE__STORAGE__BUCKET: "bucket-name" +# GREPTIMEDB_STANDALONE__STORAGE__ROOT: "/data" +# GREPTIMEDB_STANDALONE__STORAGE__REGION: "ap-southeast-1" +# GREPTIMEDB_STANDALONE__STORAGE__ACCESS_KEY_ID: "access_key_id" +# GREPTIMEDB_STANDALONE__STORAGE__SECRET_ACCESS_KEY: "secret_access_key" +# GREPTIMEDB_STANDALONE__STORAGE__CACHE__CACHE_PATH: "/tmp/greptimedb/s3cache" + +# GREPTIMEDB_STANDALONE__STORAGE__GLOBAL_TTL: "1d" +# GREPTIMEDB_STANDALONE__STORAGE__FLUSH__GLOBAL_WRITE_BUFFER_SIZE: "512MB" +# GREPTIMEDB_STANDALONE__STORAGE__FLUSH__REGION_WRITE_BUFFER_SIZE: "256MB" +# GREPTIMEDB_STANDALONE__STORAGE__FLUSH__AUTO_FLUSH_INTERVAL: "5m" +# GREPTIMEDB_STANDALONE__STORAGE__FLUSH__MAX_FLUSH_TASKS: "2" +# GREPTIMEDB_STANDALONE__STORAGE__COMPACTION__MAX_INFLIGHT_TASKS: "2" +# GREPTIMEDB_DATANODE__STORAGE__MANIFEST__CHECKPOINT_MARGIN: "100" +# GREPTIMEDB_DATANODE__STORAGE__MANIFEST__GC_DURATION: "5m" + + +envFrom: {} +# - secretRef: +# name: config + +# The pod annotations +podAnnotations: {} + +# The pod labels +podLabels: {} + +# The pod security context +podSecurityContext: {} +# runAsUser: 1000 +# runAsGroup: 3000 +# fsGroup: 2000 + +# The annotations +annotations: {} +# imageregistry: "https://hub.docker.com/" + +# The security context +securityContext: {} +# runAsUser: 1000 +# runAsGroup: 3000 +# fsGroup: 2000 + +# Resource requests and limits for the container +resources: {} +# limits: +# cpu: 800m +# memory: 1Gi +# requests: +# cpu: 200m +# memory: 512Mi + +# The node selector +nodeSelector: {} +# disktype: ssd + +# The tolerations +tolerations: {} +# - key: "key1" +# operator: "Equal" +# value: "value1" +# effect: "NoSchedule" + +# The affinity rules +affinity: {} +# nodeAffinity: +# requiredDuringSchedulingIgnoredDuringExecution: +# nodeSelectorTerms: +# - matchExpressions: +# - key: topology.kubernetes.io/zone +# operator: In +# values: +# - antarctica-east1 +# - antarctica-west1 +# preferredDuringSchedulingIgnoredDuringExecution: +# - weight: 1 +# preference: +# matchExpressions: +# - key: another-node-label-key +# operator: In +# values: +# - another-node-label-value + +# DNS config for pods +dnsConfig: {} +# nameservers: +# - 10.0.0.1 +# searches: +# - mydomain.local +# options: +# - name: ndots +# value: "2" + +# Grace period to allow the single binary to shutdown before it is killed +terminationGracePeriodSeconds: 30 + +persistence: + # Enable persistent disk + enabled: true + # Enable StatefulSetAutoDeletePVC feature + enableStatefulSetAutoDeletePVC: false + # Size of persistent disk + size: 10Gi + # Storage class name + storageClass: null + # Selector for persistent disk + selector: null + +monitoring: + enabled: false + # PodMonitor annotations + annotations: {} + # PodMonitor labels + labels: {} + # PodMonitor scrape interval + interval: 15s + +httpPort: 4000 +grpcPort: 4001 +mysqlPort: 4002 +postgresPort: 4003 + +service: + type: ClusterIP + # Annotations for Service + annotations: {}