From 4dfb6322f77a638dbc61361c6be7ca09b4ad2fe4 Mon Sep 17 00:00:00 2001 From: Gabriel Simmer Date: Thu, 19 Oct 2023 14:31:30 +0100 Subject: [PATCH] Fully migrate tclip to kubenix --- flake.nix | 4 +- homelab/custom.nix | 17 ++++++ homelab/kubernetes.nix | 3 +- homelab/tclip.nix | 20 +++++++ homelab/tclip.yml | 119 ----------------------------------------- 5 files changed, 42 insertions(+), 121 deletions(-) create mode 100644 homelab/custom.nix delete mode 100644 homelab/tclip.yml diff --git a/flake.nix b/flake.nix index 5e50cd9..a8e22f2 100644 --- a/flake.nix +++ b/flake.nix @@ -56,7 +56,9 @@ packages.x86_64-linux = { kubernetes = (kubenix.evalModules.x86_64-linux { module = { kubenix, ... }: { - imports = [ kubenix.modules.k8s ./homelab/kubernetes.nix ]; + imports = [ + kubenix.modules.k8s ./homelab/kubernetes.nix + ]; }; }).config.kubernetes.result; }; diff --git a/homelab/custom.nix b/homelab/custom.nix new file mode 100644 index 0000000..123641d --- /dev/null +++ b/homelab/custom.nix @@ -0,0 +1,17 @@ +{ lib, ... }: { + kubernetes.customTypes = [ + { + name = "servicemonitors"; + attrName = "servicemonitor"; + group = "monitoring.coreos.com"; + kind = "ServiceMonitor"; + version = "v1"; + module = { + options.endpoints = lib.mkOption { + description = "Endpoints"; + type = lib.types.list; + }; + }; + } + ]; +} diff --git a/homelab/kubernetes.nix b/homelab/kubernetes.nix index 7b9d17f..f521853 100644 --- a/homelab/kubernetes.nix +++ b/homelab/kubernetes.nix @@ -1,4 +1,5 @@ -{ config, kubenix, ... }: { +{ lib, config, kubenix, ... }: { imports = [ kubenix.modules.k8s + (import ./custom.nix) (import ./tclip.nix) ]; } diff --git a/homelab/tclip.nix b/homelab/tclip.nix index da89cb1..ce58f1c 100644 --- a/homelab/tclip.nix +++ b/homelab/tclip.nix @@ -4,6 +4,26 @@ let tclipImage = "git.gmem.ca/arch/tclip:arm"; in { + kubernetes.resources."monitoring.coreos.com"."v1".ServiceMonitor.tclip = { + spec = { + selector.matchLabels.app = appName; + endpoints = [ { port = "metrics"; interval = "30s"; } ]; + }; + }; + kubernetes.resources.services.tclip = { + metadata.annotations = { + "prometheus.io/port" = "9090"; + "prometheus.io/scrape" = "true"; + "prometheus.io/path" = "/metrics"; + }; + spec = { + selector.app = appName; + ports.metrics = { + port = 9090; + targetPort = 9090; + }; + }; + }; kubernetes.resources.statefulSets.tclip.spec = { selector.matchLabels.app = appName; serviceName = appName; diff --git a/homelab/tclip.yml b/homelab/tclip.yml deleted file mode 100644 index fffd5ad..0000000 --- a/homelab/tclip.yml +++ /dev/null @@ -1,119 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: tclip -spec: - selector: - matchLabels: - app: tclip - serviceName: tclip - replicas: 1 - template: - metadata: - labels: - app: tclip - spec: - volumes: - - name: litestream - configMap: - name: tclip-litestream - - name: config - configMap: - name: tclip - initContainers: - - name: init-litestream - image: litestream/litestream:sha-749bc0d - args: ['restore', '-if-db-not-exists', '-if-replica-exists', '-v', '/data/data.db'] - volumeMounts: - - name: data - mountPath: /data - - name: litestream - mountPath: /etc/litestream.yml - subPath: tclip.yml - envFrom: - - secretRef: - name: tclip-litestream-s3 - - containers: - - name: tclip - image: git.gmem.ca/arch/tclip:arm - imagePullPolicy: Always - resources: - limits: - memory: "128Mi" - cpu: "500m" - requests: - memory: "64Mi" - cpu: "100m" - envFrom: - - secretRef: - name: tclip - volumeMounts: - - name: data - mountPath: /data - env: - - name: DATA_DIR - value: /data - - name: USE_FUNNEL - value: "true" - - - name: litestream - image: litestream/litestream:sha-749bc0d - args: ['replicate'] - volumeMounts: - - name: data - mountPath: /data - - name: litestream - mountPath: /etc/litestream.yml - subPath: tclip.yml - envFrom: - - secretRef: - name: tclip-litestream-s3 - ports: - - name: metrics - containerPort: 9090 - resources: - limits: - memory: "128Mi" - cpu: "300m" - requests: - memory: "64Mi" - cpu: "100m" - - volumeClaimTemplates: - - metadata: - name: data - spec: - storageClassName: nfs-client - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi ---- -apiVersion: v1 -kind: Service -metadata: - name: tclip-metrics - annotations: - prometheus.io/port: "9090" - prometheus.io/scrape: "true" - prometheus.io/path: "/metrics" -spec: - selector: - app: tclip - ports: - - port: 9090 - targetPort: 9090 - name: litestream-metrics ---- -apiVersion: monitoring.coreos.com/v1 -kind: ServiceMonitor -metadata: - name: tclip -spec: - selector: - matchLabels: - app: tclip - endpoints: - - port: metrics - interval: 30s