diff --git a/charts/nodejs/.helmignore b/charts/nodejs/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/nodejs/.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/nodejs/Chart.yaml b/charts/nodejs/Chart.yaml new file mode 100644 index 0000000..93732db --- /dev/null +++ b/charts/nodejs/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: nodejs +description: A Helm chart for Node.js applications on 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.0.1" diff --git a/charts/nodejs/README.md b/charts/nodejs/README.md new file mode 100644 index 0000000..f04e940 --- /dev/null +++ b/charts/nodejs/README.md @@ -0,0 +1,69 @@ +# nodejs + +![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.16.0](https://img.shields.io/badge/AppVersion-1.16.0-informational?style=flat-square) + +A Helm chart for Kubernetes Node.js application + +## Values + +### Networking Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| ingress | object | `{"annotations":{},"className":"","enabled":false,"hosts":[{"host":"chart-example.local","paths":[{"path":"/","pathType":"ImplementationSpecific"}]}],"tls":[]}` | Ingress settings | +| service | object | `{"port":80,"type":"ClusterIP"}` | Service settings | + +### Node.js Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| nodejs | object | A complex object. Please check values below | Node.js Specific Configurations | +| nodejs.env.envFromSecretsManager.enabled | Enable environment variables from AWS Secrets Manager | bool | `false` | +| nodejs.env.envFromSecretsManager.secretPath | AWS Secrets Manager secret path | string | `""` | +| nodejs.env.variables | Environment variables as key-value pairs | object | `{}` | +| nodejs.image.pullPolicy | Image pull policy | string | `"IfNotPresent"` | +| nodejs.image.repository | Node.js image repository | string | `"nodejs"` | +| nodejs.image.tag | Overrides the image tag whose default is the chart appVersion | string | `""` | +| nodejs.podSecurityContext | Pod security context | object | `{}` | +| nodejs.port | Node.js application port | string | `"3000"` | +| nodejs.resources | Resource limits and requests | object | `{}` | +| nodejs.securityContext | Security context for Node.js container | object | `{}` | +| nodejs.volumeMounts | list | `[]` | Node.js container additional volumes mounts | +| nodejs.volumes | list | `[]` | Node.js container additional volumes | + +### NginX Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| nginx | object | A complex object. Please check values below | NginX Specific Configurations | +| nginx.image | object | `{"pullPolicy":"IfNotPresent","repository":"nginx","tag":""}` | NginX image settings | +| nginx.image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion | +| nginx.resources | object | `{}` | NginX container resources | +| nginx.securityContext | object | `{}` | NginX container security context | +| nginx.volumeMounts | list | `[]` | NginX container additional volumes mounts | +| nginx.volumes | list | `[]` | NginX container additional volumes | + +### Other Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | Affinity settings | +| autoscaling | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | Autoscaling settings | +| fullnameOverride | string | `""` | Overrides full release name | +| imagePullSecrets | list | `[]` | Secret that used to store docker registry credentials | +| ingress.enabled | bool | `false` | Enables ingress when true | +| nameOverride | string | `""` | Overrides release name | +| nodeSelector | object | `{}` | Node selector settings | +| podAnnotations | object | `{}` | Annotations to add to the pod | +| podLabels | object | `{}` | Labels to add to the pod | +| podSecurityContext | object | `{}` | Security context of the pod | +| replicaCount | int | `1` | Number of replicas to sping up | +| serviceAccount | object | `{"annotations":{},"automount":true,"create":true,"name":""}` | Service Account | +| serviceAccount.annotations | object | `{}` | Annotations to add to the service account | +| serviceAccount.automount | bool | `true` | Automatically mount a ServiceAccount's API credentials? | +| serviceAccount.create | bool | `true` | Specifies whether a service account should be created | +| serviceAccount.name | string | `""` | The name of the service account to use. | +| tolerations | list | `[]` | Tolerations settings | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2) diff --git a/charts/nodejs/templates/NOTES.txt b/charts/nodejs/templates/NOTES.txt new file mode 100644 index 0000000..8239124 --- /dev/null +++ b/charts/nodejs/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 "nodejs.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 its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "nodejs.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "nodejs.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 "nodejs.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/charts/nodejs/templates/_helpers.tpl b/charts/nodejs/templates/_helpers.tpl new file mode 100644 index 0000000..9d05833 --- /dev/null +++ b/charts/nodejs/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "nodejs.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 "nodejs.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 "nodejs.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "nodejs.labels" -}} +helm.sh/chart: {{ include "nodejs.chart" . }} +{{ include "nodejs.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "nodejs.selectorLabels" -}} +app.kubernetes.io/name: {{ include "nodejs.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "nodejs.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "nodejs.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/nodejs/templates/configmaps.yaml b/charts/nodejs/templates/configmaps.yaml new file mode 100644 index 0000000..dd11a55 --- /dev/null +++ b/charts/nodejs/templates/configmaps.yaml @@ -0,0 +1,115 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "nodejs.fullname" . }}-nginx-conf +data: + nginx.conf: | + user nginx; + worker_processes auto; + + error_log /var/log/nginx/error.log notice; + pid /var/run/nginx.pid; + + + events { + worker_connections 1024; + } + + http { + ## + # Basic Settings + ## + sendfile on; + tcp_nopush on; + types_hash_max_size 2048; + keepalive_timeout 65; + server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # Real IP + ## + set_real_ip_from 173.245.48.0/20; + set_real_ip_from 103.21.244.0/22; + set_real_ip_from 103.22.200.0/22; + set_real_ip_from 103.31.4.0/22; + set_real_ip_from 141.101.64.0/18; + set_real_ip_from 108.162.192.0/18; + set_real_ip_from 190.93.240.0/20; + set_real_ip_from 188.114.96.0/20; + set_real_ip_from 197.234.240.0/22; + set_real_ip_from 198.41.128.0/17; + set_real_ip_from 162.158.0.0/15; + set_real_ip_from 104.16.0.0/13; + set_real_ip_from 104.24.0.0/14; + set_real_ip_from 172.64.0.0/13; + set_real_ip_from 131.0.72.0/22; + + real_ip_header X-Forwarded-For; + + ## + # SSL Settings + ## + ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + log_format enhanced '$remote_addr [$http_x_forwarded_for] - $upstream_addr [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" $request_time $upstream_response_time'; + + access_log /var/log/nginx/access.log enhanced; + + ## + # Gzip Settings + ## + gzip on; + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # Virtual Host Configs + ## + upstream nodejs_upstream { + server localhost:{{ .Values.nodejs.port | default "3000" }}; + } + + server { + listen 80 default_server; + client_max_body_size 4G; + + server_name _; + + location / { + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_redirect off; + proxy_buffering off; + proxy_pass http://nodejs_upstream; + } + } + + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } + } diff --git a/charts/nodejs/templates/deployment.yaml b/charts/nodejs/templates/deployment.yaml new file mode 100644 index 0000000..a602a95 --- /dev/null +++ b/charts/nodejs/templates/deployment.yaml @@ -0,0 +1,117 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "nodejs.fullname" . }} + labels: + {{- include "nodejs.labels" . | nindent 4 }} + annotations: + secret.reloader.stakater.com/reload: "{{ .Values.nodejs.env.existingSecretName | default (printf "%s-env-secrets" (include "nodejs.fullname" .)) }}, {{ include "nodejs.fullname" . }}-env-ext-secrets" +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "nodejs.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "nodejs.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "nodejs.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }}-nginx + securityContext: + {{- toYaml .Values.nginx.securityContext | nindent 12 }} + image: "{{ .Values.nginx.image.repository }}:{{ .Values.nginx.image.tag | default "alpine" }}" + imagePullPolicy: {{ .Values.nginx.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + {{- with .Values.nginx.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.nginx.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.nginx.resources | nindent 12 }} + volumeMounts: + - name: nginx-conf + mountPath: /etc/nginx/nginx.conf + subPath: nginx.conf + readOnly: true + {{- with .Values.nginx.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + - name: {{ .Chart.Name }}-app + securityContext: + {{- toYaml .Values.nodejs.securityContext | nindent 12 }} + image: "{{ .Values.nodejs.image.repository }}:{{ .Values.nodejs.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.nodejs.image.pullPolicy }} + envFrom: + - secretRef: + name: {{ .Values.nodejs.env.existingSecretName | default (printf "%s-env-secrets" (include "nodejs.fullname" .)) }} + {{- if .Values.nodejs.env.envFromSecretsManager.enabled }} + - secretRef: + name: {{ include "nodejs.fullname" . }}-env-ext-secrets + {{- end }} + ports: + - name: http + containerPort: {{ .Values.nodejs.port | default "3000" }} + protocol: TCP + {{- with .Values.nodejs.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.nodejs.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.nodejs.resources | nindent 12 }} + {{- with .Values.nodejs.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: nginx-conf + configMap: + name: {{ include "nodejs.fullname" $ }}-nginx-conf + items: + - key: nginx.conf + path: nginx.conf + {{- with .Values.nginx.volumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodejs.volumes }} + {{- toYaml . | nindent 8 }} + {{- 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/charts/nodejs/templates/hpa.yaml b/charts/nodejs/templates/hpa.yaml new file mode 100644 index 0000000..d6a8e19 --- /dev/null +++ b/charts/nodejs/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "nodejs.fullname" . }} + labels: + {{- include "nodejs.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "nodejs.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/nodejs/templates/ingress.yaml b/charts/nodejs/templates/ingress.yaml new file mode 100644 index 0000000..002a600 --- /dev/null +++ b/charts/nodejs/templates/ingress.yaml @@ -0,0 +1,65 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "nodejs.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else 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 "nodejs.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- 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 }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ dig "backend" "service" "name" $fullName . }} + port: + {{- if (dig "backend" "service" "port" "name" "" .) }} + name: {{ .backend.service.port.name }} + {{- else }} + number: {{ dig "backend" "service" "port" "number" $svcPort . }} + {{- end }} + {{- else }} + serviceName: {{ dig "backend" "service" "name" $fullName . }} + servicePort: {{ dig "backend" "service" "port" "number" $svcPort . }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/nodejs/templates/job/job-secrets.yaml b/charts/nodejs/templates/job/job-secrets.yaml new file mode 100644 index 0000000..d45eb8c --- /dev/null +++ b/charts/nodejs/templates/job/job-secrets.yaml @@ -0,0 +1,16 @@ +{{- if and .Values.nodejs.preDeployJob.enabled (not .Values.nodejs.env.existingSecretName) -}} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "nodejs.fullname" . }}-env-pre-deploy-secrets + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-10" + "helm.sh/hook-delete-policy": hook-succeeded +type: Opaque +data: + {{- range $key, $val := .Values.nodejs.env.variables }} + {{ $key }}: {{ $val | b64enc }} + {{- end}} + +{{- end }} diff --git a/charts/nodejs/templates/job/job.yaml b/charts/nodejs/templates/job/job.yaml new file mode 100644 index 0000000..f378539 --- /dev/null +++ b/charts/nodejs/templates/job/job.yaml @@ -0,0 +1,76 @@ +{{- if .Values.nodejs.preDeployJob.enabled -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "nodejs.fullname" . }}-pre-deploy + labels: + app.kubernetes.io/component: pre-deploy-job + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-1" + "helm.sh/hook-delete-policy": before-hook-creation +spec: + backoffLimit: {{ .Values.nodejs.preDeployJob.backoffLimit }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "nodejs.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.nodejs.securityContext | nindent 12 }} + image: "{{ .Values.nodejs.image.repository }}:{{ .Values.nodejs.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.nodejs.image.pullPolicy }} + envFrom: + - secretRef: + name: {{ .Values.nodejs.env.existingSecretName | default (printf "%s-env-pre-deploy-secrets" (include "nodejs.fullname" .)) }} + {{- if .Values.nodejs.env.envFromSecretsManager.enabled }} + - secretRef: + name: {{ include "nodejs.fullname" . }}-env-ext-secrets + {{- end }} + {{- with .Values.nodejs.preDeployJob.command }} + command: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.nodejs.preDeployJob.args }} + args: + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.nodejs.resources | nindent 12 }} + {{- with .Values.nodejs.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.nodejs.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- 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 }} + restartPolicy: Never +{{- end -}} diff --git a/charts/nodejs/templates/pdb.yaml b/charts/nodejs/templates/pdb.yaml new file mode 100644 index 0000000..b62ff61 --- /dev/null +++ b/charts/nodejs/templates/pdb.yaml @@ -0,0 +1,18 @@ +{{- if .Values.pdb.create }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "nodejs.fullname" . }} + labels: + {{- include "nodejs.labels" . | nindent 4 }} +spec: + {{- if .Values.pdb.minAvailable }} + minAvailable: {{ .Values.pdb.minAvailable }} + {{- end }} + {{- if .Values.pdb.maxUnavailable }} + maxUnavailable: {{ .Values.pdb.maxUnavailable }} + {{- end }} + selector: + matchLabels: + {{- include "nodejs.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/nodejs/templates/secrets.yaml b/charts/nodejs/templates/secrets.yaml new file mode 100644 index 0000000..c0e56d0 --- /dev/null +++ b/charts/nodejs/templates/secrets.yaml @@ -0,0 +1,30 @@ +{{- if not .Values.nodejs.env.existingSecretName }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "nodejs.fullname" . }}-env-secrets +type: Opaque +data: + {{- range $key, $val := .Values.nodejs.env.variables }} + {{ $key }}: {{ $val | b64enc }} + {{- end}} +{{- end }} + +{{- if .Values.nodejs.env.envFromSecretsManager.enabled }} +--- +apiVersion: external-secrets.io/v1 +kind: ExternalSecret +metadata: + name: {{ include "nodejs.fullname" . }}-env-ext-secrets +spec: + refreshInterval: 1m + secretStoreRef: + name: global-secret-store + kind: ClusterSecretStore + target: + name: {{ include "nodejs.fullname" . }}-env-ext-secrets + creationPolicy: Owner + dataFrom: + - extract: + key: {{ .Values.nodejs.env.envFromSecretsManager.secretPath }} +{{- end }} diff --git a/charts/nodejs/templates/service.yaml b/charts/nodejs/templates/service.yaml new file mode 100644 index 0000000..4c96f6e --- /dev/null +++ b/charts/nodejs/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "nodejs.fullname" . }} + labels: + {{- include "nodejs.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "nodejs.selectorLabels" . | nindent 4 }} diff --git a/charts/nodejs/templates/serviceaccount.yaml b/charts/nodejs/templates/serviceaccount.yaml new file mode 100644 index 0000000..3709f75 --- /dev/null +++ b/charts/nodejs/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "nodejs.serviceAccountName" . }} + labels: + {{- include "nodejs.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/nodejs/templates/tests/test-connection.yaml b/charts/nodejs/templates/tests/test-connection.yaml new file mode 100644 index 0000000..c579ea6 --- /dev/null +++ b/charts/nodejs/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "nodejs.fullname" . }}-test-connection" + labels: + {{- include "nodejs.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "nodejs.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/nodejs/values.yaml b/charts/nodejs/values.yaml new file mode 100644 index 0000000..57a8180 --- /dev/null +++ b/charts/nodejs/values.yaml @@ -0,0 +1,227 @@ +# -- Number of replicas to sping up +replicaCount: 1 +# -- Secret that used to store docker registry credentials +imagePullSecrets: [] +# -- Overrides release name +nameOverride: "" +# -- Overrides full release name +fullnameOverride: "" +# -- Service Account +serviceAccount: + # -- Specifies whether a service account should be created + create: true + # -- Automatically mount a ServiceAccount's API credentials? + automount: true + # -- Annotations to add to the service account + annotations: {} + # -- The name of the service account to use. + name: "" +# -- Annotations to add to the pod +podAnnotations: {} +# -- Labels to add to the pod +podLabels: {} +# -- Security context of the pod +podSecurityContext: {} +# fsGroup: 2000 + +# -- NginX Specific Configurations +# @section -- NginX Settings +# @default -- A complex object. Please check values below +nginx: + # -- NginX image settings + # @section -- NginX Settings + image: + repository: nginx + pullPolicy: IfNotPresent + # -- Overrides the image tag whose default is the chart appVersion + # @section -- NginX Settings + tag: "" + # -- NginX container security context + # @section -- NginX Settings + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + # -- NginX container resources + # @section -- NginX Settings + 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 + # -- NginX container liveness probe + # @section -- NginX Settings + # livenessProbe: + # httpGet: + # path: / + # port: http + # -- NginX container readiness probe + # @section -- NginX Settings + # readinessProbe: + # httpGet: + # path: / + # port: http + # -- NginX container additional volumes + # @section -- NginX Settings + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # -- NginX container additional volumes mounts + # @section -- NginX Settings + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + +# -- Node.js Specific Configurations +# @section -- Node.js Settings +# @default -- A complex object. Please check values below +nodejs: + # -- Node.js image settings + # @section -- Node.js Settings + image: + repository: nodejs + pullPolicy: IfNotPresent + # -- Overrides the image tag whose default is the chart appVersion + # @section -- Node.js Settings + tag: "" + # -- Node.js container security context + # @section -- Node.js Settings + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + # -- Node.js container resources + # @section -- Node.js Settings + 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 + # -- Node.js container liveness probe + # @section -- Node.js Settings + # livenessProbe: + # httpGet: + # path: / + # port: http + # -- Node.js container readiness probe + # @section -- Node.js Settings + # readinessProbe: + # httpGet: + # path: / + # port: http + # initialDelaySeconds: 5 + # periodSeconds: 5 + # -- Node.js container additional volumes + # @section -- Node.js Settings + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # -- Node.js container additional volumes mounts + # @section -- Node.js Settings + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + # -- Enables pre-deploy job with Helm hook before rolling the update + # @section -- Node.js Settings + preDeployJob: + enabled: false + # -- Number of retries before marking the job as failed + # @section -- Node.js Settings + backoffLimit: 6 + # -- Command to run in the job container + # @section -- Node.js Settings + command: [] + # - node + # -- Arguments to pass to the command + # @section -- Node.js Settings + args: [] + # - scripts/migrate.js + # -- Node.js environment variables + # @section -- Node.js Settings + port: 3000 + env: + # -- Name of an existing Secret to use instead of creating one from variables. + # If set, the chart will not create its own Secret and will mount this one in both the deployment and the pre-deploy job. + # Useful when secrets are managed externally (e.g. via External Secrets Operator). + # @section -- Node.js Settings + existingSecretName: "" + # -- Use AWS secrets manager ref. Works with external-secrets operator + # @section -- Node.js Settings + envFromSecretsManager: + enabled: false + secretPath: dev/example-com/env-secrets + # -- Extra env variables + # @section -- Node.js Settings + variables: + APP_DOMAIN: "example.com" + +# -- Service settings +# @section -- Networking Settings +service: + type: ClusterIP + port: 80 +# -- Ingress settings +# @section -- Networking Settings +ingress: + # -- Enables ingress when true + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local +# -- Autoscaling settings +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# -- Pod Disruption Budget settings +# @section -- PDB Settings +pdb: + create: false + minAvailable: 1 + # maxUnavailable: 1 + +# -- Node selector settings +nodeSelector: {} +# -- Tolerations settings +tolerations: [] +# -- Affinity settings +affinity: {}