Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b04ab52fd2 | ||
|
|
ff2b565677 | ||
|
|
4b22f4ad11 | ||
|
|
020b277a04 | ||
|
|
ba53cbc465 |
+115
-1
@@ -19,6 +19,10 @@ const letsencryptEmail = config.requireSecret("letsencryptEmail");
|
||||
const kubeVipAddress = config.requireSecret("kubeVipAddress");
|
||||
const kubeVipInterface = config.require("kubeVipInterface");
|
||||
|
||||
const domain = config.requireSecret("domain");
|
||||
const longhornUiUser = config.requireSecret("longhornUiUser");
|
||||
const longhornUiPassword = config.requireSecret("longhornUiPassword");
|
||||
|
||||
const k8sProvider = new k8s.Provider("k3s", { kubeconfig });
|
||||
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
|
||||
provider: k8sProvider,
|
||||
@@ -134,15 +138,61 @@ const longhorn = new k8s.helm.v3.Release(
|
||||
version: "1.12.0",
|
||||
values: {
|
||||
defaultSettings: {
|
||||
defaultReplicaCount: 2,
|
||||
defaultReplicaCount: 3,
|
||||
nodeDownPodDeletionPolicy: "delete-both-statefulset-and-deployment-pod",
|
||||
createDefaultDiskLabeledNodes: true,
|
||||
orphanResourceAutoDeletion: "replica-data;instance",
|
||||
// Longhorn's recommendation for dedicated disks (longhorn-extra).
|
||||
// Docs: https://longhorn.io/docs/1.12.0/best-practices/
|
||||
storageMinimalAvailablePercentage: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
opts(),
|
||||
);
|
||||
|
||||
// Purges system snapshots, which can otherwise grow to a full volume's size
|
||||
// on every replica. Docs:
|
||||
// https://longhorn.io/docs/1.12.0/snapshots-and-backups/scheduling-backups-and-snapshots/
|
||||
new k8s.apiextensions.CustomResource(
|
||||
"longhorn-snapshot-cleanup",
|
||||
{
|
||||
apiVersion: "longhorn.io/v1beta2",
|
||||
kind: "RecurringJob",
|
||||
metadata: { name: "snapshot-cleanup", namespace: "longhorn-system" },
|
||||
spec: {
|
||||
name: "snapshot-cleanup",
|
||||
task: "snapshot-cleanup",
|
||||
cron: "30 3 * * *",
|
||||
groups: ["default"],
|
||||
retain: 0,
|
||||
concurrency: 1,
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [longhorn] }),
|
||||
);
|
||||
|
||||
// Returns blocks deleted inside a volume (e.g. expired Prometheus data) to the
|
||||
// disk. Runs after snapshot-cleanup, since trim can't reclaim valid snapshots.
|
||||
// Docs: https://longhorn.io/docs/1.12.0/nodes-and-volumes/volumes/trim-filesystem/
|
||||
new k8s.apiextensions.CustomResource(
|
||||
"longhorn-filesystem-trim",
|
||||
{
|
||||
apiVersion: "longhorn.io/v1beta2",
|
||||
kind: "RecurringJob",
|
||||
metadata: { name: "filesystem-trim", namespace: "longhorn-system" },
|
||||
spec: {
|
||||
name: "filesystem-trim",
|
||||
task: "filesystem-trim",
|
||||
cron: "30 4 * * *",
|
||||
groups: ["default"],
|
||||
retain: 0,
|
||||
concurrency: 1,
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [longhorn] }),
|
||||
);
|
||||
|
||||
// Patches Longhorn instances to use the mountend Longhorn storage on the worker nodes.
|
||||
["k3s-worker-1", "k3s-worker-2", "k3s-worker-3"].forEach(
|
||||
(nodeName) =>
|
||||
@@ -174,6 +224,70 @@ const longhorn = new k8s.helm.v3.Release(
|
||||
),
|
||||
);
|
||||
|
||||
// ── Longhorn UI ───────────────────────────────────────────────────────────
|
||||
// Docs: https://longhorn.io/docs/1.12.0/deploy/accessing-the-ui/longhorn-ingress-traefik/
|
||||
// https://doc.traefik.io/traefik/reference/routing-configuration/http/middlewares/basicauth/
|
||||
|
||||
const longhornUiAuthSecret = new k8s.core.v1.Secret(
|
||||
"longhorn-ui-basic-auth",
|
||||
{
|
||||
metadata: { name: "longhorn-ui-basic-auth", namespace: "longhorn-system" },
|
||||
type: "kubernetes.io/basic-auth",
|
||||
stringData: { username: longhornUiUser, password: longhornUiPassword },
|
||||
},
|
||||
opts({ dependsOn: [longhorn] }),
|
||||
);
|
||||
|
||||
// Fixed name: the Ingress references it as <namespace>-<name>@kubernetescrd.
|
||||
const longhornUiAuth = new k8s.apiextensions.CustomResource(
|
||||
"longhorn-ui-auth",
|
||||
{
|
||||
apiVersion: "traefik.io/v1alpha1",
|
||||
kind: "Middleware",
|
||||
metadata: { name: "longhorn-ui-auth", namespace: "longhorn-system" },
|
||||
spec: { basicAuth: { secret: longhornUiAuthSecret.metadata.name } },
|
||||
},
|
||||
opts(),
|
||||
);
|
||||
|
||||
const longhornUiHost = pulumi.interpolate`longhorn.${domain}`;
|
||||
|
||||
new k8s.networking.v1.Ingress(
|
||||
"longhorn-ui",
|
||||
{
|
||||
metadata: {
|
||||
name: "longhorn-ui",
|
||||
namespace: "longhorn-system",
|
||||
annotations: {
|
||||
"cert-manager.io/cluster-issuer": "letsencrypt-prod",
|
||||
"traefik.ingress.kubernetes.io/router.middlewares":
|
||||
"longhorn-system-longhorn-ui-auth@kubernetescrd",
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
ingressClassName: "traefik",
|
||||
tls: [{ hosts: [longhornUiHost], secretName: "longhorn-ui-tls" }],
|
||||
rules: [
|
||||
{
|
||||
host: longhornUiHost,
|
||||
http: {
|
||||
paths: [
|
||||
{
|
||||
path: "/",
|
||||
pathType: "Prefix",
|
||||
backend: {
|
||||
service: { name: "longhorn-frontend", port: { number: 80 } },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [longhorn, longhornUiAuth] }),
|
||||
);
|
||||
|
||||
// ── kube-vip ────────────
|
||||
|
||||
const kubeVipNamespace = "kube-system";
|
||||
|
||||
Reference in new issue
Block a user