manifests.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package dns
  14. const (
  15. // KubeDNSDeployment is the kube-dns Deployment manifest for the kube-dns manifest for v1.7+
  16. KubeDNSDeployment = `
  17. apiVersion: apps/v1
  18. kind: Deployment
  19. metadata:
  20. name: {{ .DeploymentName }}
  21. namespace: kube-system
  22. labels:
  23. k8s-app: kube-dns
  24. spec:
  25. # replicas: not specified here:
  26. # 1. In order to make Addon Manager do not reconcile this replicas parameter.
  27. # 2. Default is 1.
  28. # 3. Will be tuned in real time if DNS horizontal auto-scaling is turned on.
  29. strategy:
  30. rollingUpdate:
  31. maxSurge: 10%
  32. maxUnavailable: 0
  33. selector:
  34. matchLabels:
  35. k8s-app: kube-dns
  36. template:
  37. metadata:
  38. labels:
  39. k8s-app: kube-dns
  40. spec:
  41. priorityClassName: system-cluster-critical
  42. volumes:
  43. - name: kube-dns-config
  44. configMap:
  45. name: kube-dns
  46. optional: true
  47. containers:
  48. - name: kubedns
  49. image: {{ .KubeDNSImage }}
  50. imagePullPolicy: IfNotPresent
  51. resources:
  52. # TODO: Set memory limits when we've profiled the container for large
  53. # clusters, then set request = limit to keep this container in
  54. # guaranteed class. Currently, this container falls into the
  55. # "burstable" category so the kubelet doesn't backoff from restarting it.
  56. limits:
  57. memory: 170Mi
  58. requests:
  59. cpu: 100m
  60. memory: 70Mi
  61. livenessProbe:
  62. httpGet:
  63. path: /healthcheck/kubedns
  64. port: 10054
  65. scheme: HTTP
  66. initialDelaySeconds: 60
  67. timeoutSeconds: 5
  68. successThreshold: 1
  69. failureThreshold: 5
  70. readinessProbe:
  71. httpGet:
  72. path: /readiness
  73. port: 8081
  74. scheme: HTTP
  75. # we poll on pod startup for the Kubernetes control-plane service and
  76. # only setup the /readiness HTTP server once that's available.
  77. initialDelaySeconds: 3
  78. timeoutSeconds: 5
  79. args:
  80. - --domain={{ .DNSDomain }}.
  81. - --dns-port=10053
  82. - --config-dir=/kube-dns-config
  83. - --v=2
  84. env:
  85. - name: PROMETHEUS_PORT
  86. value: "10055"
  87. ports:
  88. - containerPort: 10053
  89. name: dns-local
  90. protocol: UDP
  91. - containerPort: 10053
  92. name: dns-tcp-local
  93. protocol: TCP
  94. - containerPort: 10055
  95. name: metrics
  96. protocol: TCP
  97. volumeMounts:
  98. - name: kube-dns-config
  99. mountPath: /kube-dns-config
  100. - name: dnsmasq
  101. image: {{ .DNSMasqImage }}
  102. imagePullPolicy: IfNotPresent
  103. livenessProbe:
  104. httpGet:
  105. path: /healthcheck/dnsmasq
  106. port: 10054
  107. scheme: HTTP
  108. initialDelaySeconds: 60
  109. timeoutSeconds: 5
  110. successThreshold: 1
  111. failureThreshold: 5
  112. args:
  113. - -v=2
  114. - -logtostderr
  115. - -configDir=/etc/k8s/dns/dnsmasq-nanny
  116. - -restartDnsmasq=true
  117. - --
  118. - -k
  119. - --cache-size=1000
  120. - --no-negcache
  121. - --dns-loop-detect
  122. - --log-facility=-
  123. - --server=/{{ .DNSDomain }}/{{ .DNSBindAddr }}#10053
  124. - --server=/in-addr.arpa/{{ .DNSBindAddr }}#10053
  125. - --server=/ip6.arpa/{{ .DNSBindAddr }}#10053
  126. ports:
  127. - containerPort: 53
  128. name: dns
  129. protocol: UDP
  130. - containerPort: 53
  131. name: dns-tcp
  132. protocol: TCP
  133. # see: https://github.com/kubernetes/kubernetes/issues/29055 for details
  134. resources:
  135. requests:
  136. cpu: 150m
  137. memory: 20Mi
  138. volumeMounts:
  139. - name: kube-dns-config
  140. mountPath: /etc/k8s/dns/dnsmasq-nanny
  141. - name: sidecar
  142. image: {{ .SidecarImage }}
  143. imagePullPolicy: IfNotPresent
  144. livenessProbe:
  145. httpGet:
  146. path: /metrics
  147. port: 10054
  148. scheme: HTTP
  149. initialDelaySeconds: 60
  150. timeoutSeconds: 5
  151. successThreshold: 1
  152. failureThreshold: 5
  153. args:
  154. - --v=2
  155. - --logtostderr
  156. - --probe=kubedns,{{ .DNSProbeAddr }}:10053,kubernetes.default.svc.{{ .DNSDomain }},5,SRV
  157. - --probe=dnsmasq,{{ .DNSProbeAddr }}:53,kubernetes.default.svc.{{ .DNSDomain }},5,SRV
  158. ports:
  159. - containerPort: 10054
  160. name: metrics
  161. protocol: TCP
  162. resources:
  163. requests:
  164. memory: 20Mi
  165. cpu: 10m
  166. dnsPolicy: Default # Don't use cluster DNS.
  167. serviceAccountName: kube-dns
  168. tolerations:
  169. - key: CriticalAddonsOnly
  170. operator: Exists
  171. - key: {{ .ControlPlaneTaintKey }}
  172. effect: NoSchedule
  173. `
  174. // KubeDNSService is the kube-dns Service manifest
  175. KubeDNSService = `
  176. apiVersion: v1
  177. kind: Service
  178. metadata:
  179. labels:
  180. k8s-app: kube-dns
  181. kubernetes.io/cluster-service: "true"
  182. kubernetes.io/name: "KubeDNS"
  183. name: kube-dns
  184. namespace: kube-system
  185. annotations:
  186. prometheus.io/port: "9153"
  187. prometheus.io/scrape: "true"
  188. # Without this resourceVersion value, an update of the Service between versions will yield:
  189. # Service "kube-dns" is invalid: metadata.resourceVersion: Invalid value: "": must be specified for an update
  190. resourceVersion: "0"
  191. spec:
  192. clusterIP: {{ .DNSIP }}
  193. ports:
  194. - name: dns
  195. port: 53
  196. protocol: UDP
  197. targetPort: 53
  198. - name: dns-tcp
  199. port: 53
  200. protocol: TCP
  201. targetPort: 53
  202. - name: metrics
  203. port: 9153
  204. protocol: TCP
  205. targetPort: 9153
  206. selector:
  207. k8s-app: kube-dns
  208. `
  209. // CoreDNSDeployment is the CoreDNS Deployment manifest
  210. CoreDNSDeployment = `
  211. apiVersion: apps/v1
  212. kind: Deployment
  213. metadata:
  214. name: {{ .DeploymentName }}
  215. namespace: kube-system
  216. labels:
  217. k8s-app: kube-dns
  218. spec:
  219. replicas: 2
  220. strategy:
  221. type: RollingUpdate
  222. rollingUpdate:
  223. maxUnavailable: 1
  224. selector:
  225. matchLabels:
  226. k8s-app: kube-dns
  227. template:
  228. metadata:
  229. labels:
  230. k8s-app: kube-dns
  231. spec:
  232. priorityClassName: system-cluster-critical
  233. serviceAccountName: coredns
  234. tolerations:
  235. - key: CriticalAddonsOnly
  236. operator: Exists
  237. - key: {{ .ControlPlaneTaintKey }}
  238. effect: NoSchedule
  239. nodeSelector:
  240. beta.kubernetes.io/os: linux
  241. containers:
  242. - name: coredns
  243. image: {{ .Image }}
  244. imagePullPolicy: IfNotPresent
  245. resources:
  246. limits:
  247. memory: 170Mi
  248. requests:
  249. cpu: 100m
  250. memory: 70Mi
  251. args: [ "-conf", "/etc/coredns/Corefile" ]
  252. volumeMounts:
  253. - name: config-volume
  254. mountPath: /etc/coredns
  255. readOnly: true
  256. ports:
  257. - containerPort: 53
  258. name: dns
  259. protocol: UDP
  260. - containerPort: 53
  261. name: dns-tcp
  262. protocol: TCP
  263. - containerPort: 9153
  264. name: metrics
  265. protocol: TCP
  266. livenessProbe:
  267. httpGet:
  268. path: /health
  269. port: 8080
  270. scheme: HTTP
  271. initialDelaySeconds: 60
  272. timeoutSeconds: 5
  273. successThreshold: 1
  274. failureThreshold: 5
  275. readinessProbe:
  276. httpGet:
  277. path: /health
  278. port: 8080
  279. scheme: HTTP
  280. securityContext:
  281. allowPrivilegeEscalation: false
  282. capabilities:
  283. add:
  284. - NET_BIND_SERVICE
  285. drop:
  286. - all
  287. readOnlyRootFilesystem: true
  288. dnsPolicy: Default
  289. volumes:
  290. - name: config-volume
  291. configMap:
  292. name: coredns
  293. items:
  294. - key: Corefile
  295. path: Corefile
  296. `
  297. // CoreDNSConfigMap is the CoreDNS ConfigMap manifest
  298. CoreDNSConfigMap = `
  299. apiVersion: v1
  300. kind: ConfigMap
  301. metadata:
  302. name: coredns
  303. namespace: kube-system
  304. data:
  305. Corefile: |
  306. .:53 {
  307. errors
  308. health
  309. kubernetes {{ .DNSDomain }} in-addr.arpa ip6.arpa {
  310. pods insecure
  311. upstream
  312. fallthrough in-addr.arpa ip6.arpa
  313. ttl 30
  314. }{{ .Federation }}
  315. prometheus :9153
  316. forward . {{ .UpstreamNameserver }}
  317. cache 30
  318. loop
  319. reload
  320. loadbalance
  321. }{{ .StubDomain }}
  322. `
  323. // CoreDNSClusterRole is the CoreDNS ClusterRole manifest
  324. CoreDNSClusterRole = `
  325. apiVersion: rbac.authorization.k8s.io/v1
  326. kind: ClusterRole
  327. metadata:
  328. name: system:coredns
  329. rules:
  330. - apiGroups:
  331. - ""
  332. resources:
  333. - endpoints
  334. - services
  335. - pods
  336. - namespaces
  337. verbs:
  338. - list
  339. - watch
  340. - apiGroups:
  341. - ""
  342. resources:
  343. - nodes
  344. verbs:
  345. - get
  346. `
  347. // CoreDNSClusterRoleBinding is the CoreDNS Clusterrolebinding manifest
  348. CoreDNSClusterRoleBinding = `
  349. apiVersion: rbac.authorization.k8s.io/v1
  350. kind: ClusterRoleBinding
  351. metadata:
  352. name: system:coredns
  353. roleRef:
  354. apiGroup: rbac.authorization.k8s.io
  355. kind: ClusterRole
  356. name: system:coredns
  357. subjects:
  358. - kind: ServiceAccount
  359. name: coredns
  360. namespace: kube-system
  361. `
  362. // CoreDNSServiceAccount is the CoreDNS ServiceAccount manifest
  363. CoreDNSServiceAccount = `
  364. apiVersion: v1
  365. kind: ServiceAccount
  366. metadata:
  367. name: coredns
  368. namespace: kube-system
  369. `
  370. )