Skip to content

Commit

Permalink
👷 add kubernetes setup (tools, helm chart, skaffold)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidB committed Dec 31, 2023
1 parent 66083d2 commit f081b08
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .rtx.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ RUST_WITHOUT = "rust-docs"
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = "http://127.0.0.1:4317"
# OTEL_EXPORTER_OTLP_TRACES_PROTOCOL = "grpc"
OTEL_TRACES_SAMPLER = "always_on"
CLUSTER_NAME = "kind-local"

[tools]
# docker = '*' # (or podman + some config) should be available for some of thoses tools
# dive = '*' # to explore content of image container
helm = '3.12'
# helmfile = '0.155'
kubectl = '1.27'
ctlptl = '0.8'
kind = '0.20'
java = '*' # required by skaffold
skaffold = '2'

rust = '1.75'
just = '1'
2 changes: 1 addition & 1 deletion cdviz-collector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> Result<(), BoxError> {

let app = app();
// run it
let addr = &"0.0.0.0:3000".parse::<SocketAddr>()?;
let addr = &"0.0.0.0:8080".parse::<SocketAddr>()?;
tracing::warn!("listening on {}", addr);
let listener = tokio::net::TcpListener::bind(addr).await?;
axum::serve(listener, app.into_make_service())
Expand Down
23 changes: 23 additions & 0 deletions charts/cdviz-collector/.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/
6 changes: 6 additions & 0 deletions charts/cdviz-collector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: cdviz
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "0.1.0"
62 changes: 62 additions & 0 deletions charts/cdviz-collector/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "my.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 "my.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 "my.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "my.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "my.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
61 changes: 61 additions & 0 deletions charts/cdviz-collector/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "my.fullname" . }}

Check failure on line 4 in charts/cdviz-collector/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

4:11 [braces] too many spaces inside braces

Check failure on line 4 in charts/cdviz-collector/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

4:35 [braces] too many spaces inside braces
labels:
{{- include "my.labels" . | nindent 4 }}

Check failure on line 6 in charts/cdviz-collector/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

6:7 syntax error: expected the node content, but found '-' (syntax)
spec:
{{- if not .Values.autoscaling.enabled }}

Check failure on line 8 in charts/cdviz-collector/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

8:41 [braces] too many spaces inside braces
replicas: {{ .Values.replicaCount }}

Check failure on line 9 in charts/cdviz-collector/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

9:3 [indentation] wrong indentation: expected 0 but found 2

Check failure on line 9 in charts/cdviz-collector/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

9:15 [braces] too many spaces inside braces
{{- end }}
selector:
matchLabels:
{{- include "my.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "my.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "my.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: http
readinessProbe:
httpGet:
path: /readyz
port: http
resources:
{{- toYaml .Values.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 }}
32 changes: 32 additions & 0 deletions charts/cdviz-collector/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}

Check failure on line 1 in charts/cdviz-collector/templates/hpa.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

1:3 syntax error: expected the node content, but found '-' (syntax)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "my.fullname" . }}

Check failure on line 5 in charts/cdviz-collector/templates/hpa.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

5:11 [braces] too many spaces inside braces

Check failure on line 5 in charts/cdviz-collector/templates/hpa.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

5:35 [braces] too many spaces inside braces
labels:
{{- include "my.labels" . | nindent 4 }}

Check failure on line 7 in charts/cdviz-collector/templates/hpa.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

7:42 [braces] too many spaces inside braces
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "my.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 }}
61 changes: 61 additions & 0 deletions charts/cdviz-collector/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "my.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 "my.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: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/cdviz-collector/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "my.fullname" . }}
labels:
{{- include "my.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "my.selectorLabels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions charts/cdviz-collector/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "my.serviceAccountName" . }}
labels:
{{- include "my.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
86 changes: 86 additions & 0 deletions charts/cdviz-collector/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Default values for my.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: ghcr.io/davidb/cdviz-collectory
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

podAnnotations: {}

podSecurityContext:
{}
# fsGroup: 2000

securityContext:
{}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 8080

ingress:
enabled: false
className: ""
annotations:
{}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: cdviz-collector.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

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

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}
Loading

0 comments on commit f081b08

Please sign in to comment.