Using python manage.py migrate --check in kubernetes readinessProbe never succeeds

I have a django deployment on kubernetes cluster and in the readinessProbe, I am running python, manage.py, migrate, --check. I can see that the return value of this command is 0 but the pod never becomes ready.

Snippet of my deployment:

      containers:                                                                             
        - name: myapp                                                                      
          ...
          imagePullPolicy: Always                                                             
          readinessProbe:                                                                     
            exec:                                                                             
              command: ["python", "manage.py", "migrate", "--check"]                          
            initialDelaySeconds: 15                                                           
            periodSeconds: 5  

When I describe the pod which is not yet ready:

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  66s                default-scheduler  Successfully assigned ...  Normal   Pulled     66s                kubelet            Successfully pulled image ...
  Normal   Created    66s                kubelet            Created container ...
  Normal   Started    66s                kubelet            Started container ...
  Warning  Unhealthy  5s (x10 over 50s)  kubelet            Readiness probe failed:

I can see that migrate --check returns 0 by execing into the container which is still in not ready state and running

python manage.py migrate
echo $?
0

Is there something wrong in my exec command passed as readinessProbe?

The version of kubernetes server that I am using is 1.21.7. The base image for my deployment is python:3.7-slim.


Solution 1:

The solution for the issue is to increase timeoutSeconds parameter, which is by default set to 1 second:

  • timeoutSeconds: Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1.

After increasing the timeoutSeconds parameter, the application is able to pass the readiness probe.

Example snippet of the deployment with timeoutSeconds parameter set to 5:

      containers:                                                                             
        - name: myapp                                                                      
          ...
          imagePullPolicy: Always                                                             
          readinessProbe:                                                                     
            exec:                                                                             
              command: ["python", "manage.py", "migrate", "--check"]                          
            initialDelaySeconds: 15                                                           
            periodSeconds: 5
            timeoutSeconds: 5