New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot port-forward app from kubernetes with command in documentation #1526

Closed
rothgar opened this Issue May 18, 2016 · 13 comments

Comments

Projects
None yet
6 participants
@rothgar
Contributor

rothgar commented May 18, 2016

I'm running weave scope in kubernetes and followed the documentation steps to get it running.

When trying to port forward weave scope to my localhost host using the command

kubectl port-forward $(kubectl get pod --selector=weavescope-component=weavescope-app -o jsonpath={.items..metadata.name}) 4040

It doesn't work because kubectl complains 'error: name cannot be provided when a selector is specified'
With debug output --v=9 it looks like the problem is in helpers.go line 107. I didn't dig into the code but wanted to raise the issue with documentation.

If I remove the output formatting -o jsonpath=... the command works and shows me the proper name. An alternative command could also be

kubectl port-forward $(kubectl get pod --selector=weavescope-component=weavescope-app | grep -v '^NAME' | awk '{print $1}' | head -n 1) 4040

obviously not as elegant but uses kubectl pod NAME instead of parsing the json.

I'm using kubernetes 1.2.3 with kubectl 1.2.3.

@tomwilkie tomwilkie added this to the 0.17.0 milestone Jun 24, 2016

@tomwilkie

This comment has been minimized.

Contributor

tomwilkie commented Jun 24, 2016

Hi @rothgar sorry for the delay in getting back to you!

I've just tried it and it worked for me:

Toms-MacBook-Pro:service twilkie$ kubectl version
Client Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.3", GitCommit:"882d296a99218da8f6b2a340eb0e81c69e66ecc7", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.4", GitCommit:"3eed1e3be6848b877ff80a93da3785d9034d0a4f", GitTreeState:"clean"}
Toms-MacBook-Pro:service twilkie$ kubectl create -f 'https://cloud.weave.works/launch/k8s/weavescope.yaml' --validate=false
replicationcontroller "weavescope-app" created
service "weavescope-app" created
daemonset "weavescope-probe" created
Toms-MacBook-Pro:service twilkie$ kubectl port-forward $(kubectl get pod --selector=weavescope-component=weavescope-app -o jsonpath={.items..metadata.name}) 4040
I0624 09:56:50.653731   85457 portforward.go:213] Forwarding from 127.0.0.1:4040 -> 4040
I0624 09:56:50.654230   85457 portforward.go:213] Forwarding from [::1]:4040 -> 4040
I0624 09:57:05.138140   85457 portforward.go:247] Handling connection for 4040

Would you mind pasting the equivalent output including your error?

Thanks
Tom

@nitin-amp

This comment has been minimized.

nitin-amp commented Jun 25, 2016

Not sure if others encountered this - I had a similar problem port-forwarding app to localhost using the command. The root cause was missing 'socat' on the nodes and installing it fixed the issue. It seems to be a known k8s issue (#19765).

kubectl 1.2.4/ k8s 1.2.4. 2-node (fedora23) vagrant setup on Mac OSX.

@tomwilkie

This comment has been minimized.

Contributor

tomwilkie commented Jun 25, 2016

@nitin-amp thanks for the input! I'll add a mention to the docs.

If you're having trouble accessing scope, you can set it up to use Weave Cloud; I've just opened a PR with instructions on how: #1611

@rothgar

This comment has been minimized.

Contributor

rothgar commented Jun 26, 2016

I'll have access to the nodes again on Monday and will try then.

@nitin-amp thanks for the tip about socat. I was able to port-forward once I changed the way the pod name was filtered.

@rothgar

This comment has been minimized.

Contributor

rothgar commented Jun 30, 2016

@tomwilkie Here's the output on my system

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.4", GitCommit:"3eed1e3be6848b877ff80a93da3785d9034d0a4f", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.4", GitCommit:"3eed1e3be6848b877ff80a93da3785d9034d0a4f", GitTreeState:"clean"}

