kilo-k3s-userspace.yaml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: kilo
  5. namespace: kube-system
  6. labels:
  7. app.kubernetes.io/name: kilo
  8. data:
  9. cni-conf.json: |
  10. {
  11. "cniVersion":"0.4.0",
  12. "name":"kilo",
  13. "plugins":[
  14. {
  15. "name":"kubernetes",
  16. "type":"bridge",
  17. "bridge":"kube-bridge",
  18. "isDefaultGateway":true,
  19. "forceAddress":true,
  20. "mtu": 1420,
  21. "ipam":{
  22. "type":"host-local"
  23. }
  24. },
  25. {
  26. "type":"portmap",
  27. "snat":true,
  28. "capabilities":{
  29. "portMappings":true
  30. }
  31. }
  32. ]
  33. }
  34. ---
  35. apiVersion: v1
  36. kind: ServiceAccount
  37. metadata:
  38. name: kilo
  39. namespace: kube-system
  40. ---
  41. apiVersion: rbac.authorization.k8s.io/v1
  42. kind: ClusterRole
  43. metadata:
  44. name: kilo
  45. rules:
  46. - apiGroups:
  47. - ""
  48. resources:
  49. - nodes
  50. verbs:
  51. - list
  52. - patch
  53. - watch
  54. - apiGroups:
  55. - kilo.squat.ai
  56. resources:
  57. - peers
  58. verbs:
  59. - list
  60. - watch
  61. - apiGroups:
  62. - apiextensions.k8s.io
  63. resources:
  64. - customresourcedefinitions
  65. verbs:
  66. - get
  67. ---
  68. apiVersion: rbac.authorization.k8s.io/v1
  69. kind: ClusterRoleBinding
  70. metadata:
  71. name: kilo
  72. roleRef:
  73. apiGroup: rbac.authorization.k8s.io
  74. kind: ClusterRole
  75. name: kilo
  76. subjects:
  77. - kind: ServiceAccount
  78. name: kilo
  79. namespace: kube-system
  80. ---
  81. ---
  82. apiVersion: v1
  83. kind: ConfigMap
  84. metadata:
  85. name: kilo-scripts
  86. namespace: kube-system
  87. data:
  88. init.sh: |
  89. #!/bin/sh
  90. cat > /etc/kubernetes/kubeconfig <<EOF
  91. apiVersion: v1
  92. kind: Config
  93. clusters:
  94. - cluster:
  95. server: $(sed -n 's/.*server: \(.*\)/\1/p' /var/lib/rancher/k3s/agent/kubelet.kubeconfig)
  96. certificate-authority: /var/lib/rancher/k3s/agent/server-ca.crt
  97. name: kilo
  98. users:
  99. - name: kilo
  100. user:
  101. token: $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
  102. contexts:
  103. - name: kilo
  104. context:
  105. cluster: kilo
  106. namespace: ${NAMESPACE}
  107. user: kilo
  108. current-context: kilo
  109. EOF
  110. ---
  111. apiVersion: apps/v1
  112. kind: DaemonSet
  113. metadata:
  114. name: kilo
  115. namespace: kube-system
  116. labels:
  117. app.kubernetes.io/name: kilo-userspace
  118. app.kubernetes.io/part-of: kilo
  119. spec:
  120. selector:
  121. matchLabels:
  122. app.kubernetes.io/name: kilo-userspace
  123. app.kubernetes.io/part-of: kilo
  124. template:
  125. metadata:
  126. labels:
  127. app.kubernetes.io/name: kilo-userspace
  128. app.kubernetes.io/part-of: kilo
  129. spec:
  130. serviceAccountName: kilo
  131. hostNetwork: true
  132. containers:
  133. - name: kilo
  134. image: squat/kilo:0.7.0
  135. args:
  136. - --kubeconfig=/etc/kubernetes/kubeconfig
  137. - --hostname=$(NODE_NAME)
  138. - --create-interface=false
  139. - --interface=kilo0
  140. env:
  141. - name: NODE_NAME
  142. valueFrom:
  143. fieldRef:
  144. fieldPath: spec.nodeName
  145. ports:
  146. - containerPort: 1107
  147. name: metrics
  148. securityContext:
  149. privileged: true
  150. volumeMounts:
  151. - name: cni-conf-dir
  152. mountPath: /etc/cni/net.d
  153. - name: kilo-dir
  154. mountPath: /var/lib/kilo
  155. - name: kubeconfig
  156. mountPath: /etc/kubernetes
  157. readOnly: true
  158. - name: lib-modules
  159. mountPath: /lib/modules
  160. readOnly: true
  161. - name: xtables-lock
  162. mountPath: /run/xtables.lock
  163. readOnly: false
  164. - name: wireguard
  165. mountPath: /var/run/wireguard
  166. readOnly: false
  167. - name: k3s-agent
  168. mountPath: /var/lib/rancher/k3s/agent/
  169. readOnly: true
  170. - name: wireguard
  171. image: ghcr.io/masipcat/wireguard-go-docker:0.0.20230223
  172. args:
  173. - wireguard-go
  174. - --foreground
  175. - kilo0
  176. securityContext:
  177. privileged: true
  178. volumeMounts:
  179. - name: wireguard
  180. mountPath: /var/run/wireguard
  181. readOnly: false
  182. initContainers:
  183. - name: generate-kubeconfig
  184. image: squat/kilo:0.7.0
  185. command:
  186. - /bin/sh
  187. args:
  188. - /scripts/init.sh
  189. imagePullPolicy: Always
  190. volumeMounts:
  191. - name: kubeconfig
  192. mountPath: /etc/kubernetes
  193. - name: scripts
  194. mountPath: /scripts/
  195. readOnly: true
  196. - name: k3s-agent
  197. mountPath: /var/lib/rancher/k3s/agent/
  198. readOnly: true
  199. env:
  200. - name: NAMESPACE
  201. valueFrom:
  202. fieldRef:
  203. fieldPath: metadata.namespace
  204. - name: install-cni
  205. image: squat/kilo:0.7.0
  206. command:
  207. - /bin/sh
  208. - -c
  209. - |
  210. set -e -x;
  211. cp /opt/cni/bin/* /host/opt/cni/bin/;
  212. TMP_CONF="$CNI_CONF_NAME".tmp;
  213. echo "$CNI_NETWORK_CONFIG" > $TMP_CONF;
  214. rm -f /host/etc/cni/net.d/*;
  215. mv $TMP_CONF /host/etc/cni/net.d/$CNI_CONF_NAME
  216. env:
  217. - name: CNI_CONF_NAME
  218. value: 10-kilo.conflist
  219. - name: CNI_NETWORK_CONFIG
  220. valueFrom:
  221. configMapKeyRef:
  222. name: kilo
  223. key: cni-conf.json
  224. volumeMounts:
  225. - name: cni-bin-dir
  226. mountPath: /host/opt/cni/bin
  227. - name: cni-conf-dir
  228. mountPath: /host/etc/cni/net.d
  229. tolerations:
  230. - effect: NoSchedule
  231. operator: Exists
  232. - effect: NoExecute
  233. operator: Exists
  234. volumes:
  235. - name: cni-bin-dir
  236. hostPath:
  237. path: /opt/cni/bin
  238. - name: cni-conf-dir
  239. hostPath:
  240. path: /etc/cni/net.d
  241. - name: kilo-dir
  242. hostPath:
  243. path: /var/lib/kilo
  244. - name: kubeconfig
  245. emptyDir: {}
  246. - name: scripts
  247. configMap:
  248. name: kilo-scripts
  249. - name: k3s-agent
  250. hostPath:
  251. path: /var/lib/rancher/k3s/agent
  252. - name: lib-modules
  253. hostPath:
  254. path: /lib/modules
  255. - name: xtables-lock
  256. hostPath:
  257. path: /run/xtables.lock
  258. type: FileOrCreate
  259. - name: wireguard
  260. hostPath:
  261. path: /var/run/wireguard