From fc438f3c51b53bade665aac34d6a2a3a2b7cfa4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20M=C3=BCller?= Date: Thu, 11 Apr 2024 00:08:49 +0200 Subject: [PATCH] feat(database): add DragonflyDB operator and cluster resources --- .../database/dragonfly/cluster/cluster.yaml | 25 +++++ .../dragonfly/cluster/kustomization.yaml | 7 ++ .../dragonfly/cluster/pod-monitor.yaml | 13 +++ .../apps/database/dragonfly/flux-sync.yaml | 48 +++++++++ .../dragonfly/operator/helm-release.yaml | 102 ++++++++++++++++++ .../dragonfly/operator/kustomization.yaml | 9 ++ .../database/dragonfly/operator/rbac.yaml | 40 +++++++ .../apps/database/kustomization.yaml | 1 + 8 files changed, 245 insertions(+) create mode 100644 kubernetes/talos-flux/apps/database/dragonfly/cluster/cluster.yaml create mode 100644 kubernetes/talos-flux/apps/database/dragonfly/cluster/kustomization.yaml create mode 100644 kubernetes/talos-flux/apps/database/dragonfly/cluster/pod-monitor.yaml create mode 100644 kubernetes/talos-flux/apps/database/dragonfly/flux-sync.yaml create mode 100644 kubernetes/talos-flux/apps/database/dragonfly/operator/helm-release.yaml create mode 100644 kubernetes/talos-flux/apps/database/dragonfly/operator/kustomization.yaml create mode 100644 kubernetes/talos-flux/apps/database/dragonfly/operator/rbac.yaml diff --git a/kubernetes/talos-flux/apps/database/dragonfly/cluster/cluster.yaml b/kubernetes/talos-flux/apps/database/dragonfly/cluster/cluster.yaml new file mode 100644 index 000000000..dc8fd8d05 --- /dev/null +++ b/kubernetes/talos-flux/apps/database/dragonfly/cluster/cluster.yaml @@ -0,0 +1,25 @@ +--- +# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/dragonflydb.io/dragonfly_v1alpha1.json +apiVersion: dragonflydb.io/v1alpha1 +kind: Dragonfly +metadata: + name: dragonfly +spec: + image: ghcr.io/dragonflydb/dragonfly:v1.16.1 + replicas: 4 # set to the number of nodes in the cluster + env: + - name: MAX_MEMORY + valueFrom: + resourceFieldRef: + resource: limits.memory + divisor: 1Mi + args: + - --maxmemory=$(MAX_MEMORY)Mi + - --proactor_threads=2 + - --cluster_mode=emulated + - --lock_on_hashtags + resources: + requests: + cpu: 100m + limits: + memory: 512Mi diff --git a/kubernetes/talos-flux/apps/database/dragonfly/cluster/kustomization.yaml b/kubernetes/talos-flux/apps/database/dragonfly/cluster/kustomization.yaml new file mode 100644 index 000000000..1f9afc204 --- /dev/null +++ b/kubernetes/talos-flux/apps/database/dragonfly/cluster/kustomization.yaml @@ -0,0 +1,7 @@ +--- +# yaml-language-server: $schema=https://json.schemastore.org/kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - cluster.yaml + - pod-monitor.yaml diff --git a/kubernetes/talos-flux/apps/database/dragonfly/cluster/pod-monitor.yaml b/kubernetes/talos-flux/apps/database/dragonfly/cluster/pod-monitor.yaml new file mode 100644 index 000000000..b26a770de --- /dev/null +++ b/kubernetes/talos-flux/apps/database/dragonfly/cluster/pod-monitor.yaml @@ -0,0 +1,13 @@ +--- +# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/monitoring.coreos.com/podmonitor_v1.json +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: dragonfly +spec: + selector: + matchLabels: + app: dragonfly + podTargetLabels: ["app"] + podMetricsEndpoints: + - port: admin diff --git a/kubernetes/talos-flux/apps/database/dragonfly/flux-sync.yaml b/kubernetes/talos-flux/apps/database/dragonfly/flux-sync.yaml new file mode 100644 index 000000000..52c4da64e --- /dev/null +++ b/kubernetes/talos-flux/apps/database/dragonfly/flux-sync.yaml @@ -0,0 +1,48 @@ +--- +# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: apps-dragonfly-operator + namespace: flux-system +spec: + targetNamespace: database + commonMetadata: + labels: + app.kubernetes.io/name: dragonfly-operator + app.kubernetes.io/instance: dragonfly-operator + app.kubernetes.io/component: dragonfly + path: ./kubernetes/talos-flux/apps/database/dragonfly/operator + prune: true + sourceRef: + kind: GitRepository + name: home-ops + wait: true + interval: 30m + retryInterval: 1m + timeout: 5m +--- +# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: apps-dragonfly-cluster + namespace: flux-system +spec: + targetNamespace: database + commonMetadata: + labels: + app.kubernetes.io/name: dragonfly-cluster + app.kubernetes.io/instance: dragonfly-cluster + app.kubernetes.io/component: dragonfly + dependsOn: + - name: apps-dragonfly-operator + path: ./kubernetes/talos-flux/apps/database/dragonfly/cluster + prune: true + sourceRef: + kind: GitRepository + name: home-ops + wait: true + interval: 30m + retryInterval: 1m + timeout: 5m diff --git a/kubernetes/talos-flux/apps/database/dragonfly/operator/helm-release.yaml b/kubernetes/talos-flux/apps/database/dragonfly/operator/helm-release.yaml new file mode 100644 index 000000000..389cba05e --- /dev/null +++ b/kubernetes/talos-flux/apps/database/dragonfly/operator/helm-release.yaml @@ -0,0 +1,102 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/bjw-s/helm-charts/main/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json +apiVersion: helm.toolkit.fluxcd.io/v2beta2 +kind: HelmRelease +metadata: + name: &app dragonfly-operator +spec: + interval: 30m + chart: + spec: + chart: app-template + version: 3.1.0 + sourceRef: + kind: HelmRepository + name: bjw-s-charts + namespace: flux-system + install: + remediation: + retries: 3 + upgrade: + cleanupOnFail: true + remediation: + strategy: rollback + retries: 3 + values: + controllers: + dragonfly-operator: + replicas: 1 + strategy: RollingUpdate + containers: + app: + image: + repository: ghcr.io/dragonflydb/operator + tag: v1.1.2@sha256:f0d76725950095ac65b36252e0042d339d1db9b181b1d068f4b6686ea93055e4 + command: ["/manager"] + args: + - --health-probe-bind-address=:8081 + - --metrics-bind-address=:8080 + probes: + liveness: + enabled: true + custom: true + spec: + httpGet: + path: /healthz + port: &port 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + timeoutSeconds: 1 + failureThreshold: 3 + readiness: + enabled: true + custom: true + spec: + httpGet: + path: /readyz + port: *port + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + resources: + requests: + cpu: 10m + limits: + memory: 128Mi + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: { drop: ["ALL"] } + pod: + securityContext: + runAsUser: 65534 + runAsGroup: 65534 + runAsNonRoot: true + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + app.kubernetes.io/name: *app + service: + app: + controller: *app + ports: + http: + port: *port + metrics: + port: 8080 + serviceMonitor: + app: + serviceName: *app + endpoints: + - port: metrics + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + serviceAccount: + create: true + name: *app diff --git a/kubernetes/talos-flux/apps/database/dragonfly/operator/kustomization.yaml b/kubernetes/talos-flux/apps/database/dragonfly/operator/kustomization.yaml new file mode 100644 index 000000000..e95bd4210 --- /dev/null +++ b/kubernetes/talos-flux/apps/database/dragonfly/operator/kustomization.yaml @@ -0,0 +1,9 @@ +--- +# yaml-language-server: $schema=https://json.schemastore.org/kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + # renovate: datasource=github-releases depName=dragonflydb/dragonfly-operator + - https://raw.githubusercontent.com/dragonflydb/dragonfly-operator/v1.1.2/manifests/crd.yaml + - helm-release.yaml + - rbac.yaml diff --git a/kubernetes/talos-flux/apps/database/dragonfly/operator/rbac.yaml b/kubernetes/talos-flux/apps/database/dragonfly/operator/rbac.yaml new file mode 100644 index 000000000..6e1e09204 --- /dev/null +++ b/kubernetes/talos-flux/apps/database/dragonfly/operator/rbac.yaml @@ -0,0 +1,40 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: dragonfly-operator +rules: + - apiGroups: ["coordination.k8s.io"] + resources: ["leases"] + verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] + - apiGroups: [""] + resources: ["events"] + verbs: ["create", "patch"] + - apiGroups: [""] + resources: ["pods", "services"] + verbs: ["create", "delete", "get", "list", "patch", "update", "watch"] + - apiGroups: ["apps"] + resources: ["statefulsets"] + verbs: ["create", "delete", "get", "list", "patch", "update", "watch"] + - apiGroups: ["dragonflydb.io"] + resources: ["dragonflies"] + verbs: ["create", "delete", "get", "list", "patch", "update", "watch"] + - apiGroups: ["dragonflydb.io"] + resources: ["dragonflies/finalizers"] + verbs: ["update"] + - apiGroups: ["dragonflydb.io"] + resources: ["dragonflies/status"] + verbs: ["get", "patch", "update"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: dragonfly-operator +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: dragonfly-operator +subjects: + - kind: ServiceAccount + name: dragonfly-operator + namespace: database diff --git a/kubernetes/talos-flux/apps/database/kustomization.yaml b/kubernetes/talos-flux/apps/database/kustomization.yaml index 5d9fa2b33..ca7c80fe2 100644 --- a/kubernetes/talos-flux/apps/database/kustomization.yaml +++ b/kubernetes/talos-flux/apps/database/kustomization.yaml @@ -5,4 +5,5 @@ kind: Kustomization resources: - ./namespace.yaml - ./cloudnative-pg/flux-sync.yaml + - ./dragonfly/flux-sync.yaml - ./redis/flux-sync.yaml