$ kubectl create -f 'https://cloud.weave.works/launch/k8s/weavescope.yaml' --validate=false
replicationcontroller "weavescope-app" created
service "weavescope-app" created
daemonset "weavescope-probe" created

$ kubectl port-forward $(kubectl get pod --selector=weavescope-component=weavescope-app -o jsonpath={.items..metadata.name}) 4040
error: name cannot be provided when a selector is specified
error: at least 1 PORT is required for port-forward
See 'kubectl port-forward -h' for help and examples.
@tomwilkie

This comment has been minimized.

Contributor

tomwilkie commented Jun 30, 2016

Thanks @rothgar; could you try kubectl get pod --selector=weavescope-component=weavescope-app -o jsonpath={.items..metadata.name} and send me the output please?

@rothgar

This comment has been minimized.

Contributor

rothgar commented Jun 30, 2016

kubectl get pod --selector=weavescope-component=weavescope-app -o jsonpath={.items..metadata.name}
error: name cannot be provided when a selector is specified

@rade rade added chore and removed component/docs labels Jul 4, 2016

@2opremio 2opremio self-assigned this Jul 5, 2016

@2opremio

This comment has been minimized.

Collaborator

2opremio commented Jul 5, 2016

Not sure if others encountered this - I had a similar problem port-forwarding app to localhost using the command. The root cause was missing 'socat' on the nodes and installing it fixed the issue. It seems to be a known k8s issue (#19765).

Thanks for reporting it, but that's a different issue, for @rothgar the command to obtain the pod name is nor working.

@2opremio

This comment has been minimized.

Collaborator

2opremio commented Jul 5, 2016

@rothgar Can you still reproduce? I've tried with different kubectl versions (1.2.2, 1.2.3, 1.2.4) but still can't.

I can only reproduce it when providing an explicit name in the command line:

kubectl --kubeconfig=infra/local/kubeconfig get pod --selector=weavescope-component=weavescope-app foo
error: name cannot be provided when a selector is specified

So, could it be that your shell is somehow passing a name to kubectl? What shell are you using?

To be sure, can you try running the following?

$ printargs() { echo begin; for A in $@; do echo \'$A\'; done; echo end; }
$ echo kubectl port-forward $(printargs kubectl get pod --selector=weavescope-component=weavescope-app -o jsonpath={.items..metadata.name}) 4040
kubectl port-forward begin 'kubectl' 'get' 'pod' '--selector=weavescope-component=weavescope-app' '-o' 'jsonpath={.items..metadata.name}' end 4040

Maybe there's a configuration issue? Can you try removing the ~/.kube?

I am sure this entirely depends on the client since I can reproduce with:

kubectl -s doesntexist.local get pod --selector=weavescope-component=weavescope-app foo
error: name cannot be provided when a selector is specified
@rothgar

This comment has been minimized.

Contributor

rothgar commented Jul 6, 2016

I was upgrading to 1.3.0 and was going to test when @2opremio made me realize zsh has a built in to expand (usually numbers) inside { }
Just opened #1651 with quotes to fix it. Tested on bash and zsh. Thanks for the help debugging everyone, sorry for the trouble.

@rothgar rothgar closed this Jul 6, 2016

@moneyit

This comment has been minimized.

moneyit commented Mar 24, 2017

I have issue with UI when run port-forward to localhost then use the nginx to access by hostname but it can not load the topology, Does anyone get this issue ?
Here is my nginx config:
server {
listen 80;
server_name myhostname.com;
location / {
proxy_pass http://10.0.0.215:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

@2opremio

This comment has been minimized.

Collaborator

2opremio commented Mar 27, 2017

@Van-Tien nginx doesn't handle websockets out of the box, you will need to enable upgrades in the Scope routes using websockets, see https://nginx.org/en/docs/http/websocket.html

I will try to get you a specific configuration.

@2opremio

This comment has been minimized.

Collaborator

2opremio commented Mar 27, 2017

@Van-Tien See the configuration from #2287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment