Kubernetes readiness check keeps failing for NextJS app (On GCP).
Without the timeoutSeconds: 10
I get:
Readiness probe failed: Get "http://10.60.2.69:3000/api/healthcheck": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
So I assume the connection to the pod is successful.
When I include the timeout (after waiting a while) I am getting:
Timeout waiting for pod to become healthy in at least one of the NEG(s): [k8s1-8e09c...]. Marking condition "cloud.google.com/load-balancer-neg-ready" to True.
client-deployment.yaml
kind: Deployment
metadata:
name: client-deployment
spec:
replicas: 1
selector:
matchLabels:
app: client
template:
metadata:
labels:
app: client
spec:
containers:
- name: client
image: nodejsclient
readinessProbe:
httpGet:
path: /api/healthcheck
port: 3000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 10
failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
name: client-service
spec:
selector:
app: client
ports:
- name: client
protocol: TCP
port: 3000
targetPort: 3000
pages/api/healthchek.ts
export default function HealthPage (req: NextApiRequest, res: NextApiResponse){
res.status(200).json({status: 'OK'})
}
UPDATE: curl to the pod get a 200 response
UPDATE2: I tried different configurations for the readinessProbe, including deleting it, NULL value, root path, different flags/timeouts and command instead of HTTP. Additionally deleted and created ingress.
Everything had the same result. I did notice that I am also getting "Unable to determine the pod's node name", but I don't know if that is relevant.
The issue was in the nextjs app itself and not the deployment configuration. I disabled a redirect in the middleware.ts and now it is working.
The nextjs app worked without errors + responded with 200 on /api/healthcheck
, so I am still not sure why that caused an issue but the face stays the problem was resolved.