forked from openshift/origin
/
master.go
146 lines (122 loc) · 4.63 KB
/
master.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package kubernetes
import (
"fmt"
"net"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authorizer"
"github.com/emicklei/go-restful"
"github.com/golang/glog"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
minionControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
"github.com/GoogleCloudPlatform/kubernetes/pkg/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
kubeutil "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
)
const (
KubeAPIPrefix = "/api"
KubeAPIPrefixV1Beta1 = "/api/v1beta1"
KubeAPIPrefixV1Beta2 = "/api/v1beta2"
KubeAPIPrefixV1Beta3 = "/api/v1beta3"
)
// MasterConfig defines the required values to start a Kubernetes master
type MasterConfig struct {
MasterHost string
MasterPort int
NodeHosts []string
PortalNet *net.IPNet
EtcdHelper tools.EtcdHelper
KubeClient *kclient.Client
Authorizer authorizer.Authorizer
AdmissionControl admission.Interface
}
// TODO: Longer term we should read this from some config store, rather than a flag.
func (c *MasterConfig) EnsurePortalFlags() {
if c.PortalNet == nil {
glog.Fatal("No --portal-net specified")
}
}
// InstallAPI starts a Kubernetes master and registers the supported REST APIs
// into the provided mux, then returns an array of strings indicating what
// endpoints were started (these are format strings that will expect to be sent
// a single string value).
func (c *MasterConfig) InstallAPI(container *restful.Container) []string {
kubeletClient, err := kclient.NewKubeletClient(
&kclient.KubeletConfig{
Port: 10250,
},
)
if err != nil {
glog.Fatalf("Unable to configure Kubelet client: %v", err)
}
masterConfig := &master.Config{
PublicAddress: c.MasterHost,
ReadWritePort: c.MasterPort,
ReadOnlyPort: c.MasterPort,
Client: c.KubeClient,
EtcdHelper: c.EtcdHelper,
EventTTL: 2 * time.Hour,
EnableV1Beta3: true,
PortalNet: c.PortalNet,
RestfulContainer: container,
KubeletClient: kubeletClient,
APIPrefix: KubeAPIPrefix,
Authorizer: c.Authorizer,
AdmissionControl: c.AdmissionControl,
}
_ = master.New(masterConfig)
return []string{
fmt.Sprintf("Started Kubernetes API at %%s%s", KubeAPIPrefixV1Beta1),
fmt.Sprintf("Started Kubernetes API at %%s%s", KubeAPIPrefixV1Beta2),
fmt.Sprintf("Started Kubernetes API at %%s%s (experimental)", KubeAPIPrefixV1Beta3),
}
}
// RunReplicationController starts the Kubernetes replication controller sync loop
func (c *MasterConfig) RunReplicationController() {
controllerManager := controller.NewReplicationManager(c.KubeClient)
controllerManager.Run(10 * time.Second)
glog.Infof("Started Kubernetes Replication Manager")
}
// RunEndpointController starts the Kubernetes replication controller sync loop
func (c *MasterConfig) RunEndpointController() {
endpoints := service.NewEndpointController(c.KubeClient)
go kubeutil.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
glog.Infof("Started Kubernetes Endpoint Controller")
}
// RunScheduler starts the Kubernetes scheduler
func (c *MasterConfig) RunScheduler() {
configFactory := factory.NewConfigFactory(c.KubeClient)
config, err := configFactory.CreateFromProvider(factory.DefaultProvider)
if err != nil {
glog.Fatalf("Unable to start scheduler: %v", err)
}
s := scheduler.New(config)
s.Run()
glog.Infof("Started Kubernetes Scheduler")
}
func (c *MasterConfig) RunMinionController() {
nodeResources := &kapi.NodeResources{
Capacity: kapi.ResourceList{
kapi.ResourceCPU: *resource.NewMilliQuantity(int64(1*1000), resource.DecimalSI),
kapi.ResourceMemory: *resource.NewQuantity(int64(3*1024*1024*1024), resource.BinarySI),
},
}
// TODO: enable this for TLS and make configurable
kubeletClient, err := kclient.NewKubeletClient(&kclient.KubeletConfig{
Port: 10250,
EnableHttps: false,
})
if err != nil {
glog.Fatalf("Failure to create kubelet client: %v", err)
}
minionController := minionControllerPkg.NewNodeController(nil, "", c.NodeHosts, nodeResources, c.KubeClient, kubeletClient)
minionController.Run(10*time.Second, 10)
glog.Infof("Started Kubernetes Minion Controller")
}