Skip to content

Commit e3a3b1e

Browse files
authored
Merge pull request #7308 from laozc/metallb
Add Metal LB addon
2 parents 47b769b + f078cce commit e3a3b1e

File tree

7 files changed

+395
-19
lines changed

7 files changed

+395
-19
lines changed

Diff for: cmd/minikube/cmd/config/configure.go

+26
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package config
1818

1919
import (
2020
"io/ioutil"
21+
"net"
2122

2223
"github.com/spf13/cobra"
24+
"k8s.io/minikube/pkg/minikube/config"
2325
"k8s.io/minikube/pkg/minikube/exit"
2426
"k8s.io/minikube/pkg/minikube/out"
2527
"k8s.io/minikube/pkg/minikube/service"
@@ -184,6 +186,30 @@ var addonsConfigureCmd = &cobra.Command{
184186
out.WarningT("ERROR creating `registry-creds-acr` secret")
185187
}
186188

189+
case "metallb":
190+
profile := ClusterFlagValue()
191+
cfg, err := config.Load(profile)
192+
if err != nil {
193+
out.ErrT(out.FatalType, "Failed to load config {{.profile}}", out.V{"profile": profile})
194+
}
195+
196+
validator := func(s string) bool {
197+
return net.ParseIP(s) != nil
198+
}
199+
200+
if cfg.KubernetesConfig.LoadBalancerStartIP == "" {
201+
cfg.KubernetesConfig.LoadBalancerStartIP = AskForStaticValidatedValue("-- Enter Load Balancer Start IP: ", validator)
202+
}
203+
204+
if cfg.KubernetesConfig.LoadBalancerEndIP == "" {
205+
cfg.KubernetesConfig.LoadBalancerEndIP = AskForStaticValidatedValue("-- Enter Load Balancer End IP: ", validator)
206+
}
207+
208+
err = config.SaveProfile(profile, cfg)
209+
if err != nil {
210+
out.ErrT(out.FatalType, "Failed to save config {{.profile}}", out.V{"profile": profile})
211+
}
212+
187213
default:
188214
out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon})
189215
return

Diff for: cmd/minikube/cmd/config/prompt.go

