Change etcd to be accessible within pods

pull/1145/head
Aaron Prindle 2017-02-16 11:57:56 -08:00
parent 513e463bca
commit d3531c9eec
5 changed files with 24 additions and 2 deletions

View File

@ -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:

View File

@ -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/<groupVersion> key can be used to turn on/off specific api versions. apis/<groupVersion>/<resource> 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")

View File

@ -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)

View File

@ -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

View File

@ -52,6 +52,7 @@ type LocalkubeServer struct {
APIServerInsecurePort int
ShouldGenerateCerts bool
ShowVersion bool
ShowHostIP bool
RuntimeConfig config.ConfigurationMap
NodeIP net.IP
ContainerRuntime string