RestTemplate exchange call gives 503 error when running in Docker container at Kubernetes environment

My Spring Boot application runs fine when I run on the server as traditional way.
But, when I create a Docker image with this app and run the container at Kubernetes environment, I get “503 Service Unavailable” error back when the app makes RestTemplate call.

Here is the code snipped where the call is made:

  • Docker - Running Postgres Scripts inside Container
  • “debconf: delaying package configuration, since apt-utils is not installed” :> google notebooks bash error
  • Installing docker with devstack
  • How to make communication between two docker containers running on two different hosts?
  • How do you set up an elastic search cluster with multiple master nodes in docker compose?
  • docker-compose oci runtime error starting container process caused connection reset by peer
  • import org.springframework.core.ParameterizedTypeReference;
    import org.springframework.http.HttpEntity;
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpMethod;
    import org.springframework.http.ResponseEntity;
    import org.springframework.web.client.RestTemplate;
    
    ...
    
    private boolean isActiveUserExist(String userId, String password) {
    
        String restUrl = "http://10.3.0.176:8888/persons/application_id";
    
        HttpHeaders headers = new HttpHeaders();
        headers.add("Authorization", "Basic "+ Utils.base64Creds(userId, password));
        HttpEntity<String> request = new HttpEntity<String>(headers);
    
        //construct the URL with Request Parameters parameters    
        try {
          restUrl = restUrl + "?userId=" + java.net.URLEncoder.encode(userId, "UTF-8");
        } catch (UnsupportedEncodingException e) {
          log.error(e.getMessage());
          throw e;
        }
        restUrl = restUrl + "&applicationPk=1"; //primarykey for this app
    
        log.debug("Rest URL to check user <{}>.", restUrl);
    
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<Person> response = null;
    
        try{
    
          response = restTemplate.exchange(restUrl, HttpMethod.GET, request, 
              new ParameterizedTypeReference<Person>() {
          });
        } catch (Exception e) {
          log.error("Rest URL to check user returns error {}.", e.getMessage());
          throw e;
        }
    
        Person person = response.getBody();
        log.debug("isActiveUserExist({}) returns: {}",userId,person);
    
        return  ( person != null ) ;
    }    
    ...
    

    Do you see any reason why RestTemplate.exchange call would not work and return 503 when it runs in the Docker Container at Kubernetes?

  • After deployment of WAR to tomcat docker container always getting 404
  • Docker Remote CA Verification
  • Workflow for building, pushing, and testing Docker images inside GKE / Kubernetes
  • asp-net 1.0, Docker and Kubernetes
  • kube-dns not working on kubernetes arm
  • Docker for Windows not working
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.