-
Notifications
You must be signed in to change notification settings - Fork 200
/
kins_server.go
218 lines (217 loc) · 6.15 KB
/
kins_server.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
package manifest
const KinsServerTemplate = `
apiVersion: v1
kind: Service
metadata:
name: {{ .KinsServerName }}-init
namespace: {{ .KinsNamespace }}
labels:
{{ .KinsResourceLabelKey }}: "yes"
{{ .UnitName }}: {{ .NodeUnitSuperedge }}
spec:
ports:
- port: 6443
name: https
clusterIP: None
selector:
site.superedge.io/nodeunit: {{ .UnitName }}
site.superedge.io/kins-role: server
site.superedge.io/server-type: init
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
{{ .KinsResourceLabelKey }}: "yes"
{{ .UnitName }}: {{ .NodeUnitSuperedge }}
name: {{ .KinsServerName }}
namespace: {{ .KinsNamespace }}
spec:
replicas: 1
serviceName: {{ .KinsServerName }}-init
selector:
matchLabels:
site.superedge.io/nodeunit: {{ .UnitName }}
site.superedge.io/kins-role: server
site.superedge.io/server-type: init
template:
metadata:
labels:
site.superedge.io/nodeunit: {{ .UnitName }}
site.superedge.io/kins-role: server
site.superedge.io/server-type: init
name: k3s-server
spec:
tolerations:
- key: "{{ .KinsTaintKey }}"
operator: "Exists"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .KinsRoleLabelKey }}
operator: In
values:
- {{ .KinsRoleLabelServer }}
- key: {{ .UnitName }}
operator: In
values:
- {{ .NodeUnitSuperedge }}
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: {{ .KinsRoleLabelKey }}
operator: In
values:
- {{ .KinsRoleLabelServer }}
- {{ .KinsRoleLabelAgent }}
topologyKey: kubernetes.io/hostname
initContainers:
- name: mkcgroup
image: {{ .K3SServerImage }}
imagePullPolicy: IfNotPresent
env:
- name: K3S_TOKEN
valueFrom:
secretKeyRef:
name: {{ .KinsSecretName }}
key: k3stoken
optional: false
command:
- /bin/sh
- -cx
- |
set -o pipefail
for d in $(ls /sys/fs/cgroup)
do
mkdir -p /sys/fs/cgroup/$d/edgek3s
done
volumeMounts:
- name: host-sys
mountPath: /sys
- name: rancher-root
mountPath: /var/lib/rancher
containers:
- name: server
image: {{ .K3SServerImage }}
env:
- name: K3S_TOKEN
valueFrom:
secretKeyRef:
name: {{ .KinsSecretName }}
key: k3stoken
optional: false
- name: K3S_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
securityContext:
privileged: true
command: ["/k3s"]
args:
- server
- --container-runtime-endpoint=/run/kins.sock
- --flannel-backend=none
- --disable-kube-proxy
- --disable-cloud-controller
- --cluster-cidr=169.254.0.0/16
- --service-cidr={{ .ServiceCIDR }}
- --service-node-port-range={{ .KinsNodePortRange }}
- --cluster-dns={{ .KinsCorednsIP }}
- --kube-apiserver-arg=--token-auth-file=/etc/edge/known_tokens.csv
- --kubelet-arg=--cgroup-root=/edgek3s
- --kubelet-arg=--root-dir=/data/edge/rancher-kubelet
- --cluster-init
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- |
set -x
set -o pipefail
rm -rf /var/lib/rancher/*
rm -rf /etc/rancher/*
rm -rf /data/edge/rancher-kubelet/*
rm -rf /data/edge/log/*
ports:
- containerPort: 6443
volumeMounts:
- name: host-run
mountPath: /run
mountPropagation: "Bidirectional"
- name: host-dev
mountPath: /dev
- name: host-sys
mountPath: /sys
mountPropagation: "Bidirectional"
- name: lib-modules
mountPath: /lib/modules
readOnly: true
- name: host-containerd
mountPath: /var/lib/containerd
- name: host-docker
mountPath: /var/lib/docker
- name: host-kubelet-log
mountPath: /data/edge/log/pods
- name: k3sroot
mountPath: /data/edge/rancher-kubelet
mountPropagation: "Bidirectional"
- name: rancher-root
mountPath: /var/lib/rancher
- name: rancher-etc
mountPath: /etc/rancher
- mountPath: /etc/edge/
name: token
readOnly: true
volumes:
- hostPath:
path: /run
name: host-run
- hostPath:
path: /lib/modules
name: lib-modules
- name: host-dev
hostPath:
path: /dev
- name: host-sys
hostPath:
path: /sys
- name: host-containerd
hostPath:
path: /var/lib/containerd
- name: host-docker
hostPath:
path: /var/lib/docker
- name: host-kubelet-log
hostPath:
path: /data/edge/log/pods
- name: k3sroot
hostPath:
path: /data/edge/rancher-kubelet
type: DirectoryOrCreate
- hostPath:
path: /data/edge/rancher-etc
name: rancher-etc
- secret:
defaultMode: 420
secretName: {{ .KinsSecretName }}
items:
- key: known_tokens.csv
path: known_tokens.csv
name: token
volumeClaimTemplates:
- metadata:
name: rancher-root
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "kins-localvolume"
resources:
requests:
storage: 10Gi
`