How to Troubleshoot Kubernetes Service 503 error(Service Unavailable)

FoxuTech
3 min readApr 25, 2023

--

The HTTP 503 Service Unavailable error means that a website cannot be reached now because the server is not ready to handle the request. This could happen because it’s too busy, under maintenance, or something else which requires a deeper analysis.

In Kubernetes, it means a Service tried to route a request to a pod, but something went wrong along the way:

  • The Service could not find any pods matching its selector.
  • The Service found some pods matching the selector, but none of them were Running.
  • Pods are running but were removed from the Service endpoint because they did not pass the readiness probe.
  • Some other networking or configuration issue prevented the Service from connecting with the pods.

Running into errors on your site can be intimidating. However, most errors give you some hint as to what could cause them, which can helps to troubleshooting these issues in right way. The 503 error is not as polite, unfortunately, and does not give you much information to go on.

In this article, we have listed possible issue which cause 503 error and how you can troubleshoot the issue.

What Is an HTTP Error 503?

The Internet Engineering Task Force (IETF) defines the 503 Service Unavailable as:

The 503 (Service Unavailable) status code indicates that the server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay. The server MAY send a Retry-After header field to suggest an appropriate amount of time for the client to wait before retrying the request.

Troubleshooting Kubernetes Service 503 Errors

Fix 1: Check if the Pod Label Matches the Service Selector

A possible cause of 503 errors is that a Kubernetes pod does not have the expected label, and the Service selector does not identify it. If the Service does not find any matching pod, requests will return a 503 error.

Run the following command to see the current selector:

# kubectl describe service [service-name] -n [namespace-name]

Example output:

Name: [service-name]
Namespace: [pod-name]
Labels: none
Annotations: none
Selector: [label]

Note: Replace service_name with your service name and your_namespace with your service namespace.

The Selector section shows which label or labels are used to match the Service with pods.

Check if there are pods with this label:

# kubectl get pods -n your_namespace -l “[label]”
  • If you get the message no resources found — it is a reason the Service cannot discover any pods, and clients gets a HTTP 503 error. Add the label to some pods to resolve the problem.
  • If there are pods with the required label — continue to the next solution.

Fix 2: Verify that Pods Defined for the Service are Running

In step 1 we checked the label which is used by Service selector. Run the following command to ensure the pods matched by the selector are in Running state:

# kubectl -n your_namespace get pods -l “[label]”
  • If the pod status is not Running — diagnose and resolve the error in your pod. There is could be various error it may show, you may need to understand and fix it. You can find some interesting troubleshooting from our previous articles.
  • If status is Running — proceed to the next solution.

Fix 3: Check Pods Pass the Readiness Probe for the Deployment

Next, we can check if a readiness probe is configured for the pod:

# kubectl describe pod pod-name -n namespace | grep -i readiness

This step provides helpful output only if the application is listening on the right path and port. Check the curl output with the curl -Ivk command, and make sure the path defined at the service level is getting a valid response. For example, 200 ms is a good response.

Readiness probe failed:

Read full article on https://foxutech.com/how-to-troubleshoot-kubernetes-service-503-errorservice-unavailable/

--

--

FoxuTech
FoxuTech

Written by FoxuTech

Discuss about #Linux, #DevOps, #Docker, #kubernetes, #HowTo’s, #cloud & IT technologies like #argocd #crossplane #azure https://foxutech.com/

No responses yet