From 899e6e8d233d6fd3841e2dc04fd2699b43229f5d Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Sat, 27 Aug 2022 14:34:55 -0500 Subject: [PATCH] Add helm package --- deploy/kubernetes/easyhaproxy.yml | 132 +++++++++++------- helm/easyhaproxy-ingress/.helmignore | 23 +++ helm/easyhaproxy-ingress/Chart.yaml | 24 ++++ .../templates/_helpers.tpl | 62 ++++++++ .../templates/clusterrole.yaml | 66 +++++++++ .../templates/clusterrolebinding.yaml | 20 +++ .../templates/deployment.yaml | 65 +++++++++ .../templates/serviceaccount.yaml | 12 ++ helm/easyhaproxy-ingress/values.yaml | 65 +++++++++ 9 files changed, 415 insertions(+), 54 deletions(-) create mode 100644 helm/easyhaproxy-ingress/.helmignore create mode 100644 helm/easyhaproxy-ingress/Chart.yaml create mode 100644 helm/easyhaproxy-ingress/templates/_helpers.tpl create mode 100644 helm/easyhaproxy-ingress/templates/clusterrole.yaml create mode 100644 helm/easyhaproxy-ingress/templates/clusterrolebinding.yaml create mode 100644 helm/easyhaproxy-ingress/templates/deployment.yaml create mode 100644 helm/easyhaproxy-ingress/templates/serviceaccount.yaml create mode 100644 helm/easyhaproxy-ingress/values.yaml diff --git a/deploy/kubernetes/easyhaproxy.yml b/deploy/kubernetes/easyhaproxy.yml index cec1d40..cedfdfb 100644 --- a/deploy/kubernetes/easyhaproxy.yml +++ b/deploy/kubernetes/easyhaproxy.yml @@ -1,21 +1,27 @@ --- -apiVersion: v1 -kind: Namespace -metadata: - name: easyhaproxy - ---- +# Source: easyhaproxy-ingress/templates/serviceaccount.yaml apiVersion: v1 kind: ServiceAccount metadata: - name: easyhaproxy-ingress - namespace: easyhaproxy - + name: manual-easyhaproxy-ingress + labels: + helm.sh/chart: easyhaproxy-ingress-0.1.0 + app.kubernetes.io/name: easyhaproxy-ingress + app.kubernetes.io/instance: manual + app.kubernetes.io/version: "test" + app.kubernetes.io/managed-by: Helm --- +# Source: easyhaproxy-ingress/templates/clusterrole.yaml kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: - name: easyhaproxy-ingress + name: manual-easyhaproxy-ingress + labels: + helm.sh/chart: easyhaproxy-ingress-0.1.0 + app.kubernetes.io/name: easyhaproxy-ingress + app.kubernetes.io/instance: manual + app.kubernetes.io/version: "test" + app.kubernetes.io/managed-by: Helm rules: - apiGroups: - "" @@ -69,36 +75,47 @@ rules: # - get # - list # - watch - --- +# Source: easyhaproxy-ingress/templates/clusterrolebinding.yaml kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: - name: easyhaproxy-ingress - namespace: easyhaproxy + name: manual-easyhaproxy-ingress + labels: + helm.sh/chart: easyhaproxy-ingress-0.1.0 + app.kubernetes.io/name: easyhaproxy-ingress + app.kubernetes.io/instance: manual + app.kubernetes.io/version: "test" + app.kubernetes.io/managed-by: Helm roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: easyhaproxy-ingress + name: manual-easyhaproxy-ingress subjects: - kind: ServiceAccount - name: easyhaproxy-ingress - namespace: easyhaproxy - + name: manual-easyhaproxy-ingress --- +# Source: easyhaproxy-ingress/templates/deployment.yaml apiVersion: apps/v1 kind: DaemonSet metadata: - name: easyhaproxy-ingress - namespace: easyhaproxy + name: manual-easyhaproxy-ingress + labels: + helm.sh/chart: easyhaproxy-ingress-0.1.0 + app.kubernetes.io/name: easyhaproxy-ingress + app.kubernetes.io/instance: manual + app.kubernetes.io/version: "test" + app.kubernetes.io/managed-by: Helm spec: selector: matchLabels: - app: easyhaproxy-ingress + app.kubernetes.io/name: easyhaproxy-ingress + app.kubernetes.io/instance: manual template: metadata: labels: - app: easyhaproxy-ingress + app.kubernetes.io/name: easyhaproxy-ingress + app.kubernetes.io/instance: manual spec: affinity: nodeAffinity: @@ -108,37 +125,44 @@ spec: - key: easyhaproxy/node operator: In values: - - master - serviceAccountName: easyhaproxy-ingress + - master + serviceAccountName: manual-easyhaproxy-ingress + securityContext: + {} containers: - - image: byjg/easy-haproxy:test - imagePullPolicy: Always - name: easyhaproxy-ingress - ports: - - name: http - containerPort: 80 - hostPort: 80 - - name: https - containerPort: 443 - hostPort: 443 - - name: stats - containerPort: 1936 - hostPort: 1936 - resources: - requests: - cpu: "100m" - memory: "128Mi" - - env: - - name: EASYHAPROXY_DISCOVER - value: kubernetes - - name: HAPROXY_USERNAME - value: admin - - name: HAPROXY_PASSWORD - value: password - - name: EASYHAPROXY_REFRESH_CONF - value: "10" - - name: HAPROXY_CUSTOMERRORS - value: "true" - - name: EASYHAPROXY_SSL_MODE - value: loose + - name: easyhaproxy-ingress + securityContext: + {} + image: "byjg/easy-haproxy:test" + imagePullPolicy: Always + ports: + - name: http + containerPort: 80 + hostPort: 80 + - name: https + containerPort: 443 + hostPort: 443 + - name: stats + containerPort: 1936 + hostPort: 1936 + resources: + {} + env: + - name: EASYHAPROXY_DISCOVER + value: kubernetes + - name: HAPROXY_USERNAME + value: admin + - name: HAPROXY_PASSWORD + value: password + - name: EASYHAPROXY_REFRESH_CONF + value: "10" + - name: HAPROXY_CUSTOMERRORS + value: "true" + - name: EASYHAPROXY_SSL_MODE + value: loose + - name: EASYHAPROXY_LOG_LEVEL + value: DEBUG + - name: HAPROXY_LOG_LEVEL + value: DEBUG + - name: CERTBOT_LOG_LEVEL + value: DEBUG \ No newline at end of file diff --git a/helm/easyhaproxy-ingress/.helmignore b/helm/easyhaproxy-ingress/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/easyhaproxy-ingress/.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/easyhaproxy-ingress/Chart.yaml b/helm/easyhaproxy-ingress/Chart.yaml new file mode 100644 index 0000000..fbfb95c --- /dev/null +++ b/helm/easyhaproxy-ingress/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: easyhaproxy-ingress +description: "EasyHAProxy - A service discovery backed on HAProxy" + +# 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: "test" diff --git a/helm/easyhaproxy-ingress/templates/_helpers.tpl b/helm/easyhaproxy-ingress/templates/_helpers.tpl new file mode 100644 index 0000000..3e9c496 --- /dev/null +++ b/helm/easyhaproxy-ingress/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "easyhaproxy-ingress.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 "easyhaproxy-ingress.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 "easyhaproxy-ingress.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "easyhaproxy-ingress.labels" -}} +helm.sh/chart: {{ include "easyhaproxy-ingress.chart" . }} +{{ include "easyhaproxy-ingress.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "easyhaproxy-ingress.selectorLabels" -}} +app.kubernetes.io/name: {{ include "easyhaproxy-ingress.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "easyhaproxy-ingress.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "easyhaproxy-ingress.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/helm/easyhaproxy-ingress/templates/clusterrole.yaml b/helm/easyhaproxy-ingress/templates/clusterrole.yaml new file mode 100644 index 0000000..05a42d4 --- /dev/null +++ b/helm/easyhaproxy-ingress/templates/clusterrole.yaml @@ -0,0 +1,66 @@ +{{- if .Values.serviceAccount.create -}} +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ include "easyhaproxy-ingress.fullname" . }} + labels: + {{- include "easyhaproxy-ingress.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +rules: +- apiGroups: + - "" + resources: + # - configmaps + # - endpoints + # - nodes + - pods + - services + - namespaces + # - events + - serviceaccounts + verbs: + - get + - list + - watch +- apiGroups: + - "extensions" + - "networking.k8s.io" + resources: + - ingresses + # - ingresses/status + # - ingressclasses + verbs: + - get + - list + - watch +# - apiGroups: +# - "extensions" +# - "networking.k8s.io" +# resources: +# - ingresses/status +# verbs: +# - update +- apiGroups: + - "" + resources: + - secrets + verbs: + - get + - list + # - watch + # - create + # - patch + # - update +# - apiGroups: +# - "discovery.k8s.io" +# resources: +# - endpointslices +# verbs: +# - get +# - list +# - watch +{{- end }} \ No newline at end of file diff --git a/helm/easyhaproxy-ingress/templates/clusterrolebinding.yaml b/helm/easyhaproxy-ingress/templates/clusterrolebinding.yaml new file mode 100644 index 0000000..9678a9b --- /dev/null +++ b/helm/easyhaproxy-ingress/templates/clusterrolebinding.yaml @@ -0,0 +1,20 @@ +{{- if .Values.serviceAccount.create -}} +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ include "easyhaproxy-ingress.fullname" . }} + labels: + {{- include "easyhaproxy-ingress.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "easyhaproxy-ingress.fullname" . }} +subjects: +- kind: ServiceAccount + name: {{ include "easyhaproxy-ingress.serviceAccountName" . }} +{{- end }} diff --git a/helm/easyhaproxy-ingress/templates/deployment.yaml b/helm/easyhaproxy-ingress/templates/deployment.yaml new file mode 100644 index 0000000..9df1e67 --- /dev/null +++ b/helm/easyhaproxy-ingress/templates/deployment.yaml @@ -0,0 +1,65 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ include "easyhaproxy-ingress.fullname" . }} + labels: + {{- include "easyhaproxy-ingress.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "easyhaproxy-ingress.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "easyhaproxy-ingress.selectorLabels" . | nindent 8 }} + spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: {{ .Values.masterNode.label }} + operator: In + values: + {{- toYaml .Values.masterNode.values | nindent 18 }} + serviceAccountName: {{ include "easyhaproxy-ingress.serviceAccountName" . }} + 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 }} + ports: + - name: http + containerPort: 80 + hostPort: 80 + - name: https + containerPort: 443 + hostPort: 443 + - name: stats + containerPort: 1936 + hostPort: 1936 + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + - name: EASYHAPROXY_DISCOVER + value: kubernetes + - name: HAPROXY_USERNAME + value: {{ .Values.easyhaproxy.stats.username }} + - name: HAPROXY_PASSWORD + value: {{ .Values.easyhaproxy.stats.password }} + - name: EASYHAPROXY_REFRESH_CONF + value: {{ .Values.easyhaproxy.refresh | quote }} + - name: HAPROXY_CUSTOMERRORS + value: {{ .Values.easyhaproxy.customErrors | quote}} + - name: EASYHAPROXY_SSL_MODE + value: {{ .Values.easyhaproxy.sslMode }} + - name: EASYHAPROXY_LOG_LEVEL + value: {{ .Values.easyhaproxy.logLevel.easyhaproxy }} + - name: HAPROXY_LOG_LEVEL + value: {{ .Values.easyhaproxy.logLevel.haproxy }} + - name: CERTBOT_LOG_LEVEL + value: {{ .Values.easyhaproxy.logLevel.certbot }} diff --git a/helm/easyhaproxy-ingress/templates/serviceaccount.yaml b/helm/easyhaproxy-ingress/templates/serviceaccount.yaml new file mode 100644 index 0000000..fd85feb --- /dev/null +++ b/helm/easyhaproxy-ingress/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "easyhaproxy-ingress.serviceAccountName" . }} + labels: + {{- include "easyhaproxy-ingress.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/helm/easyhaproxy-ingress/values.yaml b/helm/easyhaproxy-ingress/values.yaml new file mode 100644 index 0000000..213937f --- /dev/null +++ b/helm/easyhaproxy-ingress/values.yaml @@ -0,0 +1,65 @@ +# Default values for easyhaproxy-ingress. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: byjg/easy-haproxy + pullPolicy: Always # IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +resources: {} +# requests: +# cpu: "100m" +# memory: "128Mi" +# limits: +# cpu: 100m +# memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +easyhaproxy: + stats: + username: admin + password: password + refresh: "10" + customErrors: "true" + sslMode: loose + logLevel: + certbot: DEBUG + easyhaproxy: DEBUG + haproxy: DEBUG + +# Make sure to create this +masterNode: + label: easyhaproxy/node + values: + - master