diff --git a/charts/node/.helmignore b/charts/node/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/charts/node/.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/charts/node/Chart.yaml b/charts/node/Chart.yaml new file mode 100644 index 0000000..746f3f0 --- /dev/null +++ b/charts/node/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: node +version: 0.1.0 diff --git a/charts/node/README.md b/charts/node/README.md new file mode 100644 index 0000000..bc2f2b1 --- /dev/null +++ b/charts/node/README.md @@ -0,0 +1,73 @@ +# Clear Linux* OS `node` Helm Charts + + +## What is this image? + +`clearlinux/node` is a Docker image with `node` running on top of the [official clearlinux base image](https://hub.docker.com/_/clearlinux). + +> [Node](https://nodejs.org/en/) is a JavaScript runtime built on Chrome's V8 JavaScript engine. + +For other Clear Linux* OS based container images, see: https://hub.docker.com/u/clearlinux + +## Why use a clearlinux based image? + +> [Clear Linux* OS](https://clearlinux.org/) is an open source, rolling release Linux distribution optimized for performance and security, from the Cloud to the Edge, designed for customization, and manageability. + +Clear Linux* OS based container images use: + +- Optimized libraries that are compiled with latest compiler versions and flags. +- Software packages that follow upstream source closely and update frequently. +- An aggressive security model and best practices for CVE patching. +- A multi-staged build approach to keep a reduced container image size. +- The same container syntax as the official images to make getting started easy. + +To learn more about Clear Linux* OS, visit: [https://clearlinux.org](https://clearlinux.org/). + + + +## Installing the Node Chart + +Download the node chart and install the chart with the release name ` my-release` + +``` +$ helm install --name my-release node +``` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +``` +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Parameters + +The following table lists the configurable parameters of the node chart and their default values. + +| Parameter | Description | Default | +| ------------------------------ | ------------------------------------------- | --------------------------- | +| `image.replicaCount` | node pod count | `2` | +| `image.repository` | node image repository | `docker.io/clearlinux/node` | +| `image.imagepullPolicy` | node image pull policy | `IfNotPresent` | +| `service.type` | node service type | `NodePort` | +| `service.port` | node service port | `80` | +| `service.targetPort` | node service targetPort | `80` | +| `service.nodePort` | node service nodePort | `30001` | +| `config.enabled` | If apply custom config file to node service | `True` | +| `config.content` | custom file content | `your own custom conf` | +| `config.name` | config volume name | `nodejs-mount` | +| `ingress.enabled` | Enable ingress controller resource | `false` | +| `ingress.hosts[0].host` | Host to your Node installation | `chart-example.local` | +| `ingress.hosts[0].paths` | Path within the url structure | `[]` | +| `ingress.hosts[0].tls` | Utilize TLS backend in ingress | `[]` | +| `ingress.hosts[0].annotations` | Annotations for this host's ingress record | `{}` | + + + +## Licenses + +All licenses for the Clear Linux* Project and distributed software can be found +at https://clearlinux.org/terms-and-policies diff --git a/charts/node/templates/NOTES.txt b/charts/node/templates/NOTES.txt new file mode 100644 index 0000000..77e6647 --- /dev/null +++ b/charts/node/templates/NOTES.txt @@ -0,0 +1,21 @@ +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 }}{{ . }} + {{- 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 "node.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 "node.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "node.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 "node.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/charts/node/templates/_helpers.tpl b/charts/node/templates/_helpers.tpl new file mode 100644 index 0000000..ae1d341 --- /dev/null +++ b/charts/node/templates/_helpers.tpl @@ -0,0 +1,56 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "node.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 "node.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 "node.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "node.labels" -}} +app.kubernetes.io/name: {{ include "node.name" . }} +helm.sh/chart: {{ include "node.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "node.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "node.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/charts/node/templates/config.yaml b/charts/node/templates/config.yaml new file mode 100644 index 0000000..b46cef6 --- /dev/null +++ b/charts/node/templates/config.yaml @@ -0,0 +1,12 @@ +{{- if .Values.config.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "node.fullname" . }} + labels: +{{ include "node.labels" . | indent 4 }} +data: + app.js: |- +{{ .Values.config.content | indent 4 }} +{{- end }} + diff --git a/charts/node/templates/deployment.yaml b/charts/node/templates/deployment.yaml new file mode 100644 index 0000000..30f6380 --- /dev/null +++ b/charts/node/templates/deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "node.fullname" . }} + labels: +{{ include "node.labels" . | indent 4 }} +spec: + replicas: {{ .Values.image.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "node.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "node.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: node + image: {{ .Values.image.repository }} + imagePullPolicy: {{ .Values.image.imagePullPolicy }} + ports: + - containerPort: {{ .Values.service.port }} + command: ["node", "/app.js"] + volumeMounts: + - name: {{ .Values.config.name }} + mountPath: /app.js + subPath: app.js + volumes: + - name: {{ .Values.config.name }} + configMap: + name: {{ include "node.fullname" . }} diff --git a/charts/node/templates/service.yaml b/charts/node/templates/service.yaml new file mode 100644 index 0000000..e346a11 --- /dev/null +++ b/charts/node/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "node.fullname" . }} + labels: +{{ include "node.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.targetPort }} + nodePort: {{ .Values.service.nodePort }} + selector: + app.kubernetes.io/name: {{ include "node.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/node/values.yaml b/charts/node/values.yaml new file mode 100644 index 0000000..5e04f48 --- /dev/null +++ b/charts/node/values.yaml @@ -0,0 +1,45 @@ +# Default values for node. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + replicaCount: 2 + repository: docker.io/clearlinux/node + imagePullPolicy: IfNotPresent + +service: + type: NodePort + port: 80 + targetPort: 80 + nodePort: 30001 + + +config: + enabled: True + name: nodejs-mount + content: |- + const http = require('http'); + const os = require('os'); + var handler = function(request, response){ + response.writeHead(200); + response.end("Hello nodejs!\n") + }; + var www = http.createServer(handler); + www.listen(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 +