kilo-k3s-userspace.yaml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. name: kilo
  94. clusters:
  95. - cluster:
  96. server: $(sed -n 's/.*server: \(.*\)/\1/p' /var/lib/rancher/k3s/agent/kubelet.kubeconfig)
  97. certificate-authority: /var/lib/rancher/k3s/agent/server-ca.crt
  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: wireguard
  168. image: masipcat/wireguard-go:0.0.20230223:cc19859
  169. args:
  170. - wireguard-go
  171. - --foreground
  172. - kilo0
  173. securityContext:
  174. privileged: true
  175. volumeMounts:
  176. - name: wireguard
  177. mountPath: /var/run/wireguard
  178. readOnly: false
  179. initContainers:
  180. - name: generate-kubeconfig
  181. image: squat/kilo:0.7.0
  182. command:
  183. - /bin/sh
  184. args:
  185. - /scripts/init.sh
  186. imagePullPolicy: Always
  187. volumeMounts:
  188. - name: kubeconfig
  189. mountPath: /etc/kubernetes
  190. - name: scripts
  191. mountPath: /scripts/
  192. readOnly: true
  193. - name: k3s-agent
  194. mountPath: /var/lib/rancher/k3s/agent/
  195. readOnly: true
  196. env:
  197. - name: NAMESPACE
  198. valueFrom:
  199. fieldRef:
  200. fieldPath: metadata.namespace
  201. - name: install-cni
  202. image: squat/kilo:0.7.0
  203. command:
  204. - /bin/sh
  205. - -c
  206. - |
  207. set -e -x;
  208. cp /opt/cni/bin/* /host/opt/cni/bin/;
  209. TMP_CONF="$CNI_CONF_NAME".tmp;
  210. echo "$CNI_NETWORK_CONFIG" > $TMP_CONF;
  211. rm -f /host/etc/cni/net.d/*;
  212. mv $TMP_CONF /host/etc/cni/net.d/$CNI_CONF_NAME
  213. env:
  214. - name: CNI_CONF_NAME
  215. value: 10-kilo.conflist
  216. - name: CNI_NETWORK_CONFIG
  217. valueFrom:
  218. configMapKeyRef:
  219. name: kilo
  220. key: cni-conf.json
  221. volumeMounts:
  222. - name: cni-bin-dir
  223. mountPath: /host/opt/cni/bin
  224. - name: cni-conf-dir
  225. mountPath: /host/etc/cni/net.d
  226. tolerations:
  227. - effect: NoSchedule
  228. operator: Exists
  229. - effect: NoExecute
  230. operator: Exists
  231. volumes:
  232. - name: cni-bin-dir
  233. hostPath:
  234. path: /opt/cni/bin
  235. - name: cni-conf-dir
  236. hostPath:
  237. path: /etc/cni/net.d
  238. - name: kilo-dir
  239. hostPath:
  240. path: /var/lib/kilo
  241. - name: kubeconfig
  242. emptyDir: {}
  243. - name: scripts
  244. configMap:
  245. name: kilo-scripts
  246. - name: k3s-agent
  247. hostPath:
  248. path: /var/lib/rancher/k3s/agent
  249. - name: lib-modules
  250. hostPath:
  251. path: /lib/modules
  252. - name: xtables-lock
  253. hostPath:
  254. path: /run/xtables.lock
  255. type: FileOrCreate
  256. - name: wireguard
  257. hostPath:
  258. path: /var/run/wireguard