Deploys depended on master-1 being up. A fixed clusterIdentifier lets the provider move to the VIP as an update, because Pulumi otherwise treats a new API address as a different cluster and replaces every resource. The identifier was added to the stack state first so this change does not itself trigger a replacement.
154 lines
3.7 KiB
TypeScript
154 lines
3.7 KiB
TypeScript
import * as pulumi from "@pulumi/pulumi";
|
|
import * as k8s from "@pulumi/kubernetes";
|
|
|
|
const config = new pulumi.Config();
|
|
|
|
const bootstrapRef = new pulumi.StackReference(
|
|
`${pulumi.getOrganization()}/k8s-bootstrap/dev`,
|
|
);
|
|
|
|
const kubeconfig = bootstrapRef.requireOutput("kubeconfig");
|
|
export const domain = config.requireSecret("domain");
|
|
|
|
// A fixed identifier makes kubeconfig changes (e.g. a new API address) provider
|
|
// updates. Without it, they replace the provider and every resource in this
|
|
// stack. Changing this value triggers that replacement, so never change it.
|
|
const k8sProvider = new k8s.Provider("k3s", {
|
|
kubeconfig,
|
|
clusterIdentifier: "homelab-k3s",
|
|
});
|
|
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
|
|
provider: k8sProvider,
|
|
...extras,
|
|
});
|
|
|
|
const heimdallNs = new k8s.core.v1.Namespace(
|
|
"heimdall",
|
|
{ metadata: { name: "heimdall" } },
|
|
opts(),
|
|
);
|
|
|
|
const pvc = new k8s.core.v1.PersistentVolumeClaim(
|
|
"heimdall-config",
|
|
{
|
|
metadata: { name: "heimdall-config", namespace: heimdallNs.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: heimdallNs.metadata.name,
|
|
annotations: { "pulumi.com/patchForce": "true" },
|
|
},
|
|
spec: {
|
|
replicas: 1,
|
|
strategy: { type: "Recreate" },
|
|
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,
|
|
tolerations: [
|
|
{
|
|
key: "node.kubernetes.io/unreachable",
|
|
operator: "Exists",
|
|
effect: "NoExecute",
|
|
tolerationSeconds: 30,
|
|
},
|
|
{
|
|
key: "node.kubernetes.io/not-ready",
|
|
operator: "Exists",
|
|
effect: "NoExecute",
|
|
tolerationSeconds: 30,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
opts(),
|
|
);
|
|
|
|
const svc = new k8s.core.v1.Service(
|
|
"heimdall",
|
|
{
|
|
metadata: { name: "heimdall", namespace: heimdallNs.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: heimdallNs.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;
|