Search code examples
bashkubernetesapple-m1

curl command not working on M1 bash command line


currently busy learning kubernetes and running configs on the command line, and I'm using an M1 MacOS running on version 11.5.1, and one of the commands I wanted to run is curl "http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy" but I get the below error message curl: (3) URL using bad/illegal format or missing URL. Not sure if anyone has experienced this issue before, would appreciate the help.


Solution

  • First, curl command should receive only 1 host, not multiple hosts. Therefore pod should be single.

    Then, you need to save POD's name to a variable without any special characters.

    Last, when you're using kubectl proxy, you need to add -L option to the curl command so it will follow the redirection.

    Simple example will be:

    # run pod with echo image
    kubectl run echo --image=mendhak/http-https-echo
    
    # start proxy
    kubectl proxy
    
    # export pod's name
    export POD_NAME=echo
    
    # curl with `-I` - headers and `-L` - follow redirects
    curl -IL http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy
    HTTP/1.1 301 Moved Permanently
    Location: /api/v1/namespaces/default/pods/echo/proxy/
    
    HTTP/1.1 200 OK