From 8d1c1e4ac6eb1c079d7941ecdf87288114c4b87c Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sat, 3 Jun 2017 18:17:57 +0200 Subject: [PATCH] server: do not use localhost for streaming service The bug is silly if you have a master/node cluster where node is on a different machine than the master. The current behavior is to give our addresses like "0.0.0.0:10101". If you run "kubectl exec ..." from another host, that's not going to work since on a different host 0.0.0.0 resolves to localhost and kubectl exec fails with: error: unable to upgrade connection: 404 page not found This patch fixes the above by giving our correct addresses for reaching from outside. Signed-off-by: Antonio Murdaca --- server/server.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 4961e493..7c62afde 100644 --- a/server/server.go +++ b/server/server.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "net" "os" "path/filepath" "sync" @@ -23,6 +24,7 @@ import ( "github.com/kubernetes-incubator/cri-o/server/seccomp" rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/selinux/go-selinux/label" + knet "k8s.io/apimachinery/pkg/util/net" pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/server/streaming" ) @@ -607,9 +609,14 @@ func New(config *Config) (*Server, error) { s.restore() s.cleanupSandboxesOnShutdown() + bindAddress, err := knet.ChooseBindAddress(net.IP{0, 0, 0, 0}) + if err != nil { + return nil, err + } + // Prepare streaming server streamServerConfig := streaming.DefaultConfig - streamServerConfig.Addr = "0.0.0.0:10101" + streamServerConfig.Addr = bindAddress.String() + ":10101" s.stream.runtimeServer = s s.stream.streamServer, err = streaming.NewServer(streamServerConfig, s.stream) if err != nil {