java icon indicating copy to clipboard operation
java copied to clipboard

Trying to execute into pod results in 500 Internal Server error

Open adityank11 opened this issue 9 months ago • 6 comments
trafficstars

java.net.ProtocolException: Expected HTTP 101 response but was '500 Internal Server Error'

I am trying to execute a script in each pod of my namespace.

public void checkPods() 
{
    try 
    {
        V1PodList podList = api.listNamespacedPod(this.namespace).execute();
        int threshold = 80;
        String[] cmd = {"bash", "-c", "exec df -h | awk '$5 > " + threshold + " {print}' 2>/dev/null"};
        
        for (V1Pod pod : podList.getItems()) {
            String podName = pod.getMetadata().getName();
            Exec exec = new Exec(this.apiClient);
            Process p = exec.exec(pod, cmd, true);
        }
    } 
    catch (ApiException | IOException e) {
        throw new RuntimeException("Error executing command in pods", e);
    }
}

The above code is always giving the correct output but not without this error being thrown multiple times first. How to solve this error?

adityank11 avatar Feb 11 '25 09:02 adityank11