use traefik ingressroute for runtime ingress

This commit is contained in:
2026-07-02 17:14:34 +09:00
parent 4e819ab6de
commit fa478b45b3
+36 -37
View File
@@ -484,10 +484,12 @@ export class AppsService {
); );
} }
logs.push(`[apply] ingress/${ingressName}`); await this.deleteLegacyIngress(logs, namespace, ingressName);
logs.push(`[apply] ingressroute/${ingressName}`);
appendOutput( appendOutput(
logs, logs,
await this.applyK8sManifest(createIngressManifest({ await this.applyK8sManifest(createTraefikIngressRouteManifest({
namespace, namespace,
name: ingressName, name: ingressName,
host: rule.host, host: rule.host,
@@ -1113,10 +1115,12 @@ export class AppsService {
); );
} }
logs.push(`[apply] ingress/${ingressName}`); await this.deleteLegacyIngress(logs, namespace, ingressName);
logs.push(`[apply] ingressroute/${ingressName}`);
appendOutput( appendOutput(
logs, logs,
await this.applyK8sManifest(createIngressManifest({ await this.applyK8sManifest(createTraefikIngressRouteManifest({
namespace, namespace,
name: ingressName, name: ingressName,
host: rule.host, host: rule.host,
@@ -1345,6 +1349,16 @@ export class AppsService {
} }
} }
private async deleteLegacyIngress(logs: string[], namespace: string, name: string) {
try {
const output = await this.kubectl(['delete', 'ingress', name, '-n', namespace, '--ignore-not-found=true']);
if (output.trim()) appendOutput(logs, output);
} catch (error) {
const message = error instanceof Error ? error.message : 'delete legacy ingress failed';
logs.push(`[warn] legacy ingress/${name} 정리는 건너뜀: ${message}`);
}
}
private async applyDatabaseResources(input: { private async applyDatabaseResources(input: {
namespace: string; namespace: string;
appKey: string; appKey: string;
@@ -2086,7 +2100,7 @@ function createServiceManifest(input: {
}; };
} }
function createIngressManifest(input: { function createTraefikIngressRouteManifest(input: {
namespace: string; namespace: string;
name: string; name: string;
host: string; host: string;
@@ -2097,51 +2111,36 @@ function createIngressManifest(input: {
tlsEnabled: boolean; tlsEnabled: boolean;
tlsSecretName?: string | null; tlsSecretName?: string | null;
}) { }) {
const annotations: Record<string, string> = {};
if (input.middlewareName) {
annotations['traefik.ingress.kubernetes.io/router.middlewares'] = `${input.namespace}-${input.middlewareName}@kubernetescrd`;
}
const manifest: Record<string, unknown> = { const manifest: Record<string, unknown> = {
apiVersion: 'networking.k8s.io/v1', apiVersion: 'traefik.io/v1alpha1',
kind: 'Ingress', kind: 'IngressRoute',
metadata: { metadata: {
name: input.name, name: input.name,
namespace: input.namespace, namespace: input.namespace,
labels: getManagedLabels(input.name, 'ingress'), labels: getManagedLabels(input.name, 'ingressroute'),
...(Object.keys(annotations).length > 0 ? { annotations } : {}),
}, },
spec: { spec: {
rules: [ entryPoints: [input.tlsEnabled ? 'websecure' : 'web'],
routes: [
{ {
host: input.host, match: `Host(\`${input.host}\`) && PathPrefix(\`${input.path}\`)`,
http: { kind: 'Rule',
paths: [ ...(input.middlewareName ? { middlewares: [{ name: input.middlewareName }] } : {}),
{ services: [
path: input.path, {
pathType: 'Prefix', name: input.serviceName,
backend: { port: input.servicePort,
service: { },
name: input.serviceName, ],
port: { number: input.servicePort },
},
},
},
],
},
}, },
], ],
}, },
}; };
if (input.tlsEnabled && input.tlsSecretName) { if (input.tlsEnabled && input.tlsSecretName) {
(manifest.spec as Record<string, unknown>).tls = [ (manifest.spec as Record<string, unknown>).tls = {
{ secretName: input.tlsSecretName,
hosts: [input.host], };
secretName: input.tlsSecretName,
},
];
} }
return manifest; return manifest;