This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
1.9.go
633 lines (618 loc) · 15.4 KB
/
1.9.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
package templates
var (
manifest1o9 = []Manifest{
{
Name: "kubelet.service",
Destination: ManifestSystemdUnit,
Content: []byte(`[Unit]
Description=Hyperkube kubelet for pupernetes
After=network.target
[Service]
ExecStart={{.RootABSPath}}/bin/hyperkube kubelet \
--v=4 \
--allow-privileged \
--fail-swap-on=false \
--hairpin-mode=none \
--pod-manifest-path={{.RootABSPath}}/manifest-static-pod \
--hostname-override={{ .Hostname }} \
--root-dir=/var/lib/p8s-kubelet \
--healthz-port=10248 \
--kubeconfig={{.RootABSPath}}/manifest-config/kubeconfig-insecure.yaml \
--resolv-conf={{.RootABSPath}}/net.d/resolv-conf \
--cluster-dns={{ .DNSClusterIP }} \
--cluster-domain=cluster.local \
--cert-dir={{.RootABSPath}}/secrets \
--client-ca-file={{.RootABSPath}}/secrets/kubernetes.issuing_ca \
--tls-cert-file={{.RootABSPath}}/secrets/kubernetes.certificate \
--tls-private-key-file={{.RootABSPath}}/secrets/kubernetes.private_key \
--read-only-port=0 \
--anonymous-auth=false \
--authentication-token-webhook \
--authentication-token-webhook-cache-ttl=5s \
--authorization-mode=Webhook \
--cadvisor-port=0 \
--cgroups-per-qos=true \
--cgroup-driver={{ .CgroupDriver }} \
--max-pods=60 \
--node-ip={{ .NodeIP }} \
--node-labels=p8s=mononode \
--application-metrics-count-limit=50 \
--network-plugin=cni \
--cni-conf-dir={{.RootABSPath}}/net.d \
--cni-bin-dir={{.RootABSPath}}/bin \
--container-runtime={{.ContainerRuntime}} \
--runtime-request-timeout=15m \
--container-runtime-endpoint=unix://{{.ContainerRuntimeEndpoint}}
Restart=no
`),
},
{
Name: "containerd.service",
Destination: ManifestSystemdUnit,
Content: []byte(`[Unit]
Description=containerd
After=network.target
[Service]
KillMode=process
Environment=PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin:{{.RootABSPath}}/bin
ExecStart={{.RootABSPath}}/bin/containerd \
--config {{.RootABSPath}}/manifest-config/containerd-config.toml
Restart=no
`),
},
{
Name: "kube-apiserver.service",
Destination: ManifestSystemdUnit,
Content: []byte(`[Unit]
Description=Hyperkube apiserver for pupernetes
After=network.target
[Service]
ExecStart={{.RootABSPath}}/bin/hyperkube apiserver \
--apiserver-count=1 \
--insecure-bind-address=127.0.0.1 \
--insecure-port=8080 \
--allow-privileged=true \
--service-cluster-ip-range={{ .ServiceClusterIPRange }} \
--admission-control=NamespaceLifecycle,PodPreset,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,EventRateLimit \
--kubelet-preferred-address-types=InternalIP,LegacyHostIP,ExternalDNS,InternalDNS,Hostname \
--authorization-mode=RBAC \
--etcd-servers=http://127.0.0.1:2379 \
--anonymous-auth=false \
--service-account-lookup=true \
--runtime-config=api/all=true \
--client-ca-file={{.RootABSPath}}/secrets/kubernetes.issuing_ca \
--tls-ca-file={{.RootABSPath}}/secrets/kubernetes.issuing_ca \
--tls-cert-file={{.RootABSPath}}/secrets/kubernetes.certificate \
--tls-private-key-file={{.RootABSPath}}/secrets/kubernetes.private_key \
--service-account-key-file={{.RootABSPath}}/secrets/service-accounts.rsa \
--kubelet-client-certificate={{.RootABSPath}}/secrets/kubernetes.certificate \
--kubelet-client-key={{.RootABSPath}}/secrets/kubernetes.private_key \
--kubelet-https \
--requestheader-client-ca-file={{.RootABSPath}}/secrets/kubernetes.issuing_ca \
--requestheader-allowed-names=aggregator,p8s \
--requestheader-extra-headers-prefix=X-Remote-Extra- \
--requestheader-group-headers=X-Remote-Group \
--requestheader-username-headers=X-Remote-User \
--proxy-client-cert-file={{.RootABSPath}}/secrets/kubernetes.certificate \
--proxy-client-key-file={{.RootABSPath}}/secrets/kubernetes.private_key \
--kubelet-https \
--kubelet-certificate-authority={{.RootABSPath}}/secrets/kubernetes.issuing_ca \
--target-ram-mb=0 \
--watch-cache=false \
--default-watch-cache-size=0 \
--watch-cache-sizes="" \
--deserialization-cache-size=0 \
--audit-log-path={{.RootABSPath}}/logs/audit.log \
--audit-policy-file={{.RootABSPath}}/manifest-config/audit.yaml \
--etcd-compaction-interval=0 \
--event-ttl=10m \
--admission-control-config-file={{.RootABSPath}}/manifest-config/admission.yaml
Restart=no
`),
},
{
Name: "etcd.service",
Destination: ManifestSystemdUnit,
Content: []byte(`[Unit]
Description=etcd for pupernetes
After=network.target
[Service]
ExecStart={{.RootABSPath}}/bin/etcd \
--name=etcdv3.1.11 \
--data-dir={{.RootABSPath}}/etcd-data \
--auto-compaction-retention=0 \
--quota-backend-bytes=0 \
--metrics=basic \
--cert-file={{.RootABSPath}}/secrets/etcd.certificate \
--key-file={{.RootABSPath}}/secrets/etcd.private_key \
--client-cert-auth=true \
--trusted-ca-file={{.RootABSPath}}/secrets/etcd.issuing_ca \
--listen-client-urls=http://127.0.0.1:2379,https://{{ .NodeIP }}:2379 \
--advertise-client-urls=http://127.0.0.1:2379,https://{{ .NodeIP }}:2379
Restart=no
`),
},
{
Name: "kubeconfig-auth.yaml",
Destination: ManifestConfig,
Content: []byte(`---
apiVersion: v1
kind: Config
clusters:
- cluster:
server: https://127.0.0.1:6443
certificate-authority: "{{.RootABSPath}}/secrets/kubernetes.issuing_ca"
name: p8s
contexts:
- context:
cluster: p8s
user: p8s
name: p8s
current-context: p8s
users:
- name: p8s
username: p8s
client-certificate: "{{.RootABSPath}}/secrets/kubernetes.certificate"
client-key: "{{.RootABSPath}}/secrets/kubernetes.private_key"
`),
},
{
Name: "containerd-config.toml",
Destination: ManifestConfig,
Content: []byte(`
root = "/var/lib/containerd"
state = "/run/containerd"
oom_score = 0
[grpc]
address = "{{.ContainerRuntimeEndpoint}}"
uid = 0
gid = 0
max_recv_message_size = 16777216
max_send_message_size = 16777216
[debug]
address = ""
uid = 0
gid = 0
level = ""
[metrics]
address = "127.0.0.1:1338"
grpc_histogram = false
[cgroup]
path = ""
[plugins]
[plugins.cgroups]
no_prometheus = false
[plugins.cri]
stream_server_address = ""
stream_server_port = "10010"
enable_selinux = false
sandbox_image = "k8s.gcr.io/pause:3.1"
stats_collect_period = 10
systemd_cgroup = false
enable_tls_streaming = false
[plugins.cri.containerd]
snapshotter = "overlayfs"
[plugins.cri.containerd.default_runtime]
runtime_type = "io.containerd.runtime.v1.linux"
runtime_engine = ""
runtime_root = ""
[plugins.cri.containerd.untrusted_workload_runtime]
runtime_type = ""
runtime_engine = ""
runtime_root = ""
[plugins.cri.cni]
bin_dir = "{{.RootABSPath}}/bin"
conf_dir = "{{.RootABSPath}}/net.d"
conf_template = ""
[plugins.cri.registry]
[plugins.cri.registry.mirrors]
[plugins.cri.registry.mirrors."docker.io"]
endpoint = ["https://registry-1.docker.io"]
[plugins.diff-service]
default = ["walking"]
[plugins.linux]
shim = "containerd-shim"
runtime = "runc"
runtime_root = ""
no_shim = false
shim_debug = false
[plugins.scheduler]
pause_threshold = 0.02
deletion_threshold = 0
mutation_threshold = 100
schedule_delay = "0s"
startup_delay = "100ms"
`),
},
{
Name: "kubeconfig-insecure.yaml",
Destination: ManifestConfig,
Content: []byte(`---
apiVersion: v1
kind: Config
clusters:
- cluster:
server: http://127.0.0.1:8080
name: p8s
contexts:
- context:
cluster: p8s
user: p8s
name: p8s
current-context: p8s
users:
- name: p8s
username: p8s
`),
},
{
Name: "audit.yaml",
Destination: ManifestConfig,
Content: []byte(`---
apiVersion: audit.k8s.io/v1beta1
kind: Policy
rules:
- level: RequestResponse
`),
},
{
Name: "admission.yaml",
Destination: ManifestConfig,
Content: []byte(`---
kind: AdmissionConfiguration
apiVersion: apiserver.k8s.io/v1alpha1
plugins:
- name: EventRateLimit
path: eventconfig.yaml
`),
},
{
Name: "eventconfig.yaml",
Destination: ManifestConfig,
Content: []byte(`---
kind: Configuration
apiVersion: eventratelimit.admission.k8s.io/v1alpha1
limits:
- type: Namespace
qps: 50
burst: 100
cacheSize: 2000
- type: User
qps: 10
burst: 50
`),
},
{
Name: "kube-controller-manager.yaml",
Destination: ManifestAPI,
Content: []byte(`---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-controller-manager
namespace: kube-system
automountServiceAccountToken: false
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: kube-controller-manager
name: kube-controller-manager
namespace: kube-system
spec:
serviceAccountName: kube-controller-manager
automountServiceAccountToken: false
nodeName: "{{ .Hostname }}"
hostNetwork: true
volumes:
- name: secrets
hostPath:
path: "{{.RootABSPath}}/secrets"
containers:
- name: kube-controller-manager
image: "{{ .HyperkubeImageURL }}"
imagePullPolicy: IfNotPresent
command:
- /hyperkube
- controller-manager
- --master=http://127.0.0.1:8080
- --leader-elect=true
- --leader-elect-lease-duration=150s
- --leader-elect-renew-deadline=100s
- --leader-elect-retry-period=20s
- --cluster-signing-cert-file=/etc/secrets/pupernetes.certificate
- --cluster-signing-key-file=/etc/secrets/pupernetes.private_key
- --root-ca-file=/etc/secrets/pupernetes.issuing_ca
- --service-account-private-key-file=/etc/secrets/service-accounts.rsa
- --concurrent-deployment-syncs=2
- --concurrent-endpoint-syncs=2
- --concurrent-gc-syncs=5
- --concurrent-namespace-syncs=3
- --concurrent-replicaset-syncs=2
- --concurrent-resource-quota-syncs=2
- --concurrent-service-syncs=1
- --concurrent-serviceaccount-token-syncs=2
- --horizontal-pod-autoscaler-use-rest-clients=true
volumeMounts:
- name: secrets
mountPath: /etc/secrets
livenessProbe:
httpGet:
path: /healthz
port: 10252
initialDelaySeconds: 15
readinessProbe:
httpGet:
path: /healthz
port: 10252
initialDelaySeconds: 5
resources:
requests:
cpu: "100m"
limits:
cpu: "250m"
`),
},
{
Name: "kube-scheduler.yaml",
Destination: ManifestAPI,
Content: []byte(`---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-scheduler
namespace: kube-system
spec:
template:
metadata:
labels:
app: kube-scheduler
spec:
hostNetwork: true
containers:
- name: kube-scheduler
image: "{{ .HyperkubeImageURL }}"
imagePullPolicy: IfNotPresent
command:
- /hyperkube
- scheduler
- --master=http://127.0.0.1:8080
- --leader-elect=true
- --leader-elect-lease-duration=150s
- --leader-elect-renew-deadline=100s
- --leader-elect-retry-period=20s
- --housekeeping-interval=15s
livenessProbe:
httpGet:
path: /healthz
port: 10251
initialDelaySeconds: 15
readinessProbe:
httpGet:
path: /healthz
port: 10251
initialDelaySeconds: 5
resources:
requests:
cpu: "50m"
limits:
cpu: "100m"
`),
},
{
Name: "kube-proxy.yaml",
Destination: ManifestAPI,
Content: []byte(`---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-proxy
namespace: kube-system
spec:
template:
metadata:
labels:
app: kube-proxy
spec:
hostNetwork: true
containers:
- name: kube-proxy
image: "{{ .HyperkubeImageURL }}"
imagePullPolicy: IfNotPresent
command:
- /hyperkube
- proxy
- --master=http://127.0.0.1:8080
- --proxy-mode=iptables
- --masquerade-all
securityContext:
privileged: true
livenessProbe:
httpGet:
path: /healthz
port: 10256
readinessProbe:
httpGet:
path: /healthz
port: 10256
resources:
requests:
cpu: "50m"
limits:
cpu: "100m"
`),
},
{
Name: "p8s-user-admin.yaml",
Destination: ManifestAPI,
Content: []byte(`---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: p8s-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: p8s
`),
},
{
Name: "coredns.yaml",
Destination: ManifestAPI,
Content: []byte(`---
apiVersion: v1
kind: ServiceAccount
metadata:
name: coredns
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:coredns
rules:
- apiGroups:
- ""
resources:
- endpoints
- services
- pods
- namespaces
verbs:
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:coredns
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:coredns
subjects:
- kind: ServiceAccount
name: coredns
namespace: kube-system
---
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
log
health
kubernetes cluster.local {{ .ServiceClusterIPRange }} {
pods insecure
}
prometheus :9153
proxy . /etc/resolv.conf 8.8.8.8 8.8.4.4
cache 30
}
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: coredns
namespace: kube-system
labels:
dns: coredns
kubernetes.io/name: "CoreDNS"
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
selector:
matchLabels:
dns: coredns
template:
metadata:
labels:
dns: coredns
spec:
serviceAccountName: coredns
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
containers:
- name: coredns
image: coredns/coredns:1.1.1
imagePullPolicy: IfNotPresent
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 9153
name: metrics
protocol: TCP
readinessProbe:
httpGet:
path: /health
port: 8080
livenessProbe:
httpGet:
path: /health
port: 8080
resources:
requests:
cpu: "50m"
limits:
cpu: "100m"
dnsPolicy: Default
volumes:
- name: config-volume
configMap:
name: coredns
items:
- key: Corefile
path: Corefile
---
apiVersion: v1
kind: Service
metadata:
name: coredns
namespace: kube-system
annotations:
labels:
dns: coredns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "CoreDNS"
spec:
selector:
dns: coredns
clusterIP: {{ .DNSClusterIP }}
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
protocol: TCP
`),
},
}
)