+20
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,23 @@ func posString(slice []string, element string) int {
153153
func containsString(slice []string, element string) bool {
154154
return posString(slice, element) != -1
155155
}
156+
157+
// AskForStaticValidatedValue asks for a single value to enter and check for valid input
158+
func AskForStaticValidatedValue(s string, validator func(s string) bool) string {
159+
reader := bufio.NewReader(os.Stdin)
160+
161+
for {
162+
response := getStaticValue(reader, s)
163+
164+
// Can't have zero length
165+
if len(response) == 0 {
166+
out.Err("--Error, please enter a value:")
167+
continue
168+
}
169+
if !validator(response) {
170+
out.Err("--Invalid input, please enter a value:")
171+
continue
172+
}
173+
return response
174+
}
175+
}

Diff for: deploy/addons/metallb/metallb-config.yaml.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
namespace: metallb-system
5+
name: config
6+
data:
7+
config: |
8+
address-pools:
9+
- name: default
10+
protocol: layer2
11+
addresses:
12+
- {{ .LoadBalancerStartIP }}-{{ .LoadBalancerEndIP }}

Diff for: deploy/addons/metallb/metallb.yaml

+293
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
labels:
5+
app: metallb
6+
name: metallb-system
7+
---
8+
apiVersion: policy/v1beta1
9+
kind: PodSecurityPolicy
10+
metadata:
11+
labels:
12+
app: metallb
13+
name: speaker
14+
namespace: metallb-system
15+
spec:
16+
allowPrivilegeEscalation: false
17+
allowedCapabilities:
18+
- NET_ADMIN
19+
- NET_RAW
20+
- SYS_ADMIN
21+
fsGroup:
22+
rule: RunAsAny
23+
hostNetwork: true
24+
hostPorts:
25+
- max: 7472
26+
min: 7472
27+
privileged: true
28+
runAsUser:
29+
rule: RunAsAny
30+
seLinux:
31+
rule: RunAsAny
32+
supplementalGroups:
33+
rule: RunAsAny
34+
volumes:
35+
- '*'
36+
---
37+
apiVersion: v1
38+
kind: ServiceAccount
39+
metadata:
40+
labels:
41+
app: metallb
42+
name: controller
43+
namespace: metallb-system
44+
---
45+
apiVersion: v1
46+
kind: ServiceAccount
47+
metadata:
48+
labels:
49+
app: metallb
50+
name: speaker
51+
namespace: metallb-system
52+
---
53+
apiVersion: rbac.authorization.k8s.io/v1
54+
kind: ClusterRole
55+
metadata:
56+
labels:
57+
app: metallb
58+
name: metallb-system:controller
59+
rules:
60+
- apiGroups:
61+
- ''
62+
resources:
63+
- services
64+
verbs:
65+
- get
66+
- list
67+
- watch
68+
- update
69+
- apiGroups:
70+
- ''
71+
resources:
72+
- services/status
73+
verbs:
74+
- update
75+
- apiGroups:
76+
- ''
77+
resources:
78+
- events
79+
verbs:
80+
- create
81+
- patch
82+
---
83+
apiVersion: rbac.authorization.k8s.io/v1
84+
kind: ClusterRole
85+
metadata:
86+
labels:
87+
app: metallb
88+
name: metallb-system:speaker
89+
rules:
90+
- apiGroups:
91+
- ''
92+
resources:
93+
- services
94+
- endpoints
95+
- nodes
96+
verbs:
97+
- get
98+
- list
99+
- watch
100+
- apiGroups:
101+
- ''
102+
resources:
103+
- events
104+
verbs:
105+
- create
106+
- patch
107+
- apiGroups:
108+
- extensions
109+
resourceNames:
110+
- speaker
111+
resources:
112+
- podsecuritypolicies
113+
verbs:
114+
- use
115+
---
116+
apiVersion: rbac.authorization.k8s.io/v1
117+
kind: Role
118+
metadata:
119+
labels:
120+
app: metallb
121+
name: config-watcher
122+
namespace: metallb-system
123+
rules:
124+
- apiGroups:
125+
- ''
126+
resources:
127+
- configmaps
128+
verbs:
129+
- get
130+
- list
131+
- watch
132+
---
133+
apiVersion: rbac.authorization.k8s.io/v1
134+
kind: ClusterRoleBinding
135+
metadata:
136+
labels:
137+
app: metallb
138+
name: metallb-system:controller
139+
roleRef:
140+
apiGroup: rbac.authorization.k8s.io
141+
kind: ClusterRole
142+
name: metallb-system:controller
143+
subjects:
144+
- kind: ServiceAccount
145+
name: controller
146+
namespace: metallb-system
147+
---
148+
apiVersion: rbac.authorization.k8s.io/v1
149+
kind: ClusterRoleBinding
150+
metadata:
151+
labels:
152+
app: metallb
153+
name: metallb-system:speaker
154+
roleRef:
155+
apiGroup: rbac.authorization.k8s.io
156+
kind: ClusterRole
157+
name: metallb-system:speaker
158+
subjects:
159+
- kind: ServiceAccount
160+
name: speaker
161+
namespace: metallb-system
162+
---
163+
apiVersion: rbac.authorization.k8s.io/v1
164+
kind: RoleBinding
165+
metadata:
166+
labels:
167+
app: metallb
168+
name: config-watcher
169+
namespace: metallb-system
170+
roleRef:
171+
apiGroup: rbac.authorization.k8s.io
172+
kind: Role
173+
name: config-watcher
174+
subjects:
175+
- kind: ServiceAccount
176+
name: controller
177+
- kind: ServiceAccount
178+
name: speaker
179+
---
180+
apiVersion: apps/v1
181+
kind: DaemonSet
182+
metadata:
183+
labels:
184+
app: metallb
185+
component: speaker
186+
name: speaker
187+
namespace: metallb-system
188+
spec:
189+
selector:
190+
matchLabels:
191+
app: metallb
192+
component: speaker
193+
template:
194+
metadata:
195+
annotations:
196+
prometheus.io/port: '7472'
197+
prometheus.io/scrape: 'true'
198+
labels:
199+
app: metallb
200+
component: speaker
201+
spec:
202+
containers:
203+
- args:
204+
- --port=7472
205+
- --config=config
206+
env:
207+
- name: METALLB_NODE_NAME
208+
valueFrom:
209+
fieldRef:
210+
fieldPath: spec.nodeName
211+
- name: METALLB_HOST
212+
valueFrom:
213+
fieldRef:
214+
fieldPath: status.hostIP
215+
image: metallb/speaker:v0.8.2
216+
imagePullPolicy: IfNotPresent
217+
name: speaker
218+
ports:
219+
- containerPort: 7472
220+
name: monitoring
221+
resources:
222+
limits:
223+
cpu: 100m
224+
memory: 100Mi
225+
securityContext:
226+
allowPrivilegeEscalation: false
227+
capabilities:
228+
add:
229+
- NET_ADMIN
230+
- NET_RAW
231+
- SYS_ADMIN
232+
drop:
233+
- ALL
234+
readOnlyRootFilesystem: true
235+
hostNetwork: true
236+
nodeSelector:
237+
beta.kubernetes.io/os: linux
238+
serviceAccountName: speaker
239+
terminationGracePeriodSeconds: 0
240+
tolerations:
241+
- effect: NoSchedule
242+
key: node-role.kubernetes.io/master
243+
---
244+
apiVersion: apps/v1
245+
kind: Deployment
246+
metadata:
247+
labels:
248+
app: metallb
249+
component: controller
250+
name: controller
251+
namespace: metallb-system
252+
spec:
253+
revisionHistoryLimit: 3
254+
selector:
255+
matchLabels:
256+
app: metallb
257+
component: controller
258+
template:
259+
metadata:
260+
annotations:
261+
prometheus.io/port: '7472'
262+
prometheus.io/scrape: 'true'
263+
labels:
264+
app: metallb
265+
component: controller
266+
spec:
267+
containers:
268+
- args:
269+
- --port=7472
270+
- --config=config
271+
image: metallb/controller:v0.8.2
272+
imagePullPolicy: IfNotPresent
273+
name: controller
274+
ports:
275+
- containerPort: 7472
276+
name: monitoring
277+
resources:
278+
limits:
279+
cpu: 100m
280+
memory: 100Mi
281+
securityContext:
282+
allowPrivilegeEscalation: false
283+
capabilities:
284+
drop:
285+
- all
286+
readOnlyRootFilesystem: true
287+
nodeSelector:
288+
beta.kubernetes.io/os: linux
289+
securityContext:
290+
runAsNonRoot: true
291+
runAsUser: 65534
292+
serviceAccountName: controller
293+
terminationGracePeriodSeconds: 0

Diff for: pkg/addons/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,9 @@ var Addons = []*Addon{
129129
set: SetBool,
130130
callbacks: []setFn{enableOrDisableStorageClasses},
131131
},
132+
{
133+
name: "metallb",
134+
set: SetBool,
135+
callbacks: []setFn{enableOrDisableAddon},
136+
},
132137
}

0 commit comments

Comments
 (0)