mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-05-30 18:20:38 +02:00
feat: kubevirt on k3s
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .victoria_metrics import *
|
||||
@@ -1,28 +0,0 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
|
||||
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
|
||||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
||||
)
|
||||
|
||||
func NewMonitoring(ctx *pulumi.Context, env string) error {
|
||||
// Create a Kubernetes Namespace
|
||||
namespaceName := "monitoring"
|
||||
namespace, err := corev1.NewNamespace(ctx, namespaceName, &corev1.NamespaceArgs{
|
||||
Metadata: &metav1.ObjectMetaArgs{
|
||||
Name: pulumi.String(namespaceName),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Export the name of the namespace
|
||||
ctx.Export("monitoringNamespaceName", namespace.Metadata.Name())
|
||||
|
||||
if err := NewVictoriaMetrics(ctx, env, namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import pulumi
|
||||
import pulumi_kubernetes as kubernetes
|
||||
|
||||
from pathlib import Path
|
||||
import yaml
|
||||
|
||||
config = pulumi.Config()
|
||||
k8s_namespace = "monitoring"
|
||||
app_labels = {
|
||||
"app": "monitoring",
|
||||
}
|
||||
|
||||
victoriaMetricsvaluesPath = Path(__file__).parent / "victoria_metrics_helm_values.yml"
|
||||
|
||||
# Create a namespace (user supplies the name of the namespace)
|
||||
monitoring_ns = kubernetes.core.v1.Namespace(
|
||||
"monitoring",
|
||||
metadata=kubernetes.meta.v1.ObjectMetaArgs(
|
||||
labels=app_labels,
|
||||
name=k8s_namespace,
|
||||
),
|
||||
)
|
||||
|
||||
# https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-k8s-stack
|
||||
victoriaMetrics = kubernetes.helm.v3.Release(
|
||||
"victoria-metrics-k8s-stack",
|
||||
chart="victoria-metrics-k8s-stack",
|
||||
namespace=monitoring_ns.metadata.name,
|
||||
repository_opts=kubernetes.helm.v3.RepositoryOptsArgs(
|
||||
repo="https://victoriametrics.github.io/helm-charts/",
|
||||
),
|
||||
version="0.19.2",
|
||||
skip_crds=False,
|
||||
atomic=True, # purges chart on fail
|
||||
cleanup_on_fail=True, # Allow deletion of new resources created in this upgrade when upgrade fails.
|
||||
dependency_update=True, # run helm dependency update before installing the chart
|
||||
reset_values=True, # When upgrading, reset the values to the ones built into the chart
|
||||
# verify=True, # verify the package before installing it
|
||||
# recreate_pods=True, # performs pods restart for the resource if applicable
|
||||
value_yaml_files=[pulumi.FileAsset(victoriaMetricsvaluesPath)],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-k8s-stack
|
||||
#
|
||||
# Pulumi will complain ` ValueError: unexpected input of type set` if some values are not available in helm chart!
|
||||
grafana:
|
||||
enabled: true
|
||||
defaultDashboardsTimezone: utc+8
|
||||
ingress:
|
||||
enabled: true
|
||||
hosts:
|
||||
- k8s-grafana.writefor.fun
|
||||
persistence:
|
||||
type: pvc
|
||||
enabled: false
|
||||
kube-state-metrics:
|
||||
enabled: true
|
||||
prometheus-node-exporter:
|
||||
# install node exporter via nixos, not container
|
||||
enabled: false
|
||||
vmagent:
|
||||
# vmagent collects metrics from targets and sends them to a remote storage
|
||||
enabled: true
|
||||
vmalert:
|
||||
# vmalert is a Prometheus-compatible alertmanager
|
||||
enabled: true
|
||||
vmsingle:
|
||||
# Single-node VictoriaMetrics for storing metrics.
|
||||
# https://docs.victoriametrics.com/faq/#which-victoriametrics-type-is-recommended-for-use-in-production---single-node-or-cluster
|
||||
# vmsingle = vmcluster(vmselect + vmstorage + vminsert)
|
||||
enabled: true
|
||||
ingress:
|
||||
hosts:
|
||||
- vm.writefor.fun
|
||||
spec:
|
||||
storage:
|
||||
resources:
|
||||
requests:
|
||||
storage: 50Gi
|
||||
@@ -1,85 +0,0 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
|
||||
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/helm/v3"
|
||||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
||||
)
|
||||
|
||||
func NewVictoriaMetrics(ctx *pulumi.Context, env string, namespace corev1.Namespace) error {
|
||||
var opts []pulumi.ResourceOption
|
||||
opts = append(opts, pulumi.DependsOn([]pulumi.Resource{namespace}))
|
||||
|
||||
// https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-k8s-stack
|
||||
_, err := helm.NewChart(ctx, "victoria-metrics-k8s-stack", helm.ChartArgs{
|
||||
Chart: pulumi.String("victoria-metrics-k8s-stack"),
|
||||
Version: pulumi.String("0.19.0"),
|
||||
Namespace: pulumi.String(namespace.Metadata.Name()),
|
||||
FetchArgs: helm.FetchArgs{
|
||||
Repo: pulumi.String("https://victoriametrics.github.io/helm-charts/"),
|
||||
},
|
||||
// https://github.com/VictoriaMetrics/helm-charts/blob/master/charts/victoria-metrics-k8s-stack/README.md
|
||||
Values: pulumi.Map{
|
||||
// grafana.ingress.enabled: true
|
||||
"ingress": pulumi.Map{
|
||||
"enabled": pulumi.Bool(true),
|
||||
},
|
||||
// grafana.defaultDashboardsTimezone: utc+8
|
||||
// grafana.ingress.hosts[0].host: grafana.example.com
|
||||
"grafana": pulumi.Map{
|
||||
"defaultDashboardsTimezone": pulumi.String("utc+8"),
|
||||
"ingress": pulumi.Map{
|
||||
"hosts": pulumi.Array{
|
||||
pulumi.Map{
|
||||
"host": pulumi.String("k8s-grafana.writefor.fun"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// prometheus-node-exporter.enabled: false
|
||||
"nodeExporter": pulumi.Map{
|
||||
"enabled": pulumi.Bool(false),
|
||||
},
|
||||
"vmsingle": pulumi.Map{
|
||||
"enabled": pulumi.Bool(true),
|
||||
"ingress": pulumi.Map{
|
||||
"hosts": pulumi.Array{
|
||||
pulumi.Map{
|
||||
"host": pulumi.String("vm.writefor.fun"),
|
||||
},
|
||||
},
|
||||
},
|
||||
// https://docs.victoriametrics.com/operator/api/#vmsinglespec
|
||||
"spec": pulumi.Map{
|
||||
"affinity": pulumi.Map{
|
||||
"nodeAffinity": pulumi.Map{
|
||||
"requiredDuringSchedulingIgnoredDuringExecution": pulumi.Map{
|
||||
"nodeSelectorTerms": pulumi.Array{
|
||||
pulumi.Map{
|
||||
"matchExpressions": pulumi.Array{
|
||||
pulumi.Map{
|
||||
"key": pulumi.String("kubernetes.io/arch"),
|
||||
"operator": pulumi.String("In"),
|
||||
"values": pulumi.Array{
|
||||
pulumi.String("amd64"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"storage": pulumi.Map{
|
||||
"resources": pulumi.Map{
|
||||
"requests": pulumi.Map{
|
||||
"storage": pulumi.String("50Gi"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, opts...)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user