예제 #1
0
// Starts api services (the master). Never returns.
func api_server() {
	machineList := util.StringList{*kubelet_address}

	etcdClient := etcd.NewClient([]string{*etcd_server})
	podRegistry := registry.MakeEtcdRegistry(etcdClient, machineList)
	controllerRegistry := registry.MakeEtcdRegistry(etcdClient, machineList)
	serviceRegistry := registry.MakeEtcdRegistry(etcdClient, machineList)

	containerInfo := &client.HTTPContainerInfo{
		Client: http.DefaultClient,
		Port:   *kubelet_port,
	}
	random := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))

	storage := map[string]apiserver.RESTStorage{
		"pods": registry.MakePodRegistryStorage(podRegistry, containerInfo, registry.MakeFirstFitScheduler(machineList, podRegistry, random)),
		"replicationControllers": registry.MakeControllerRegistryStorage(controllerRegistry),
		"services":               registry.MakeServiceRegistryStorage(serviceRegistry),
	}

	endpoints := registry.MakeEndpointController(serviceRegistry, podRegistry)
	go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)

	s := &http.Server{
		Addr:           fmt.Sprintf("%s:%d", *master_address, *master_port),
		Handler:        apiserver.New(storage, *apiPrefix),
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	log.Fatal(s.ListenAndServe())
}
예제 #2
0
func newKubernetesMaster(scheduler *scheduler.KubernetesScheduler, c *master.Config) *kubernetesMaster {
	var m *kubernetesMaster

	if len(c.EtcdServers) > 0 {
		etcdClient := etcd.NewClient(c.EtcdServers)
		minionRegistry := registry.MakeMinionRegistry(c.Minions)
		m = &kubernetesMaster{
			podRegistry:        scheduler,
			controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
			serviceRegistry:    registry.MakeEtcdRegistry(etcdClient, minionRegistry),
			minionRegistry:     minionRegistry,
			client:             c.Client,
		}
		m.init(scheduler, c.Cloud, c.PodInfoGetter)
	} else {
		m = &kubernetesMaster{
			podRegistry:        scheduler,
			controllerRegistry: registry.MakeMemoryRegistry(),
			serviceRegistry:    registry.MakeMemoryRegistry(),
			minionRegistry:     registry.MakeMinionRegistry(c.Minions),
			client:             c.Client,
		}
		m.init(scheduler, c.Cloud, c.PodInfoGetter)
	}
	return m
}
예제 #3
0
파일: master.go 프로젝트: r-ling/kubernetes
// Returns a new apiserver.
func New(etcdServers, minions []string, cloud cloudprovider.Interface) *Master {
	etcdClient := etcd.NewClient(etcdServers)
	m := &Master{
		podRegistry:        registry.MakeEtcdRegistry(etcdClient, minions),
		controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minions),
		serviceRegistry:    registry.MakeEtcdRegistry(etcdClient, minions),
	}
	m.init(minions, cloud)
	return m
}
예제 #4
0
파일: master.go 프로젝트: j3ffhu/kubernetes
// Returns a new apiserver.
func New(etcdServers, minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface, minionRegexp string) *Master {
	etcdClient := etcd.NewClient(etcdServers)
	minionRegistry := minionRegistryMaker(minions, cloud, minionRegexp)
	m := &Master{
		podRegistry:        registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		serviceRegistry:    registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		minionRegistry:     minionRegistry,
	}
	m.init(cloud, podInfoGetter)
	return m
}
예제 #5
0
파일: master.go 프로젝트: nyaxt/kubernetes
// New returns a new instance of Master connected to the given etcdServer.
func New(c *Config) *Master {
	etcdClient := etcd.NewClient(c.EtcdServers)
	minionRegistry := minionRegistryMaker(c)
	m := &Master{
		podRegistry:        registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		serviceRegistry:    registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		minionRegistry:     minionRegistry,
		client:             c.Client,
	}
	m.init(c.Cloud, c.PodInfoGetter)
	return m
}
예제 #6
0
// New returns a new instance of Master connected to the given etcdServer.
func New(etcdServers, minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface, minionRegexp string, client *client.Client, healthCheckMinions bool, cacheMinionsTTL time.Duration) *Master {
	etcdClient := etcd.NewClient(etcdServers)
	minionRegistry := minionRegistryMaker(minions, cloud, minionRegexp, healthCheckMinions, cacheMinionsTTL)
	m := &Master{
		podRegistry:        registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		serviceRegistry:    registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		minionRegistry:     minionRegistry,
		client:             client,
	}
	m.init(cloud, podInfoGetter)
	return m
}
예제 #7
0
func main() {
	flag.Parse()

	if len(machineList) == 0 {
		log.Fatal("No machines specified!")
	}

	var (
		podRegistry        registry.PodRegistry
		controllerRegistry registry.ControllerRegistry
		serviceRegistry    registry.ServiceRegistry
	)

	if len(etcdServerList) > 0 {
		log.Printf("Creating etcd client pointing to %v", etcdServerList)
		etcdClient := etcd.NewClient(etcdServerList)
		podRegistry = registry.MakeEtcdRegistry(etcdClient, machineList)
		controllerRegistry = registry.MakeEtcdRegistry(etcdClient, machineList)
		serviceRegistry = registry.MakeEtcdRegistry(etcdClient, machineList)
	} else {
		podRegistry = registry.MakeMemoryRegistry()
		controllerRegistry = registry.MakeMemoryRegistry()
		serviceRegistry = registry.MakeMemoryRegistry()
	}

	containerInfo := &kube_client.HTTPContainerInfo{
		Client: http.DefaultClient,
		Port:   10250,
	}

	random := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
	storage := map[string]apiserver.RESTStorage{
		"pods": registry.MakePodRegistryStorage(podRegistry, containerInfo, registry.MakeFirstFitScheduler(machineList, podRegistry, random)),
		"replicationControllers": registry.MakeControllerRegistryStorage(controllerRegistry),
		"services":               registry.MakeServiceRegistryStorage(serviceRegistry),
	}

	endpoints := registry.MakeEndpointController(serviceRegistry, podRegistry)
	go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)

	s := &http.Server{
		Addr:           fmt.Sprintf("%s:%d", *address, *port),
		Handler:        apiserver.New(storage, *apiPrefix),
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	log.Fatal(s.ListenAndServe())
}
예제 #8
0
func main() {

	// Setup
	servers := []string{"http://localhost:4001"}
	log.Printf("Creating etcd client pointing to %v", servers)
	etcdClient := etcd.NewClient(servers)
	machineList := []string{"machine"}

	reg := registry.MakeEtcdRegistry(etcdClient, machineList)

	apiserver := apiserver.New(map[string]apiserver.RESTStorage{
		"pods": registry.MakePodRegistryStorage(reg, &client.FakeContainerInfo{}, registry.MakeRoundRobinScheduler(machineList)),
		"replicationControllers": registry.MakeControllerRegistryStorage(reg),
	}, "/api/v1beta1")
	server := httptest.NewServer(apiserver)

	controllerManager := registry.MakeReplicationManager(etcd.NewClient(servers),
		client.Client{
			Host: server.URL,
		})

	go controllerManager.Synchronize()
	go controllerManager.WatchControllers()

	// Ok. we're good to go.
	log.Printf("API Server started on %s", server.URL)
	// Wait for the synchronization threads to come up.
	time.Sleep(time.Second * 10)

	kubeClient := client.Client{
		Host: server.URL,
	}
	data, err := ioutil.ReadFile("api/examples/controller.json")
	if err != nil {
		log.Fatalf("Unexpected error: %#v", err)
	}
	var controllerRequest api.ReplicationController
	if err = json.Unmarshal(data, &controllerRequest); err != nil {
		log.Fatalf("Unexpected error: %#v", err)
	}

	if _, err = kubeClient.CreateReplicationController(controllerRequest); err != nil {
		log.Fatalf("Unexpected error: %#v", err)
	}
	// Give the controllers some time to actually create the pods
	time.Sleep(time.Second * 10)

	// Validate that they're truly up.
	pods, err := kubeClient.ListPods(nil)
	if err != nil || len(pods.Items) != 2 {
		log.Fatal("FAILED")
	}
	log.Printf("OK")
}
예제 #9
0
파일: master.go 프로젝트: jjhuff/kubernetes
// Returns a new apiserver.
func New(etcdServers, minions []string, cloud cloudprovider.Interface, minionRegexp string) *Master {
	etcdClient := etcd.NewClient(etcdServers)
	var minionRegistry registry.MinionRegistry
	if cloud != nil && len(minionRegexp) > 0 {
		var err error
		minionRegistry, err = registry.MakeCloudMinionRegistry(cloud, minionRegexp)
		if err != nil {
			glog.Errorf("Failed to initalize cloud minion registry reverting to static registry (%#v)", err)
			minionRegistry = registry.MakeMinionRegistry(minions)
		}
	} else {
		minionRegistry = registry.MakeMinionRegistry(minions)
	}
	m := &Master{
		podRegistry:        registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		serviceRegistry:    registry.MakeEtcdRegistry(etcdClient, minionRegistry),
		minionRegistry:     minionRegistry,
	}
	m.init(cloud)
	return m
}