目的

使用CoreDNS实现对k8s内部域名解析

说明

这部分使用CoreDNS
群集域名: cluster.local 地址:10.254.0.0/16 群集服务地址: 10.254.0.10

创建coreDNS 的sa,rbac,Deployment和svc,文件为:Coredns.yaml

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. name: kubernetes
  5. namespace: kube-system
  6. ---
  7. apiVersion: rbac.authorization.k8s.io/v1beta1
  8. kind: ClusterRole
  9. metadata:
  10. labels:
  11. kubernetes.io/bootstrapping: rbac-defaults
  12. name: system:kubernetes
  13. rules:
  14. - apiGroups:
  15. - ""
  16. resources:
  17. - endpoints
  18. - services
  19. - pods
  20. - nodes
  21. - namespaces
  22. verbs:
  23. - get
  24. - list
  25. - watch
  26. ---
  27. apiVersion: rbac.authorization.k8s.io/v1beta1
  28. kind: ClusterRoleBinding
  29. metadata:
  30. annotations:
  31. rbac.authorization.kubernetes.io/autoupdate: "true"
  32. labels:
  33. kubernetes.io/bootstrapping: rbac-defaults
  34. name: system:kubernetes
  35. roleRef:
  36. apiGroup: rbac.authorization.k8s.io
  37. kind: ClusterRole
  38. name: system:kubernetes
  39. subjects:
  40. - kind: ServiceAccount
  41. name: kubernetes
  42. namespace: kube-system
  43. ---
  44. apiVersion: v1
  45. kind: ConfigMap
  46. metadata:
  47. name: coredns
  48. namespace: kube-system
  49. data:
  50. Corefile: |
  51. .:53 {
  52. errors
  53. health
  54. kubernetes cluster.local 10.254.0.0/16 {
  55. #pods insecure
  56. upstream /etc/resolv.conf
  57. }
  58. prometheus :9153
  59. proxy . /etc/resolv.conf
  60. cache 30
  61. }
  62. ---
  63. apiVersion: extensions/v1beta1
  64. kind: Deployment
  65. metadata:
  66. name: coredns
  67. namespace: kube-system
  68. labels:
  69. k8s-app: coredns
  70. kubernetes.io/name: "CoreDNS"
  71. spec:
  72. replicas: 2
  73. strategy:
  74. type: RollingUpdate
  75. rollingUpdate:
  76. maxUnavailable: 1
  77. selector:
  78. matchLabels:
  79. k8s-app: coredns
  80. template:
  81. metadata:
  82. labels:
  83. k8s-app: coredns
  84. spec:
  85. serviceAccountName: kubernetes
  86. tolerations:
  87. - key: node-role.kubernetes.io/master
  88. effect: NoSchedule
  89. - key: "CriticalAddonsOnly"
  90. operator: "Exists"
  91. containers:
  92. - name: coredns
  93. image: hub.k8s.com/apps/coredns:1.0.3
  94. imagePullPolicy: IfNotPresent
  95. args: [ "-conf", "/etc/coredns/Corefile" ]
  96. volumeMounts:
  97. - name: config-volume
  98. mountPath: /etc/coredns
  99. ports:
  100. - containerPort: 53
  101. name: dns
  102. protocol: UDP
  103. - containerPort: 53
  104. name: dns-tcp
  105. protocol: TCP
  106. livenessProbe:
  107. httpGet:
  108. path: /health
  109. port: 8080
  110. scheme: HTTP
  111. initialDelaySeconds: 60
  112. timeoutSeconds: 5
  113. successThreshold: 1
  114. failureThreshold: 5
  115. dnsPolicy: Default
  116. volumes:
  117. - name: config-volume
  118. configMap:
  119. name: coredns
  120. items:
  121. - key: Corefile
  122. path: Corefile
  123. ---
  124. apiVersion: v1
  125. kind: Service
  126. metadata:
  127. name: kube-dns
  128. namespace: kube-system
  129. labels:
  130. k8s-app: coredns
  131. kubernetes.io/cluster-service: "true"
  132. kubernetes.io/name: "CoreDNS"
  133. spec:
  134. selector:
  135. k8s-app: coredns
  136. clusterIP: 10.254.0.10
  137. ports:
  138. - name: dns
  139. port: 53
  140. protocol: UDP
  141. - name: dns-tcp
  142. port: 53
  143. protocol: TCP

验证