kilo-k3s.yaml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. apiVersion: v1
  82. kind: ConfigMap
  83. metadata:
  84. name: kilo-scripts
  85. namespace: kube-system
  86. data:
  87. init.sh: |
  88. #!/bin/sh
  89. cat > /etc/kubernetes/kubeconfig <<EOF
  90. apiVersion: v1
  91. kind: Config
  92. name: kilo
  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. users:
  98. - name: kilo
  99. user:
  100. token: $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
  101. contexts:
  102. - name: kilo
  103. context:
  104. cluster: kilo
  105. namespace: ${NAMESPACE}
  106. user: kilo
  107. current-context: kilo
  108. EOF
  109. ---
  110. apiVersion: apps/v1
  111. kind: DaemonSet
  112. metadata:
  113. name: kilo
  114. namespace: kube-system
  115. labels:
  116. app.kubernetes.io/name: kilo
  117. app.kubernetes.io/part-of: kilo
  118. spec:
  119. selector:
  120. matchLabels:
  121. app.kubernetes.io/name: kilo
  122. app.kubernetes.io/part-of: kilo
  123. template:
  124. metadata:
  125. labels:
  126. app.kubernetes.io/name: kilo
  127. app.kubernetes.io/part-of: kilo
  128. spec:
  129. serviceAccountName: kilo
  130. hostNetwork: true
  131. containers:
  132. - name: kilo
  133. image: squat/kilo:0.6.0
  134. args:
  135. - --kubeconfig=/etc/kubernetes/kubeconfig
  136. - --hostname=$(NODE_NAME)
  137. env:
  138. - name: NODE_NAME
  139. valueFrom:
  140. fieldRef:
  141. fieldPath: spec.nodeName
  142. ports:
  143. - containerPort: 1107
  144. name: metrics
  145. securityContext:
  146. privileged: true
  147. volumeMounts:
  148. - name: cni-conf-dir
  149. mountPath: /etc/cni/net.d
  150. - name: kilo-dir
  151. mountPath: /var/lib/kilo
  152. - name: kubeconfig
  153. mountPath: /etc/kubernetes
  154. readOnly: true
  155. - name: lib-modules
  156. mountPath: /lib/modules
  157. readOnly: true
  158. - name: xtables-lock
  159. mountPath: /run/xtables.lock
  160. readOnly: false
  161. initContainers:
  162. - name: generate-kubeconfig
  163. image: squat/kilo:0.6.0
  164. command:
  165. - /bin/sh
  166. args:
  167. - /scripts/init.sh
  168. imagePullPolicy: Always
  169. volumeMounts:
  170. - name: kubeconfig
  171. mountPath: /etc/kubernetes
  172. - name: scripts
  173. mountPath: /scripts/
  174. readOnly: true
  175. - name: k3s-agent
  176. mountPath: /var/lib/rancher/k3s/agent/
  177. readOnly: true
  178. env:
  179. - name: NAMESPACE
  180. valueFrom:
  181. fieldRef:
  182. fieldPath: metadata.namespace
  183. - name: install-cni
  184. image: squat/kilo:0.6.0
  185. command:
  186. - /bin/sh
  187. - -c
  188. - |
  189. set -e -x;
  190. cp /opt/cni/bin/* /host/opt/cni/bin/;
  191. TMP_CONF="$CNI_CONF_NAME".tmp;
  192. echo "$CNI_NETWORK_CONFIG" > $TMP_CONF;
  193. rm -f /host/etc/cni/net.d/*;
  194. mv $TMP_CONF /host/etc/cni/net.d/$CNI_CONF_NAME
  195. env:
  196. - name: CNI_CONF_NAME
  197. value: 10-kilo.conflist
  198. - name: CNI_NETWORK_CONFIG
  199. valueFrom:
  200. configMapKeyRef:
  201. name: kilo
  202. key: cni-conf.json
  203. volumeMounts:
  204. - name: cni-bin-dir
  205. mountPath: /host/opt/cni/bin
  206. - name: cni-conf-dir
  207. mountPath: /host/etc/cni/net.d
  208. tolerations:
  209. - effect: NoSchedule
  210. operator: Exists
  211. - effect: NoExecute
  212. operator: Exists
  213. volumes:
  214. - name: cni-bin-dir
  215. hostPath:
  216. path: /opt/cni/bin
  217. - name: cni-conf-dir
  218. hostPath:
  219. path: /etc/cni/net.d
  220. - name: kilo-dir
  221. hostPath:
  222. path: /var/lib/kilo
  223. - name: kubeconfig
  224. emptyDir: {}
  225. - name: scripts
  226. configMap:
  227. name: kilo-scripts
  228. - name: k3s-agent
  229. hostPath:
  230. path: /var/lib/rancher/k3s/agent
  231. - name: lib-modules
  232. hostPath:
  233. path: /lib/modules
  234. - name: xtables-lock
  235. hostPath:
  236. path: /run/xtables.lock
  237. type: FileOrCreate