Skip to content

Commit

Permalink
Merge pull request #27 from soketi/new-chart/k8soketi
Browse files Browse the repository at this point in the history
soketi/k8soketi
  • Loading branch information
rennokki authored Nov 9, 2022
2 parents 1175fe5 + 9fe297c commit 5125258
Show file tree
Hide file tree
Showing 17 changed files with 817 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/k8soketi/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
23 changes: 23 additions & 0 deletions charts/k8soketi/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: k8soketi
description: Run soketi/k8soketi in your Kubernetes cluster using this Helm chart.

# 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: 1.0.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.
appVersion: 1.0.0
49 changes: 49 additions & 0 deletions charts/k8soketi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
k8soketi Server Chart
===================

Containerize & Orchestrate your k8soketi application with this simple Helm chart.

## 🤝 Supporting

**If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with [Github Sponsors](https://github.com/sponsors/rennokki). 📦**

## 🛑 Requirements

- Kubernetes v1.19+

## 🚀 Installation

Install Helm chart repository:

```bash
$ helm repo add k8soketi https://helm.soketi.app
$ helm repo update
```

Install the k8soketi chart:

```bash
$ helm upgrade k8soketi \
--install \
--version=1.0.0 \
soketi/k8soketi
```

Check `values.yaml` for additional available customizations.

## 🐛 Testing

Coming soon.

## 🤝 Contributing

Please see [CONTRIBUTING](../../CONTRIBUTING.md) for details.

## 🔒 Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## 🎉 Credits

- [Alex Renoki](https://github.com/rennokki)
- [All Contributors](../../../../contributors)
30 changes: 30 additions & 0 deletions charts/k8soketi/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- if .Values.ingress.enabled }}
The application is available at these URLs:
{{- 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 }}
Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "soketi.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 "soketi.fullname" . }}'
Get the application URL by running these commands:
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "soketi.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "soketi.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:{{ .Values.service.port }} to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME {{ .Values.service.port }}:$CONTAINER_PORT
{{- end }}

{{- if or .Values.metrics.enabled .Values.serviceMonitor.enabled }}
Metrics: The Prometheus metrics are enabled on port {{ .Values.metrics.service.port }}.
{{- end }}
The pods can discovery each other using WebSockets with the port {{ .Values.peerServer.service.port }}.
63 changes: 63 additions & 0 deletions charts/k8soketi/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "soketi.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 "soketi.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 "soketi.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "soketi.labels" -}}
helm.sh/chart: {{ include "soketi.chart" . }}
{{ include "soketi.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "soketi.selectorLabels" -}}
app.kubernetes.io/name: {{ include "soketi.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: soketi
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "soketi.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "soketi.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
148 changes: 148 additions & 0 deletions charts/k8soketi/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "soketi.fullname" . }}
labels:
{{- include "soketi.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
{{- with .Values.strategy }}
strategy:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- include "soketi.selectorLabels" . | nindent 6 }}
{{- if or .Values.metrics.enabled .Values.serviceMonitor.enabled }}
k8s.soketi.app/serves-metrics: "yes"
{{- end }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "soketi.selectorLabels" . | nindent 8 }}
{{- if or .Values.metrics.enabled .Values.serviceMonitor.enabled }}
k8s.soketi.app/serves-metrics: "yes"
{{- end }}
spec:
{{- with .Values.extraVolumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}

terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}

{{- if .Values.app.multicast.enabled }}
hostNetwork: {{ .Values.app.multicast.hostNetwork }}
dnsPolicy: {{ .Values.app.multicast.dnsPolicy }}
{{- end }}

{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}

serviceAccountName: {{ include "soketi.serviceAccountName" . }}

securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}

{{- with .Values.extraInitContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}

containers:
{{- with .Values.extraContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.app.image.repository }}:{{ .Values.app.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.app.image.pullPolicy }}
{{- with .Values.app.extraVolumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: soketi
containerPort: {{ .Values.service.port }}
protocol: TCP
- name: metrics
containerPort: {{ .Values.metrics.service.port }}
protocol: TCP
- name: peer
containerPort: {{ .Values.peerServer.service.port }}
protocol: TCP
command:
- node
- --optimize_for_size
- --optimize-for-size
- /app/bin/server.js
- start
{{- if or .Values.metrics.enabled .Values.serviceMonitor.enabled }}
- --metrics
{{- end }}
{{- with .Values.app.flags }}
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: PORT
value: "{{ .Values.service.port }}"
- name: METRICS_SERVER_PORT
value: "{{ .Values.metrics.service.port }}"
- name: KUBE_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: KUBE_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: KUBE_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: KUBE_SERVICES
value: {{ include "soketi.fullname" . }}-peer
- name: PEER_WS_PORT
value: "{{ .Values.peerServer.service.port }}"
- name: NODE_OPTIONS
value: "--es-module-specifier-resolution=node"
- name: PEER_INACTIVITY_TIMEOUT
value: "10"
- name: WS_GRACE_PERIOD
value: "10"
- name: MODE
value: {{ .Values.app.mode | default "full" }}
{{- with .Values.app.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.app.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 }}
39 changes: 39 additions & 0 deletions charts/k8soketi/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "soketi.fullname" . }}
labels:
{{- include "soketi.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "soketi.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
{{- with .Values.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
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 }}
{{- with .Values.autoscaling.customMetrics }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 5125258

Please sign in to comment.