manifests.go 9.4 KB

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