diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml index 43f541d..4d74712 100644 --- a/kubernetes/deployment.yaml +++ b/kubernetes/deployment.yaml @@ -35,15 +35,17 @@ spec: - containerPort: 3000 livenessProbe: httpGet: - path: /login + path: /healthz port: 3000 initialDelaySeconds: 5 periodSeconds: 15 + failureThreshold: 3 readinessProbe: httpGet: - path: /login + path: /healthz port: 3000 initialDelaySeconds: 3 periodSeconds: 5 + failureThreshold: 2 imagePullSecrets: - name: github-container-registry diff --git a/src/hooks.server.ts b/src/hooks.server.ts index cfb19c3..9191376 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -101,6 +101,11 @@ function apiUnreachablePage(): Response { } export const handle: Handle = async ({ event, resolve }) => { + // Let Kubernetes health probes pass without hitting the external API + if (event.url.pathname === "/healthz") { + return await resolve(event); + } + // Health-check the API before doing anything else. // /v1/teapot returns 418 when the API is alive. try { diff --git a/src/routes/healthz/+server.ts b/src/routes/healthz/+server.ts new file mode 100644 index 0000000..ee32eb8 --- /dev/null +++ b/src/routes/healthz/+server.ts @@ -0,0 +1,8 @@ +import type { RequestHandler } from "./$types"; + +export const GET: RequestHandler = async () => { + return new Response(JSON.stringify({ status: "ok" }), { + status: 200, + headers: { "Content-Type": "application/json" }, + }); +};