From 1d771a2bea66c3c564125280cccbb859bf77443d Mon Sep 17 00:00:00 2001 From: Dmitry Dunaev Date: Thu, 1 Jul 2021 13:28:29 +0300 Subject: [PATCH] [WIFI-2695] Add: helm chart --- .dockerignore | 1 + helm/.gitignore | 1 + helm/.helmignore | 22 ++++++++ helm/Chart.yaml | 5 ++ helm/README.md | 62 ++++++++++++++++++++++ helm/templates/_helpers.tpl | 32 ++++++++++++ helm/templates/deployment.yaml | 84 ++++++++++++++++++++++++++++++ helm/templates/ingress.yaml | 47 +++++++++++++++++ helm/templates/secret-regcred.yaml | 21 ++++++++ helm/templates/service.yaml | 48 +++++++++++++++++ helm/values.yaml | 75 ++++++++++++++++++++++++++ 11 files changed, 398 insertions(+) create mode 100644 helm/.gitignore create mode 100644 helm/.helmignore create mode 100644 helm/Chart.yaml create mode 100644 helm/README.md create mode 100644 helm/templates/_helpers.tpl create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/ingress.yaml create mode 100644 helm/templates/secret-regcred.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/values.yaml diff --git a/.dockerignore b/.dockerignore index a71a153..eed91c0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -25,3 +25,4 @@ yarn-error.log* .git .github Dockerfile +helm diff --git a/helm/.gitignore b/helm/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/helm/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/helm/.helmignore b/helm/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/helm/.helmignore @@ -0,0 +1,22 @@ +# 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 +.vscode/ diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..75159a3 --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: ucentralgwui +version: 0.1.0 diff --git a/helm/README.md b/helm/README.md new file mode 100644 index 0000000..e1f5869 --- /dev/null +++ b/helm/README.md @@ -0,0 +1,62 @@ +# ucentralgwui + +> Application description placeholder + +## TL;DR; + +```bash +$ helm install . +``` + +## Introduction + +This chart bootstraps an ucentralgwui on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```bash +$ helm install --name my-release stable/ipfs +``` + +The command deploys ucentralgwui on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```bash +$ helm delete --purge my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following table lists the configurable parameters of the Memcached chart and their default values. + +| Parameter | Description | Default | +|-----------|-------------|---------| +||| + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```bash +$ helm install --name my-release \ + --set replicaCount=1 \ + . +``` + +The above command sets that only 1 instance of your app should be running + +Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example, + +```bash +$ helm install --name my-release -f values.yaml . +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) as a base for customization. + diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl new file mode 100644 index 0000000..55e1937 --- /dev/null +++ b/helm/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "ucentralgwui.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 "ucentralgwui.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 "ucentralgwui.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..93fa78f --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,84 @@ +{{- $root := . -}} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "ucentralgwui.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "ucentralgwui.name" . }} + helm.sh/chart: {{ include "ucentralgwui.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "ucentralgwui.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + {{- with .Values.services.ucentralgwui.labels }} + {{- toYaml . | nindent 6 }} + {{- end }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "ucentralgwui.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + {{- with .Values.services.ucentralgwui.labels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + + containers: + + - name: ucentralgwui + image: "{{ .Values.images.ucentralgwui.repository }}:{{ .Values.images.ucentralgwui.tag }}" + imagePullPolicy: {{ .Values.images.ucentralgwui.pullPolicy }} + + env: + {{- range $key, $value := .Values.public_env_variables }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + + ports: + {{- range $key, $value := .Values.services.ucentralgwui.ports }} + - name: {{ $key }} + containerPort: {{ $value.targetPort }} + protocol: {{ $value.protocol }} + {{- end }} + + {{- if .Values.checks.ucentralgwui.liveness }} + livenessProbe: + {{- toYaml .Values.checks.ucentralgwui.liveness | nindent 12 }} + {{- end }} + {{- if .Values.checks.ucentralgwui.readiness }} + readinessProbe: + {{- toYaml .Values.checks.ucentralgwui.readiness | nindent 12 }} + {{- end }} + + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + + imagePullSecrets: + {{- range $image, $imageValue := .Values.images }} + {{- if $imageValue.regcred }} + - name: {{ include "ucentralgwui.fullname" $root }}-{{ $image }}-regcred + {{- end }} + {{- end }} + + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/helm/templates/ingress.yaml b/helm/templates/ingress.yaml new file mode 100644 index 0000000..f2d2fcc --- /dev/null +++ b/helm/templates/ingress.yaml @@ -0,0 +1,47 @@ +{{- $root := . -}} +{{- range $ingress, $ingressValue := .Values.ingresses }} +{{- if $ingressValue.enabled }} +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ include "ucentralgwui.fullname" $root }}-{{ $ingress }} + labels: + app.kubernetes.io/name: {{ include "ucentralgwui.name" $root }} + helm.sh/chart: {{ include "ucentralgwui.chart" $root }} + app.kubernetes.io/instance: {{ $root.Release.Name }} + app.kubernetes.io/managed-by: {{ $root.Release.Service }} + {{- with $ingressValue.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + +spec: + +{{- if $ingressValue.tls }} + tls: + {{- range $ingressValue.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ tpl .secretName $root }} + {{- end }} +{{- end }} + + rules: + {{- range $ingressValue.hosts }} + - host: {{ . | quote }} + http: + paths: + {{- range $ingressValue.paths }} + - path: {{ .path }} + backend: + serviceName: {{ include "ucentralgwui.fullname" $root }}-{{ .serviceName }} + servicePort: {{ .servicePort }} + {{- end }} + {{- end }} + +{{- end }} + +{{- end }} diff --git a/helm/templates/secret-regcred.yaml b/helm/templates/secret-regcred.yaml new file mode 100644 index 0000000..3360d94 --- /dev/null +++ b/helm/templates/secret-regcred.yaml @@ -0,0 +1,21 @@ +{{- define "imagePullSecret" }} +{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .registry (printf "%s:%s" .username .password | b64enc) | b64enc }} +{{- end }} +{{- $root := . -}} +{{- range $image, $imageValue := .Values.images }} +{{- if $imageValue.regcred }} +--- +apiVersion: v1 +kind: Secret +type: kubernetes.io/dockerconfigjson +metadata: + labels: + app.kuberentes.io/name: {{ include "ucentralgwui.name" $root }} + helm.sh/chart: {{ include "ucentralgwui.chart" $root }} + app.kubernetes.io/instance: {{ $root.Release.Name }} + app.kubernetes.io/managed-by: {{ $root.Release.Service }} + name: {{ include "ucentralgwui.fullname" $root }}-{{ $image }}-regcred +data: + .dockerconfigjson: {{ template "imagePullSecret" $imageValue.regcred }} +{{- end }} +{{- end }} diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 0000000..264e610 --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,48 @@ +{{- $root := . -}} +{{- range $service, $serviceValue := .Values.services }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ include "ucentralgwui.fullname" $root }}-{{ $service }} + {{- with $serviceValue.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + app.kubernetes.io/name: {{ include "ucentralgwui.name" $root }} + helm.sh/chart: {{ include "ucentralgwui.chart" $root }} + app.kubernetes.io/instance: {{ $root.Release.Name }} + app.kubernetes.io/managed-by: {{ $root.Release.Service }} + + {{- with $serviceValue.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + + {{- if $serviceValue.serviceMonitor }} + + {{- range $selector, $selectorValue := $serviceValue.serviceMonitor.serviceSelector }} + {{ $selector }}: {{ tpl $selectorValue $root }} + {{- end }} + {{- end }} +spec: + type: {{ $serviceValue.type }} + ports: + + {{- range $service_service, $service_value := $serviceValue.ports }} + - name: {{ $service_service }} + targetPort: {{ $service_value.targetPort }} + protocol: {{ $service_value.protocol }} + port: {{ $service_value.servicePort }} + {{- if and (eq "NodePort" $serviceValue.type) $service_value.nodePort }} + nodePort: {{ $service_value.nodePort }} + {{- end }} + {{- end }} + selector: + app.kubernetes.io/name: {{ include "ucentralgwui.name" $root }} + app.kubernetes.io/instance: {{ $root.Release.Name }} + {{- with $serviceValue.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + +{{- end }} diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..9eb9f0a --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,75 @@ +# System +replicaCount: 1 + +nameOverride: "" +fullnameOverride: "" + +images: + ucentralgwui: + repository: tip-tip-wlan-cloud-ucentral.jfrog.io/ucentralgw-ui + tag: main + pullPolicy: Always + +services: + ucentralgwui: + type: ClusterIP + ports: + http: + servicePort: 80 + targetPort: 80 + protocol: TCP + +checks: + ucentralgwui: + liveness: + httpGet: + path: / + port: http + readiness: + httpGet: + path: / + port: http + +ingresses: + default: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + # tls: + # - secretName: '{{ include "ucentralgwui.fullname" . }}-default-tls' # template may be used + # cert: | + # CERT_HERE_IN_PEM + # key: | + # KEY_HERE_IN_PEM + # hosts: + # - chart-example.local + hosts: + - chart-example.local + paths: + - path: / + serviceName: ucentralgwui + servicePort: http + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # requests: + # cpu: 100m + # memory: 128Mi + # limits: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# Application +public_env_variables: + DEFAULT_GATEWAY_URL: https://ucentral.dpaas.arilia.com:16001 + ALLOW_GATEWAY_CHANGE: false