forked from kubeup/archon
/
kuberunner.go
92 lines (78 loc) · 2.47 KB
/
kuberunner.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
package kuberunner
import (
"net"
"os"
"os/signal"
"github.com/golang/glog"
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/minikube/pkg/localkube"
"k8s.io/minikube/pkg/util"
)
func NewLocalkubeServer() *localkube.LocalkubeServer {
_, defaultServiceClusterIPRange, _ := net.ParseCIDR("10.0.0.1/24")
return &localkube.LocalkubeServer{
Containerized: false,
DNSDomain: "cluster.local",
DNSIP: net.ParseIP("10.0.0.10"),
LocalkubeDirectory: "./.localkube",
ServiceClusterIPRange: *defaultServiceClusterIPRange,
APIServerAddress: net.ParseIP("127.0.0.1"),
APIServerPort: 443,
APIServerInsecureAddress: net.ParseIP("127.0.0.1"),
APIServerInsecurePort: 8080,
ShouldGenerateCerts: true,
ShowVersion: false,
RuntimeConfig: map[string]string{"api/all": "true"},
ExtraConfig: util.ExtraOptionSlice{},
}
}
func StartLocalkubeServer(s *localkube.LocalkubeServer) {
if s.ShouldGenerateCerts {
if err := s.GenerateCerts(); err != nil {
glog.Errorf("Failed to create certificates!")
panic(err)
}
}
//Set feature gates
glog.Infof("Feature gates:", s.FeatureGates)
if s.FeatureGates != "" {
err := feature.DefaultFeatureGate.Set(s.FeatureGates)
if err != nil {
glog.Errorf("Error setting feature gates: %s", err)
}
}
// Setup capabilities. This can only be done once per binary.
allSources, _ := types.GetValidatedSources([]string{types.AllSource})
c := capabilities.Capabilities{
AllowPrivileged: true,
PrivilegedSources: capabilities.PrivilegedSources{
HostNetworkSources: allSources,
HostIPCSources: allSources,
HostPIDSources: allSources,
},
}
capabilities.Initialize(c)
// setup etcd
etcd, err := s.NewEtcd(localkube.KubeEtcdClientURLs, localkube.KubeEtcdPeerURLs, "kubeetcd", s.GetEtcdDataDirectory())
if err != nil {
panic(err)
}
s.AddServer(etcd)
// setup access to etcd
netIP, _ := s.GetHostIP()
glog.Infof("localkube host ip address: %s\n", netIP.String())
// setup apiserver
apiserver := s.NewAPIServer()
s.AddServer(apiserver)
// setup controller-manager
//controllerManager := s.NewControllerManagerServer()
//s.AddServer(controllerManager)
s.StartAll()
defer s.StopAll()
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt)
<-interruptChan
glog.Infof("Shutting down localkube...")
}