diff --git a/ser2sock/.helmignore b/ser2sock/.helmignore new file mode 100644 index 00000000..e559de0a --- /dev/null +++ b/ser2sock/.helmignore @@ -0,0 +1,24 @@ +# 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/ +# OWNERS file for Kubernetes +OWNERS diff --git a/ser2sock/Chart.yaml b/ser2sock/Chart.yaml new file mode 100644 index 00000000..57e291bb --- /dev/null +++ b/ser2sock/Chart.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +appVersion: "1.0.0" +description: Serial to Socket Redirector +name: ser2sock +version: 0.0.1 +keywords: + - ser2sock +home: https://github.com/billimek/billimek-charts/tree/master/ser2sock +icon: https://i.imgur.com/GfZ7McO.png +sources: + - https://github.com/nutechsoftware/ser2sock + - https://github.com/tenstartups/ser2sock +maintainers: + - name: billimek + email: jeff@billimek.com diff --git a/ser2sock/OWNERS b/ser2sock/OWNERS new file mode 100644 index 00000000..51f88652 --- /dev/null +++ b/ser2sock/OWNERS @@ -0,0 +1,4 @@ +approvers: +- billimek +reviewers: +- billimek \ No newline at end of file diff --git a/ser2sock/README.md b/ser2sock/README.md new file mode 100644 index 00000000..df84bfa4 --- /dev/null +++ b/ser2sock/README.md @@ -0,0 +1,86 @@ +# ser2sock: Serial to Socket Redirector + +This is a helm chart for [ser2sock](https://github.com/nutechsoftware/ser2sock) + +## TL;DR; + +```shell +$ helm repo add billimek https://billimek.com/billimek-charts/ +$ helm install billimek/ser2sock +``` + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +helm install --name my-release billimek/ser2sock +``` + +**IMPORTANT NOTE:** the USB device must be accessible on the node where this pod runs, in order for this chart to function properly. + +A way to achieve this can be with nodeAffinity rules, for example: + +```yaml +affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: usb + operator: In + values: + - alarmdecoder +``` + +... where a node with an attached Coral USB device is labeled with `usb: alarmdecoder` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +helm delete my-release --purge +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following tables lists the configurable parameters of the Sentry chart and their default values. + +| Parameter | Description | Default | +|----------------------------|-------------------------------------|---------------------------------------------------------| +| `image.repository` | Image repository | `tenstartups/ser2sock` | +| `image.tag` | Image tag. Possible values listed [here](https://hub.docker.com/r/tenstartups/ser2sock/tags).| `latest`| +| `image.pullPolicy` | Image pull policy | `IfNotPresent` | +| `strategyType` | Specifies the strategy used to replace old Pods by new ones | `Recreate` | +| `timezone` | Timezone the ser2sock instance should run as, e.g. 'America/New_York' | `` | +| `device` | USB Device to use | `/dev/ttyUSB0` | +| `puid` | UID to run as | `1001` | +| `pgid` | GID to run as | `1001` | +| `Service.type` | Kubernetes service type for the ser2sock GUI | `ClusterIP` | +| `Service.port` | Kubernetes port where the ser2sock GUI is exposed| `5000` | +| `Service.annotations` | Service annotations for the ser2sock GUI | `{}` | +| `Service.labels` | Custom labels | `{}` | +| `Service.loadBalancerIP` | Loadbalance IP for the ser2sock GUI | `{}` | +| `Service.loadBalancerSourceRanges` | List of IP CIDRs allowed access to load balancer (if supported) | None +| `resources` | CPU/Memory resource requests/limits | `{}` | +| `nodeSelector` | Node labels for pod assignment | `{}` | +| `tolerations` | Toleration labels for pod assignment | `[]` | +| `affinity` | Affinity settings for pod assignment | `{}` | + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```console +helm install --name my-release \ + billimek/ser2sock +``` + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, + +```console +helm install --name my-release -f values.yaml billimek/ser2sock +``` + +Read through the [values.yaml](https://github.com/billimek/billimek-charts/blob/master/ser2sock/values.yaml) file. It has several commented out suggested values. diff --git a/ser2sock/templates/NOTES.txt b/ser2sock/templates/NOTES.txt new file mode 100644 index 00000000..67377874 --- /dev/null +++ b/ser2sock/templates/NOTES.txt @@ -0,0 +1,15 @@ +1. Get the application URL by running these commands: +{{- if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "ser2sock.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 svc -w {{ include "ser2sock.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ser2sock.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + 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 "ser2sock.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:5000 to use your application" + kubectl port-forward $POD_NAME 5000:5000 +{{- end }} diff --git a/ser2sock/templates/_helpers.tpl b/ser2sock/templates/_helpers.tpl new file mode 100644 index 00000000..0d9c12a6 --- /dev/null +++ b/ser2sock/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "ser2sock.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 "ser2sock.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 "ser2sock.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "ser2sock.labels" -}} +app.kubernetes.io/name: {{ include "ser2sock.name" . }} +helm.sh/chart: {{ include "ser2sock.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 -}} diff --git a/ser2sock/templates/deployment.yaml b/ser2sock/templates/deployment.yaml new file mode 100644 index 00000000..a375ec7b --- /dev/null +++ b/ser2sock/templates/deployment.yaml @@ -0,0 +1,84 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "ser2sock.fullname" . }} + labels: +{{ include "ser2sock.labels" . | indent 4 }} +spec: + replicas: 1 + strategy: + type: {{ .Values.strategyType }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "ser2sock.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "ser2sock.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + {{- if .Values.podAnnotations }} + annotations: + {{- range $key, $value := .Values.podAnnotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + privileged: true + ports: + - name: http + containerPort: 10000 + protocol: TCP + livenessProbe: + tcpSocket: + port: http + initialDelaySeconds: 30 + failureThreshold: 5 + timeoutSeconds: 5 + readinessProbe: + tcpSocket: + port: http + initialDelaySeconds: 30 + failureThreshold: 5 + timeoutSeconds: 5 + env: + {{- if .Values.timezone }} + - name: TZ + value: "{{ .Values.timezone }}" + {{- end }} + - name: LISTENER_PORT + value: "10000" + - name: BAUD_RATE + value: "115200" + - name: SERIAL_DEVICE + value: "{{ .Values.device }}" + - name: PUID + value: "{{ .Values.puid }}" + - name: PGID + value: "{{ .Values.pgid }}" + volumeMounts: + - mountPath: /dev/ttyUSB0 + name: usb + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: usb + hostPath: + path: {{ .Values.device }} + {{- 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/ser2sock/templates/service.yaml b/ser2sock/templates/service.yaml new file mode 100644 index 00000000..dad9e63e --- /dev/null +++ b/ser2sock/templates/service.yaml @@ -0,0 +1,49 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "ser2sock.fullname" . }} + labels: +{{ include "ser2sock.labels" . | indent 4 }} +{{- if .Values.service.labels }} +{{ toYaml .Values.service.labels | indent 4 }} +{{- end }} +{{- with .Values.service.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }} + type: ClusterIP + {{- if .Values.service.clusterIP }} + clusterIP: {{ .Values.service.clusterIP }} + {{end}} +{{- else if eq .Values.service.type "LoadBalancer" }} + type: {{ .Values.service.type }} + {{- if .Values.service.loadBalancerIP }} + loadBalancerIP: {{ .Values.service.loadBalancerIP }} + {{- end }} + {{- if .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: +{{ toYaml .Values.service.loadBalancerSourceRanges | indent 4 }} + {{- end -}} +{{- else }} + type: {{ .Values.service.type }} +{{- end }} +{{- if .Values.service.externalIPs }} + externalIPs: +{{ toYaml .Values.service.externalIPs | indent 4 }} +{{- end }} + {{- if .Values.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} + {{- end }} + ports: + - name: http + port: {{ .Values.service.port }} + protocol: TCP + targetPort: http +{{ if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }} + nodePort: {{.Values.service.nodePort}} +{{ end }} + selector: + app.kubernetes.io/name: {{ include "ser2sock.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} \ No newline at end of file diff --git a/ser2sock/values.yaml b/ser2sock/values.yaml new file mode 100644 index 00000000..115de8ea --- /dev/null +++ b/ser2sock/values.yaml @@ -0,0 +1,60 @@ +# Default values for ser2sock. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# upgrade strategy type (e.g. Recreate or RollingUpdate) +strategyType: Recreate + +image: + repository: tenstartups/ser2sock + tag: latest + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +# timezone: "America/New York" +device: "/dev/ttyUSB0" +puid: "1001" +pgid: "1001" + +service: + type: ClusterIP + port: 10000 + ## Specify the nodePort value for the LoadBalancer and NodePort service types. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport + ## + # nodePort: + ## Provide any additional annotations which may be required. This can be used to + ## set the LoadBalancer service type to internal only. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer + ## + annotations: {} + labels: {} + ## Use loadBalancerIP to request a specific static IP, + ## otherwise leave blank + ## + loadBalancerIP: + # loadBalancerSourceRanges: [] + ## Set the externalTrafficPolicy in the Service to either Cluster or Local + # externalTrafficPolicy: Cluster + +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 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +podAnnotations: {}