Files
homelab-infrastructure-as-code/04-k8s-apps/index.ts
T
kasun dd6fa942cb
Deploy Proxmox Infra / Pulumi Preview (pull_request) Successful in 1m8s
Deploy Proxmox Infra / Pulumi Deploy (pull_request) Has been skipped
Deploy k8s Infra / Pulumi Preview (pull_request) Successful in 53s
Deploy k8s Infra / Pulumi Deploy (pull_request) Has been skipped
Deploy k8s Apps / Pulumi Preview (pull_request) Failing after 7s
Deploy k8s Apps / Pulumi Deploy (pull_request) Has been skipped
added secret
2026-06-06 04:33:16 +02:00

134 lines
3.0 KiB
TypeScript

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
const config = new pulumi.Config();
//fetch credentials from k8s-bootstrap
const bootstrapRef = new pulumi.StackReference(
`${pulumi.getOrganization()}/k8s-bootstrap/dev`,
);
const kubeconfig = bootstrapRef.requireOutput("kubeconfig");
const domain = config.requireSecret("domain");
const k8sProvider = new k8s.Provider("k3s", { kubeconfig });
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
provider: k8sProvider,
...extras,
});
const ns = new k8s.core.v1.Namespace(
"heimdall",
{ metadata: { name: "heimdall" } },
opts(),
);
const pvc = new k8s.core.v1.PersistentVolumeClaim(
"heimdall-config",
{
metadata: { name: "heimdall-config", namespace: ns.metadata.name },
spec: {
accessModes: ["ReadWriteOnce"],
storageClassName: "longhorn",
resources: { requests: { storage: "50Mi" } },
},
},
opts(),
);
const labels = { app: "heimdall" };
new k8s.apps.v1.Deployment(
"heimdall",
{
metadata: {
name: "heimdall",
namespace: ns.metadata.name,
annotations: { "pulumi.com/patchForce": "true" },
},
spec: {
replicas: 1,
selector: { matchLabels: labels },
template: {
metadata: { labels },
spec: {
containers: [
{
name: "heimdall",
image: "lscr.io/linuxserver/heimdall:latest",
env: [
{ name: "PUID", value: "1000" },
{ name: "PGID", value: "1000" },
],
ports: [{ containerPort: 80 }],
volumeMounts: [{ name: "config", mountPath: "/config" }],
},
],
volumes: [
{
name: "config",
persistentVolumeClaim: { claimName: pvc.metadata.name },
},
],
terminationGracePeriodSeconds: 5,
},
},
},
},
opts(),
);
const svc = new k8s.core.v1.Service(
"heimdall",
{
metadata: { name: "heimdall", namespace: ns.metadata.name },
spec: {
selector: labels,
ports: [{ port: 80, targetPort: 80 }],
type: "ClusterIP",
},
},
opts(),
);
const host = pulumi.interpolate`heimdall.${domain}`;
new k8s.networking.v1.Ingress(
"heimdall",
{
metadata: {
name: "heimdall",
namespace: ns.metadata.name,
annotations: {
"cert-manager.io/cluster-issuer": "letsencrypt-prod",
},
},
spec: {
ingressClassName: "traefik",
tls: [{ hosts: [host], secretName: "heimdall-tls" }],
rules: [
{
host,
http: {
paths: [
{
path: "/",
pathType: "Prefix",
backend: {
service: {
name: svc.metadata.name,
port: { number: 80 },
},
},
},
],
},
},
],
},
},
opts(),
);
export const ingressHost = host;