From a4e5db0e289efed091354d2424d1939c31dcf127 Mon Sep 17 00:00:00 2001 From: Oleksii Dovzhanytsia Date: Sun, 17 Oct 2021 23:35:59 +0300 Subject: [PATCH] Add Helm Chart --- Helm/.helmignore | 23 +++++++ Helm/Chart.yaml | 6 ++ Helm/templates/NOTES.txt | 22 +++++++ Helm/templates/_helpers.tpl | 62 ++++++++++++++++++ Helm/templates/config.yaml | 66 +++++++++++++++++++ Helm/templates/deployment.yaml | 73 +++++++++++++++++++++ Helm/templates/ingress.yaml | 42 ++++++++++++ Helm/templates/service.yaml | 15 +++++ Helm/templates/tests/test-connection.yaml | 15 +++++ Helm/values.yaml | 79 +++++++++++++++++++++++ Helm/valuesTest.yaml | 71 ++++++++++++++++++++ 11 files changed, 474 insertions(+) create mode 100644 Helm/.helmignore create mode 100644 Helm/Chart.yaml create mode 100644 Helm/templates/NOTES.txt create mode 100644 Helm/templates/_helpers.tpl create mode 100644 Helm/templates/config.yaml create mode 100644 Helm/templates/deployment.yaml create mode 100644 Helm/templates/ingress.yaml create mode 100644 Helm/templates/service.yaml create mode 100644 Helm/templates/tests/test-connection.yaml create mode 100644 Helm/values.yaml create mode 100644 Helm/valuesTest.yaml diff --git a/Helm/.helmignore b/Helm/.helmignore new file mode 100644 index 0000000000..0e8a0eb36f --- /dev/null +++ b/Helm/.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/Helm/Chart.yaml b/Helm/Chart.yaml new file mode 100644 index 0000000000..fc5994d4b1 --- /dev/null +++ b/Helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: easyappointments +description: A Helm chart for Kubernetes +type: application +version: 0.0.1 +appVersion: 0.0.1 diff --git a/Helm/templates/NOTES.txt b/Helm/templates/NOTES.txt new file mode 100644 index 0000000000..42b63ae323 --- /dev/null +++ b/Helm/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "easyappointments.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 --namespace {{ .Release.Namespace }} svc -w {{ include "easyappointments.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "easyappointments.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + 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 "easyappointments.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/Helm/templates/_helpers.tpl b/Helm/templates/_helpers.tpl new file mode 100644 index 0000000000..ccbea1a70f --- /dev/null +++ b/Helm/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "easyappointments.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 "easyappointments.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 "easyappointments.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "easyappointments.labels" -}} +helm.sh/chart: {{ include "easyappointments.chart" . }} +{{ include "easyappointments.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "easyappointments.selectorLabels" -}} +app.kubernetes.io/name: {{ include "easyappointments.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "easyappointments.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "easyappointments.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/Helm/templates/config.yaml b/Helm/templates/config.yaml new file mode 100644 index 0000000000..b46834717f --- /dev/null +++ b/Helm/templates/config.yaml @@ -0,0 +1,66 @@ +kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ include "easyappointments.fullname" . }}-config + labels: + {{- include "easyappointments.labels" . | nindent 4 }} +data: + config.php: | + + * @copyright Copyright (c) 2013 - 2016, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.0.0 + * ---------------------------------------------------------------------------- */ + + /** + * Easy!Appointments Configuration File + * + * Set your installation BASE_URL * without the trailing slash * and the database + * credentials in order to connect to the database. You can enable the DEBUG_MODE + * while developing the application. + * + * Set the default language by changing the LANGUAGE constant. For a full list of + * available languages look at the /application/config/config.php file. + * + * IMPORTANT: + * If you are updating from version 1.0 you will have to create a new "config.php" + * file because the old "configuration.php" is not used anymore. + */ + class Config { + + // ------------------------------------------------------------------------ + // GENERAL SETTINGS + // ------------------------------------------------------------------------ + + const BASE_URL = '{{ .Values.app.envVars.BASE_URL }}'; + const LANGUAGE = '{{ .Values.app.envVars.LANGUAGE }}'; + const DEBUG_MODE = {{ .Values.app.envVars.PHP_DEBUG_MODE }}; + + // ------------------------------------------------------------------------ + // DATABASE SETTINGS + // ------------------------------------------------------------------------ + + const DB_HOST = '{{ .Values.dataBase.databaseHost }}'; + const DB_NAME = '{{ .Values.dataBase.dbName }}'; + const DB_USERNAME = '{{ .Values.dataBase.dbUser }}'; + const DB_PASSWORD = '{{ .Values.dataBase.dbUserPassword }}'; + + // ------------------------------------------------------------------------ + // GOOGLE CALENDAR SYNC + // ------------------------------------------------------------------------ + + const GOOGLE_SYNC_FEATURE = {{ .Values.app.envVars.GOOGLE_SYNC_FEATURE }}; // Enter TRUE or FALSE + const GOOGLE_PRODUCT_NAME = '{{ .Values.app.envVars.GOOGLE_PRODUCT_NAME }}'; + const GOOGLE_CLIENT_ID = '{{ .Values.app.envVars.GOOGLE_CLIENT_ID }}'; + const GOOGLE_CLIENT_SECRET = '{{ .Values.app.envVars.GOOGLE_CLIENT_SECRET }}'; + const GOOGLE_API_KEY = '{{ .Values.app.envVars.GOOGLE_API_KEY }}'; + } + + /* End of file config.php */ + /* Location: ./config.php */ \ No newline at end of file diff --git a/Helm/templates/deployment.yaml b/Helm/templates/deployment.yaml new file mode 100644 index 0000000000..ed5caa7b0c --- /dev/null +++ b/Helm/templates/deployment.yaml @@ -0,0 +1,73 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "easyappointments.fullname" . }} + labels: + {{- include "easyappointments.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "easyappointments.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "easyappointments.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + - name: config-php + mountPath: /app/www/config.php + subPath: config.php + ports: + - name: http + containerPort: {{ .Values.app.Port }} + protocol: TCP + # livenessProbe: + # httpGet: + # path: / + # port: http + # readinessProbe: + # httpGet: + # path: / + # port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: config-php + configMap: + name: {{ include "easyappointments.fullname" . }}-config + items: + - key: config.php + path: config.php + + + {{- 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 0000000000..939bdc41e9 --- /dev/null +++ b/Helm/templates/ingress.yaml @@ -0,0 +1,42 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "easyappointments.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "easyappointments.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 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: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} + diff --git a/Helm/templates/service.yaml b/Helm/templates/service.yaml new file mode 100644 index 0000000000..ef1d9ed731 --- /dev/null +++ b/Helm/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "easyappointments.fullname" . }} + labels: + {{- include "easyappointments.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "easyappointments.selectorLabels" . | nindent 4 }} diff --git a/Helm/templates/tests/test-connection.yaml b/Helm/templates/tests/test-connection.yaml new file mode 100644 index 0000000000..2afbe4eb42 --- /dev/null +++ b/Helm/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "easyappointments.fullname" . }}-test-connection" + labels: + {{- include "easyappointments.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "easyappointments.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/Helm/values.yaml b/Helm/values.yaml new file mode 100644 index 0000000000..5c00a04864 --- /dev/null +++ b/Helm/values.yaml @@ -0,0 +1,79 @@ +# Default values for easyappointments. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +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: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/Helm/valuesTest.yaml b/Helm/valuesTest.yaml new file mode 100644 index 0000000000..eb6c7f951f --- /dev/null +++ b/Helm/valuesTest.yaml @@ -0,0 +1,71 @@ +nameOverride: "easyappointments" +fullnameOverride: "easyappointments" + +replicaCount: 1 + +image: + repository: jamrizzi/easyappointments + pullPolicy: IfNotPresent + tag: latest +imagePullSecrets: [] + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 +app: + Port: 8888 + envVars: + BASE_URL: http://localhost:8888 + LANGUAGE: russian + PHP_DEBUG_MODE: true + GOOGLE_SYNC_FEATURE: false + GOOGLE_PRODUCT_NAME: '' + GOOGLE_CLIENT_ID: '' + GOOGLE_CLIENT_SECRET: '' + GOOGLE_API_KEY: '' + +dataBase: + databaseHost: my-release-mysql + dbUser: root + dbUserPassword: 11vy2vJrko + dbName: easyappointmentsDB + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {}