Skip to content

Commit

Permalink
add rewards squid helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
DaMandal0rian committed Apr 23, 2024
1 parent 9d5caae commit 31ba640
Show file tree
Hide file tree
Showing 23 changed files with 963 additions and 0 deletions.
23 changes: 23 additions & 0 deletions explorer/k8s/helm/rewards-squid/.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/
24 changes: 24 additions & 0 deletions explorer/k8s/helm/rewards-squid/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: rewards-squid
description: A Helm chart for 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: "gemini-3h"
8 changes: 8 additions & 0 deletions explorer/k8s/helm/rewards-squid/config/explorer-env-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POSTGRES_HOST=""
POSTGRES_USER=""
POSTGRES_DB="general-squid"
POSTGRES_PASSWORD=""
POSTGRES_PORT=5432
ARCHIVE_ENDPOINT="https://archive.gemini-3h.subspace.network/api"
RPC_ENDPOINT="wss://rpc-squids.gemini-3h.subspace.network/ws"
GQL_PORT=4350
20 changes: 20 additions & 0 deletions explorer/k8s/helm/rewards-squid/misc/acme-certificate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-production
namespace: explorer-network
spec:
acme:
# You must replace this email address with your own.
# Let's Encrypt will use this to contact you about expiring
# certificates, and issues related to your account.
email: [email protected]
server: https://acme-staging-v02.api.letsencrypt.org/directory
privateKeySecretRef:
# Secret resource that will be used to store the account's private key.
name: explorer-issuer-account-key
# Add a single challenge solver, HTTP01 using nginx
solvers:
- http01:
ingress:
class: nginx
22 changes: 22 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -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 {{ .Values.namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "rewards-squid.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Values.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 {{ .Values.namespace }} svc -w {{ include "rewards-squid.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Values.namespace }} {{ include "rewards-squid.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 {{ .Values.namespace }} -l "app.kubernetes.io/name={{ include "rewards-squid.name" . }},app.kubernetes.io/instance={{ .Values.namespace }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Values.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 {{ .Values.namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
60 changes: 60 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "rewards-squid.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
*/}}
{{- define "rewards-squid.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 "rewards-squid.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "rewards-squid.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "rewards-squid.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
55 changes: 55 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/clusterroles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: rbac.authorization.k8s.io/v1
# This cluster role binding allows anyone in the "manager" group to
# read secrets in any namespace.
kind: ClusterRoleBinding
metadata:
name: secret-reader-cluster-binding
namespace: {{ .Values.namespace}}
subjects:
- kind: Group
name: manager # Name is case sensitive
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
# "namespace" omitted since ClusterRoles are not namespaced
name: secret-reader
rules:
- apiGroups: [""]
# at the HTTP level, the name of the resource for accessing Secret
# objects is "secrets"
resources: ["secrets"]
verbs: ["get", "watch", "list"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "rewards-squid.fullname" . }}-admin
namespace: {{ .Values.namespace}}
subjects:
- kind: Group
name: {{ include "rewards-squid.fullname" . }}-admin
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: admin
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: role-grantor
rules:
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["rolebindings"]
verbs: ["create"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["clusterroles"]
verbs: ["bind"]
# omit resourceNames to allow binding any ClusterRole
resourceNames: ["admin","edit","view"]
13 changes: 13 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.namespace }}-configmap
namespace: {{ .Values.namespace }}
labels:
app: {{ include "rewards-squid.fullname" . }}
data:
POSTGRES_PORT: {{ .Values.postgres.postgresPort }}
POSTGRES_DB: {{ .Values.postgres.postgresDatabase }}
POSTGRES_HOST : {{ .Values.postgres.postgresHost }}
files:
- ../config/explorer-env-file
46 changes: 46 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "rewards-squid.fullname" . }}
labels:
{{- include "rewards-squid.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "rewards-squid.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
- type: Pods
pods:
metric:
name: packets-per-second
target:
type: AverageValue
averageValue: 3k
- type: Object
object:
metric:
name: requests-per-second
describedObject:
apiVersion: networking.k8s.io/v1
kind: Ingress
name: main-route
target:
type: Value
value: 10k
{{- end }}
45 changes: 45 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "rewards-squid.fullname" . }}-ingress
namespace: {{ .Values.namespace }}
labels:
app.kubernetes.io/name: {{ include "rewards-squid.name" . }}
helm.sh/chart: {{ include "rewards-squid.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: nginx
tls:
- hosts:
- {{ .Values.ingress.hosts | first | quote }}
secretName: {{ .Values.ingress.tls.secretName | quote }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path | quote }}
pathType: {{ .pathType | quote }}
backend:
service:
name: {{ .Values.lb_service.name | quote }}
port:
number: {{ .Values.lb_service.port }}
{{- end }}
{{- end }}

---
apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
name: acme-tls-secret
data:
tls.crt: {{ .Values.ingress.tls.crt | quote }}
tls.key: {{ .Values.ingress.tls.key | quote }}
26 changes: 26 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/loadbal-svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "rewards-squid.fullname" . }}-loadbal-svc
namespace: {{ .Values.namespace}}
labels:
app: {{ include "rewards-squid.fullname" . }}-app
chart: {{ include "rewards-squid.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
selector:
name: {{ include "rewards-squid.fullname" . }}-app
app: {{ include "rewards-squid.fullname" . }}-app
type: {{ .Values.lb_service.type }}
sessionAffinity: None
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10800
ports:
{{- range .Values.lb_service.lb_ports }}
- port: {{ .port }}
name: {{ .name }}
targetPort: {{ .targetPort }}
protocol: {{ .protocol }}
{{- end }}
6 changes: 6 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.namespace }}
labels:
name: {{ .Values.namespace }}
27 changes: 27 additions & 0 deletions explorer/k8s/helm/rewards-squid/templates/postgres-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "rewards-squid.fullname" . }}-postgres-configmap
namespace: {{ .Values.namespace }}
data:
postgres.conf: |-
max_connections = 200
shared_buffers = 8GB
effective_cache_size = 24GB
maintenance_work_mem = 2GB
checkpoint_completion_target = 0.9
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 1.1
effective_io_concurrency = 200
work_mem = 10485kB
min_wal_size = 1GB
max_wal_size = 4GB
max_worker_processes = 16
max_parallel_workers_per_gather = 4
max_parallel_workers = 16
max_parallel_maintenance_workers = 4
shared_preload_libraries='pg_stat_statements'
pg_stat_statements.track=all
# Replace with particular IP addresses in production
listen_addresses = '0.0.0.0'
Loading

0 comments on commit 31ba640

Please sign in to comment.