From d3531c9eece486608c80d769490d9761ce407d10 Mon Sep 17 00:00:00 2001 From: Aaron Prindle Date: Thu, 16 Feb 2017 11:57:56 -0800 Subject: [PATCH] Change etcd to be accessible within pods --- README.md | 10 ++++++++++ cmd/localkube/cmd/options.go | 1 + cmd/localkube/cmd/start.go | 10 ++++++++++ pkg/localkube/etcd.go | 4 ++-- pkg/localkube/localkube.go | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fc795b3180..9d94b4167d 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,17 @@ Kubectl is now configured to use the cluster. # Then you can examine the profile with: $ go tool pprof /tmp/profile933201292/cpu.pprof ``` +## Accessing Localkube Resources From Inside A Pod: Example etcd +In order to access localkube resources from inside a pod, localkube's host ip address must be used. This can be obtained by running: +```shell +$ minikube ssh -- "sudo /usr/local/bin/localkube --host-ip" +localkube host ip: 10.0.2.15 +``` +You can use the host-ip:`10.0.2.15` to access localkube's resources, for example its etcd cluster. In order to access etcd from within a pod, you can run the following command inside: +```shell +curl -L -X PUT http://10.0.2.15:2379/v2/keys/message -d value="Hello" +``` ## KNOWN Issues * Features that require a Cloud Provider will not work in Minikube. These include: diff --git a/cmd/localkube/cmd/options.go b/cmd/localkube/cmd/options.go index 46dad286de..eadd450f0e 100644 --- a/cmd/localkube/cmd/options.go +++ b/cmd/localkube/cmd/options.go @@ -61,6 +61,7 @@ func AddFlags(s *localkube.LocalkubeServer) { flag.IntVar(&s.APIServerInsecurePort, "apiserver-insecure-port", s.APIServerInsecurePort, "The port the apiserver will listen insecurely on") flag.BoolVar(&s.ShouldGenerateCerts, "generate-certs", s.ShouldGenerateCerts, "If localkube should generate it's own certificates") flag.BoolVar(&s.ShowVersion, "version", s.ShowVersion, "If localkube should just print the version and exit.") + flag.BoolVar(&s.ShowHostIP, "host-ip", s.ShowHostIP, "If localkube should just print the host IP and exit.") flag.Var(&s.RuntimeConfig, "runtime-config", "A set of key=value pairs that describe runtime configuration that may be passed to apiserver. apis/ key can be used to turn on/off specific api versions. apis// can be used to turn on/off specific resources. api/all and api/legacy are special keys to control all and legacy api versions respectively.") flag.IPVar(&s.NodeIP, "node-ip", s.NodeIP, "IP address of the node. If set, kubelet will use this IP address for the node.") flag.StringVar(&s.ContainerRuntime, "container-runtime", "", "The container runtime to be used") diff --git a/cmd/localkube/cmd/start.go b/cmd/localkube/cmd/start.go index d8e18185b1..85e0eafad1 100644 --- a/cmd/localkube/cmd/start.go +++ b/cmd/localkube/cmd/start.go @@ -40,6 +40,12 @@ func StartLocalkube() { os.Exit(0) } + if Server.ShowHostIP { + hostIP, _ := Server.GetHostIP() + fmt.Println("localkube host ip: ", hostIP.String()) + os.Exit(0) + } + // Get the etcd logger for the api repo apiRepoLogger := capnslog.MustRepoLogger("github.com/coreos/etcd/etcdserver/api") // Set the logging level to NOTICE as there is an INFO lvl log statement that runs every few seconds -> log spam @@ -95,6 +101,10 @@ func SetupServer(s *localkube.LocalkubeServer) { } s.AddServer(etcd) + // setup access to etcd + netIP, _ := s.GetHostIP() + fmt.Printf("localkube host ip address: %s\n", netIP.String()) + // setup apiserver apiserver := s.NewAPIServer() s.AddServer(apiserver) diff --git a/pkg/localkube/etcd.go b/pkg/localkube/etcd.go index 245f7980ba..e9992da293 100644 --- a/pkg/localkube/etcd.go +++ b/pkg/localkube/etcd.go @@ -35,10 +35,10 @@ const ( var ( // EtcdClientURLs have listeners created and handle etcd API traffic - KubeEtcdClientURLs = []string{"http://localhost:2379"} + KubeEtcdClientURLs = []string{"http://0.0.0.0:2379"} // EtcdPeerURLs don't have listeners created for them, they are used to pass Etcd validation - KubeEtcdPeerURLs = []string{"http://localhost:2380"} + KubeEtcdPeerURLs = []string{"http://0.0.0.0:2380"} ) // Etcd is a Server which manages an Etcd cluster diff --git a/pkg/localkube/localkube.go b/pkg/localkube/localkube.go index 659e22ea05..c1f458db9f 100644 --- a/pkg/localkube/localkube.go +++ b/pkg/localkube/localkube.go @@ -52,6 +52,7 @@ type LocalkubeServer struct { APIServerInsecurePort int ShouldGenerateCerts bool ShowVersion bool + ShowHostIP bool RuntimeConfig config.ConfigurationMap NodeIP net.IP ContainerRuntime string