From 83a7a778a4eb9fd1ea10e83e4622d10bff558afe Mon Sep 17 00:00:00 2001 From: Benoit Werquin Date: Fri, 26 Feb 2021 17:30:44 +0100 Subject: [PATCH 1/4] Add queen --- charts/queen/Chart.yaml | 24 +++++++ charts/queen/templates/_helpers.tpl | 53 +++++++++++++++ charts/queen/templates/deployment.yaml | 68 +++++++++++++++++++ charts/queen/templates/hpa.yaml | 28 ++++++++ charts/queen/templates/ingress.yaml | 41 ++++++++++++ charts/queen/templates/service.yaml | 15 +++++ charts/queen/values.yaml | 90 ++++++++++++++++++++++++++ 7 files changed, 319 insertions(+) create mode 100644 charts/queen/Chart.yaml create mode 100644 charts/queen/templates/_helpers.tpl create mode 100644 charts/queen/templates/deployment.yaml create mode 100644 charts/queen/templates/hpa.yaml create mode 100644 charts/queen/templates/ingress.yaml create mode 100644 charts/queen/templates/service.yaml create mode 100644 charts/queen/values.yaml diff --git a/charts/queen/Chart.yaml b/charts/queen/Chart.yaml new file mode 100644 index 0000000..66e2f09 --- /dev/null +++ b/charts/queen/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: queen +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.4.0" diff --git a/charts/queen/templates/_helpers.tpl b/charts/queen/templates/_helpers.tpl new file mode 100644 index 0000000..2490eae --- /dev/null +++ b/charts/queen/templates/_helpers.tpl @@ -0,0 +1,53 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "queen.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 "queen.fullname" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "queen.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "queen.labels" -}} +helm.sh/chart: {{ include "queen.chart" . }} +{{ include "queen.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "queen.selectorLabels" -}} +app.kubernetes.io/name: {{ include "queen.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "queen.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "queen.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/queen/templates/deployment.yaml b/charts/queen/templates/deployment.yaml new file mode 100644 index 0000000..e4a1ca6 --- /dev/null +++ b/charts/queen/templates/deployment.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "queen.fullname" . }} + labels: + {{- include "queen.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "queen.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "queen.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "queen.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.ui.image.name }}:{{ .Values.ui.image.version }}" + imagePullPolicy: {{ .Values.ui.image.pullPolicy }} + env: + {{- range .Values.ingress.hosts }} + - name: QUEEN_URL + value: "https://{{ .host }}" + {{- end }} + - name: QUEEN_API_URL + value: "https://{{ .Values.api.hostname }}" + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- 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/charts/queen/templates/hpa.yaml b/charts/queen/templates/hpa.yaml new file mode 100644 index 0000000..1917355 --- /dev/null +++ b/charts/queen/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "queen.fullname" . }} + labels: + {{- include "queen.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "queen.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/queen/templates/ingress.yaml b/charts/queen/templates/ingress.yaml new file mode 100644 index 0000000..e17b8de --- /dev/null +++ b/charts/queen/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "queen.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 "queen.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/charts/queen/templates/service.yaml b/charts/queen/templates/service.yaml new file mode 100644 index 0000000..51fef47 --- /dev/null +++ b/charts/queen/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "queen.fullname" . }} + labels: + {{- include "queen.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "queen.selectorLabels" . | nindent 4 }} diff --git a/charts/queen/values.yaml b/charts/queen/values.yaml new file mode 100644 index 0000000..854e373 --- /dev/null +++ b/charts/queen/values.yaml @@ -0,0 +1,90 @@ +# Default values for queen. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +ui: + name: ui + image: + name: inseefr/queen + version: latest + pullPolicy: Always + +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: false + # 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: true + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +api: + hostname: chart-example-bo.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: {} From 62ea4dfcbe010e551a5f1b5d6984e0035eeb20f4 Mon Sep 17 00:00:00 2001 From: Benoit Werquin Date: Fri, 26 Feb 2021 21:28:05 +0100 Subject: [PATCH 2/4] fix indent --- charts/queen/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/queen/values.yaml b/charts/queen/values.yaml index 854e373..ed17ffb 100644 --- a/charts/queen/values.yaml +++ b/charts/queen/values.yaml @@ -53,7 +53,7 @@ ingress: # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: - - host: chart-example.local + - host: chart-example.local paths: - path: / tls: [] From 02532907735975459f1de0441bdec3ea75223893 Mon Sep 17 00:00:00 2001 From: Benoit Werquin Date: Fri, 26 Feb 2021 21:43:16 +0100 Subject: [PATCH 3/4] remove unused image nginx config --- charts/queen/values.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/charts/queen/values.yaml b/charts/queen/values.yaml index ed17ffb..efe6403 100644 --- a/charts/queen/values.yaml +++ b/charts/queen/values.yaml @@ -11,11 +11,6 @@ ui: version: latest pullPolicy: Always -image: - repository: nginx - pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "" imagePullSecrets: [] nameOverride: "" From 88845a8524241f7d2273a4bf4d5259878c81fbc8 Mon Sep 17 00:00:00 2001 From: Benoit Werquin Date: Sat, 27 Feb 2021 21:35:30 +0100 Subject: [PATCH 4/4] get back to init fullname function --- charts/queen/templates/_helpers.tpl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/charts/queen/templates/_helpers.tpl b/charts/queen/templates/_helpers.tpl index 2490eae..14787d4 100644 --- a/charts/queen/templates/_helpers.tpl +++ b/charts/queen/templates/_helpers.tpl @@ -11,7 +11,16 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this If release name contains chart name it will be used as a full name. */}} {{- define "queen.fullname" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- 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 }} {{/*