0 I was doing the tutorial for using kubernetes (one of the ones in kubernetes.io) and it tells you to use: export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}') I had to remove the "export" for it to work in windows (also had to remove the line break for some reason, but it worked after that), so the command was: $POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{end}}') It worked, and if I typed: $POD_NAME I got the correct pod name. The problem came from the next step where I had to use: curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME:8080/proxy/ Here, it was unable to resolve the url, while if I just replaced $POD_NAME with the text in the variable, it worked just fine. I was wondering if there is a way to make it work (as in making the variable name be substituted by it's content when interpreting the command). Not sure if it helps, but this is the error message: curl : { "kind": "Status", "apiVersion": "v1", "metadata": {}, "status": "Failure", "message": "pods "proxy" not found", "reason": "NotFound", "details": { "name": "proxy", "kind": "pods" }, "code": 404 } En línea: 1 Carácter: 1 + curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME:8 ... + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands. I see what's happening here. When you use $POD_NAME in the curl command, it isn't getting replaced by its value. This issue often arises from how the shell handles variable interpolation.
In PowerShell, which it looks like you might be using, you need to use different syntax for variable interpolation. Here’s how you can make it work:
$POD_NAME = $(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{end}}') curl "http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME:8080/proxy/"