The healthcheck step in your GitLab CI deployment job is failing because the target service isn’t responding to health probes within the configured timeout.

This usually means one of several things:

  • The application isn’t starting fast enough: The CI job’s healthcheck step has a default timeout (often 60 seconds). If your application, especially after a fresh deployment, takes longer than this to become ready and respond to its health endpoint, the check will fail.
    • Diagnosis: Check your application logs for startup errors or slow initialization. Examine the healthcheck configuration in your .gitlab-ci.yml to see the timeout value.
    • Fix: Increase the timeout in your healthcheck configuration. For example, if it’s set to 60s, try 120s:
      healthcheck:
        timeout: 120s
        interval: 10s
        retries: 5
      
      This gives your application more time to boot up before the CI job declares it unhealthy.
  • The healthcheck endpoint is misconfigured: The healthcheck step expects to hit a specific URL and port. If this isn’t correctly defined, or if the application is listening on a different interface/port than expected, the check will fail.
    • Diagnosis: Verify the url and port specified in your healthcheck configuration against your application’s actual listening address. Check application logs to see which address/port it’s binding to.
    • Fix: Correct the url or port in your .gitlab-ci.yml to match your application’s configuration. For instance, if your app listens on 0.0.0.0:8080 but your check is http://localhost:8000, update it:
      healthcheck:
        url: http://your-app-host:8080/health
        port: 8080 # Or omit if url includes port
      
      This ensures the CI runner is trying to connect to the correct network endpoint.
  • Firewall rules are blocking access: The GitLab Runner, executing the healthcheck, might be on a different network segment or in a different container than your deployed application. Network policies or firewalls could be preventing the runner from reaching the application’s health endpoint.
    • Diagnosis: Ensure that the network where your GitLab Runner is operating can reach the IP address and port of your deployed application. Tools like curl or telnet from the runner’s environment can test connectivity.
    • Fix: Adjust firewall rules or network policies to allow traffic from the GitLab Runner’s IP/network to the application’s health check port. For example, if using Kubernetes, update NetworkPolicies to permit ingress to the application’s pod on its health port.
  • The healthcheck endpoint itself is faulty: The code responsible for the /health (or whatever endpoint you’re using) endpoint might have a bug, or it might be too slow to respond, even if the rest of the application is running.
    • Diagnosis: Manually access the healthcheck URL from a machine that can reach your deployed service. If it returns errors, is slow, or hangs, the endpoint code needs fixing.
    • Fix: Debug and optimize the healthcheck endpoint logic within your application. Ensure it returns a quick, successful response (e.g., 200 OK with a simple JSON body) under normal operating conditions.
  • Resource exhaustion on the deployed instance: If your application is deployed to an environment with limited CPU or memory, it might be struggling to start up or respond to requests, including healthchecks.
    • Diagnosis: Monitor the resource utilization (CPU, memory) of your deployed application instance. Check application logs for signs of garbage collection pauses or out-of-memory errors.
    • Fix: Increase the resources allocated to your application’s deployment. This could involve scaling up the VM, increasing pod resource limits in Kubernetes, or optimizing application memory usage.
  • DNS resolution issues: The GitLab Runner might be unable to resolve the hostname of your deployed application.
    • Diagnosis: From the GitLab Runner’s environment, try to ping or curl the hostname of your application. If it fails to resolve, you have a DNS problem.
    • Fix: Ensure your GitLab Runner’s DNS configuration is correct and can resolve the internal or external DNS names of your deployed services. This might involve updating /etc/resolv.conf on the runner host or configuring DNS within your Kubernetes cluster.
  • Incorrect interval or retries: While less common as a primary cause of failure, these can exacerbate startup delays. If the interval is too short and retries are too few, the check might give up before the application has a real chance to recover.
    • Diagnosis: Review the interval and retries values in your healthcheck configuration.
    • Fix: Increase the interval and retries to give the system more chances to succeed. For example:
      healthcheck:
        timeout: 120s
        interval: 30s # Increased from 10s
        retries: 10 # Increased from 5
      
      This makes the health check more lenient during startup.

After fixing the underlying issue, the next error you might encounter is a deployment failure if the application starts but then immediately crashes due to a new bug introduced in the deployment.

Want structured learning?

Take the full Gitlab-ci course →