【10】搭建k8s集群系列(二进制部署)之安装Dashboard和CoreDNS ...

打印 上一主题 下一主题

主题 1670|帖子 1670|积分 5010

一、部署Dashboard

1.1、创建kubernetes-dashboard.yaml文件

完整的yaml设置文件信息如下:
  1. # Copyright 2017 The Kubernetes Authors.
  2. #
  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. #
  7. #     http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. apiVersion: v1
  15. kind: Namespace
  16. metadata:
  17.   name: kubernetes-dashboard
  18. ---
  19. apiVersion: v1
  20. kind: ServiceAccount
  21. metadata:
  22.   labels:
  23.     k8s-app: kubernetes-dashboard
  24.   name: kubernetes-dashboard
  25.   namespace: kubernetes-dashboard
  26. ---
  27. kind: Service
  28. apiVersion: v1
  29. metadata:
  30.   labels:
  31.     k8s-app: kubernetes-dashboard
  32.   name: kubernetes-dashboard
  33.   namespace: kubernetes-dashboard
  34. spec:
  35.   type: NodePort
  36.   ports:
  37.     - port: 443
  38.       targetPort: 8443
  39.       nodePort: 30001
  40.   selector:
  41.     k8s-app: kubernetes-dashboard
  42. ---
  43. apiVersion: v1
  44. kind: Secret
  45. metadata:
  46.   labels:
  47.     k8s-app: kubernetes-dashboard
  48.   name: kubernetes-dashboard-certs
  49.   namespace: kubernetes-dashboard
  50. type: Opaque
  51. ---
  52. apiVersion: v1
  53. kind: Secret
  54. metadata:
  55.   labels:
  56.     k8s-app: kubernetes-dashboard
  57.   name: kubernetes-dashboard-csrf
  58.   namespace: kubernetes-dashboard
  59. type: Opaque
  60. data:
  61.   csrf: ""
  62. ---
  63. apiVersion: v1
  64. kind: Secret
  65. metadata:
  66.   labels:
  67.     k8s-app: kubernetes-dashboard
  68.   name: kubernetes-dashboard-key-holder
  69.   namespace: kubernetes-dashboard
  70. type: Opaque
  71. ---
  72. kind: ConfigMap
  73. apiVersion: v1
  74. metadata:
  75.   labels:
  76.     k8s-app: kubernetes-dashboard
  77.   name: kubernetes-dashboard-settings
  78.   namespace: kubernetes-dashboard
  79. ---
  80. kind: Role
  81. apiVersion: rbac.authorization.k8s.io/v1
  82. metadata:
  83.   labels:
  84.     k8s-app: kubernetes-dashboard
  85.   name: kubernetes-dashboard
  86.   namespace: kubernetes-dashboard
  87. rules:
  88.   # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
  89.   - apiGroups: [""]
  90.     resources: ["secrets"]
  91.     resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs", "kubernetes-dashboard-csrf"]
  92.     verbs: ["get", "update", "delete"]
  93.     # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
  94.   - apiGroups: [""]
  95.     resources: ["configmaps"]
  96.     resourceNames: ["kubernetes-dashboard-settings"]
  97.     verbs: ["get", "update"]
  98.     # Allow Dashboard to get metrics.
  99.   - apiGroups: [""]
  100.     resources: ["services"]
  101.     resourceNames: ["heapster", "dashboard-metrics-scraper"]
  102.     verbs: ["proxy"]
  103.   - apiGroups: [""]
  104.     resources: ["services/proxy"]
  105.     resourceNames: ["heapster", "http:heapster:", "https:heapster:", "dashboard-metrics-scraper", "http:dashboard-metrics-scraper"]
  106.     verbs: ["get"]
  107. ---
  108. kind: ClusterRole
  109. apiVersion: rbac.authorization.k8s.io/v1
  110. metadata:
  111.   labels:
  112.     k8s-app: kubernetes-dashboard
  113.   name: kubernetes-dashboard
  114. rules:
  115.   # Allow Metrics Scraper to get metrics from the Metrics server
  116.   - apiGroups: ["metrics.k8s.io"]
  117.     resources: ["pods", "nodes"]
  118.     verbs: ["get", "list", "watch"]
  119. ---
  120. apiVersion: rbac.authorization.k8s.io/v1
  121. kind: RoleBinding
  122. metadata:
  123.   labels:
  124.     k8s-app: kubernetes-dashboard
  125.   name: kubernetes-dashboard
  126.   namespace: kubernetes-dashboard
  127. roleRef:
  128.   apiGroup: rbac.authorization.k8s.io
  129.   kind: Role
  130.   name: kubernetes-dashboard
  131. subjects:
  132.   - kind: ServiceAccount
  133.     name: kubernetes-dashboard
  134.     namespace: kubernetes-dashboard
  135. ---
  136. apiVersion: rbac.authorization.k8s.io/v1
  137. kind: ClusterRoleBinding
  138. metadata:
  139.   name: kubernetes-dashboard
  140. roleRef:
  141.   apiGroup: rbac.authorization.k8s.io
  142.   kind: ClusterRole
  143.   name: kubernetes-dashboard
  144. subjects:
  145.   - kind: ServiceAccount
  146.     name: kubernetes-dashboard
  147.     namespace: kubernetes-dashboard
  148. ---
  149. kind: Deployment
  150. apiVersion: apps/v1
  151. metadata:
  152.   labels:
  153.     k8s-app: kubernetes-dashboard
  154.   name: kubernetes-dashboard
  155.   namespace: kubernetes-dashboard
  156. spec:
  157.   replicas: 1
  158.   revisionHistoryLimit: 10
  159.   selector:
  160.     matchLabels:
  161.       k8s-app: kubernetes-dashboard
  162.   template:
  163.     metadata:
  164.       labels:
  165.         k8s-app: kubernetes-dashboard
  166.     spec:
  167.       containers:
  168.         - name: kubernetes-dashboard
  169.           image: kubernetesui/dashboard:v2.0.0
  170.           imagePullPolicy: Always
  171.           ports:
  172.             - containerPort: 8443
  173.               protocol: TCP
  174.           args:
  175.             - --auto-generate-certificates
  176.             - --namespace=kubernetes-dashboard
  177.             # Uncomment the following line to manually specify Kubernetes API server Host
  178.             # If not specified, Dashboard will attempt to auto discover the API server and connect
  179.             # to it. Uncomment only if the default does not work.
  180.             # - --apiserver-host=http://my-address:port
  181.           volumeMounts:
  182.             - name: kubernetes-dashboard-certs
  183.               mountPath: /certs
  184.               # Create on-disk volume to store exec logs
  185.             - mountPath: /tmp
  186.               name: tmp-volume
  187.           livenessProbe:
  188.             httpGet:
  189.               scheme: HTTPS
  190.               path: /
  191.               port: 8443
  192.             initialDelaySeconds: 30
  193.             timeoutSeconds: 30
  194.           securityContext:
  195.             allowPrivilegeEscalation: false
  196.             readOnlyRootFilesystem: true
  197.             runAsUser: 1001
  198.             runAsGroup: 2001
  199.       volumes:
  200.         - name: kubernetes-dashboard-certs
  201.           secret:
  202.             secretName: kubernetes-dashboard-certs
  203.         - name: tmp-volume
  204.           emptyDir: {}
  205.       serviceAccountName: kubernetes-dashboard
  206.       nodeSelector:
  207.         "kubernetes.io/os": linux
  208.       # Comment the following tolerations if Dashboard must not be deployed on master
  209.       tolerations:
  210.         - key: node-role.kubernetes.io/master
  211.           effect: NoSchedule
  212. ---
  213. kind: Service
  214. apiVersion: v1
  215. metadata:
  216.   labels:
  217.     k8s-app: dashboard-metrics-scraper
  218.   name: dashboard-metrics-scraper
  219.   namespace: kubernetes-dashboard
  220. spec:
  221.   ports:
  222.     - port: 8000
  223.       targetPort: 8000
  224.   selector:
  225.     k8s-app: dashboard-metrics-scraper
  226. ---
  227. kind: Deployment
  228. apiVersion: apps/v1
  229. metadata:
  230.   labels:
  231.     k8s-app: dashboard-metrics-scraper
  232.   name: dashboard-metrics-scraper
  233.   namespace: kubernetes-dashboard
  234. spec:
  235.   replicas: 1
  236.   revisionHistoryLimit: 10
  237.   selector:
  238.     matchLabels:
  239.       k8s-app: dashboard-metrics-scraper
  240.   template:
  241.     metadata:
  242.       labels:
  243.         k8s-app: dashboard-metrics-scraper
  244.       annotations:
  245.         seccomp.security.alpha.kubernetes.io/pod: 'runtime/default'
  246.     spec:
  247.       containers:
  248.         - name: dashboard-metrics-scraper
  249.           image: kubernetesui/metrics-scraper:v1.0.4
  250.           ports:
  251.             - containerPort: 8000
  252.               protocol: TCP
  253.           livenessProbe:
  254.             httpGet:
  255.               scheme: HTTP
  256.               path: /
  257.               port: 8000
  258.             initialDelaySeconds: 30
  259.             timeoutSeconds: 30
  260.           volumeMounts:
  261.           - mountPath: /tmp
  262.             name: tmp-volume
  263.           securityContext:
  264.             allowPrivilegeEscalation: false
  265.             readOnlyRootFilesystem: true
  266.             runAsUser: 1001
  267.             runAsGroup: 2001
  268.       serviceAccountName: kubernetes-dashboard
  269.       nodeSelector:
  270.         "kubernetes.io/os": linux
  271.       # Comment the following tolerations if Dashboard must not be deployed on master
  272.       tolerations:
  273.         - key: node-role.kubernetes.io/master
  274.           effect: NoSchedule
  275.       volumes:
  276.         - name: tmp-volume
  277.           emptyDir: {}
复制代码
1.2、部署和查看

  1. kubectl apply -f kubernetes-dashboard.yaml
  2. # 查看部署
  3. kubectl get pods,svc -n kubernetes-dashboard
复制代码
访问地址:https://NodeIP:30001
创建service account并绑定默认cluster-admin管理员集群脚色
  1. kubectl create serviceaccount dashboard-admin -n kube-system
  2. kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
  3. kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
复制代码
利用输出的token登录Dashboard

二、部署CoreDNS

2.1 创建coredns.yaml,并写入以下内容

  1. # __MACHINE_GENERATED_WARNING__
  2. apiVersion: v1
  3. kind: ServiceAccount
  4. metadata:
  5.   name: coredns
  6.   namespace: kube-system
  7.   labels:
  8.       kubernetes.io/cluster-service: "true"
  9.       addonmanager.kubernetes.io/mode: Reconcile
  10. ---
  11. apiVersion: rbac.authorization.k8s.io/v1
  12. kind: ClusterRole
  13. metadata:
  14.   labels:
  15.     kubernetes.io/bootstrapping: rbac-defaults
  16.     addonmanager.kubernetes.io/mode: Reconcile
  17.   name: system:coredns
  18. rules:
  19. - apiGroups:
  20.   - ""
  21.   resources:
  22.   - endpoints
  23.   - services
  24.   - pods
  25.   - namespaces
  26.   verbs:
  27.   - list
  28.   - watch
  29. - apiGroups:
  30.   - ""
  31.   resources:
  32.   - nodes
  33.   verbs:
  34.   - get
  35. - apiGroups:
  36.   - discovery.k8s.io
  37.   resources:
  38.   - endpointslices
  39.   verbs:
  40.   - list
  41.   - watch
  42. ---
  43. apiVersion: rbac.authorization.k8s.io/v1
  44. kind: ClusterRoleBinding
  45. metadata:
  46.   annotations:
  47.     rbac.authorization.kubernetes.io/autoupdate: "true"
  48.   labels:
  49.     kubernetes.io/bootstrapping: rbac-defaults
  50.     addonmanager.kubernetes.io/mode: EnsureExists
  51.   name: system:coredns
  52. roleRef:
  53.   apiGroup: rbac.authorization.k8s.io
  54.   kind: ClusterRole
  55.   name: system:coredns
  56. subjects:
  57. - kind: ServiceAccount
  58.   name: coredns
  59.   namespace: kube-system
  60. ---
  61. apiVersion: v1
  62. kind: ConfigMap
  63. metadata:
  64.   name: coredns
  65.   namespace: kube-system
  66.   labels:
  67.       addonmanager.kubernetes.io/mode: EnsureExists
  68. data:
  69.   Corefile: |
  70.     .:53 {
  71.         errors
  72.         health {
  73.             lameduck 5s
  74.         }
  75.         ready
  76.         kubernetes cluster.local in-addr.arpa ip6.arpa {
  77.             pods insecure
  78.             fallthrough in-addr.arpa ip6.arpa
  79.             ttl 30
  80.         }
  81.         prometheus :9153
  82.         forward . /etc/resolv.conf {
  83.             max_concurrent 1000
  84.         }
  85.         cache 30
  86.         loop
  87.         reload
  88.         loadbalance
  89.     }
  90. ---
  91. apiVersion: apps/v1
  92. kind: Deployment
  93. metadata:
  94.   name: coredns
  95.   namespace: kube-system
  96.   labels:
  97.     k8s-app: kube-dns
  98.     kubernetes.io/cluster-service: "true"
  99.     addonmanager.kubernetes.io/mode: Reconcile
  100.     kubernetes.io/name: "CoreDNS"
  101. spec:
  102.   # replicas: not specified here:
  103.   # 1. In order to make Addon Manager do not reconcile this replicas parameter.
  104.   # 2. Default is 1.
  105.   # 3. Will be tuned in real time if DNS horizontal auto-scaling is turned on.
  106.   replicas: 1
  107.   strategy:
  108.     type: RollingUpdate
  109.     rollingUpdate:
  110.       maxUnavailable: 1
  111.   selector:
  112.     matchLabels:
  113.       k8s-app: kube-dns
  114.   template:
  115.     metadata:
  116.       labels:
  117.         k8s-app: kube-dns
  118.     spec:
  119.       securityContext:
  120.         seccompProfile:
  121.           type: RuntimeDefault
  122.       priorityClassName: system-cluster-critical
  123.       serviceAccountName: coredns
  124.       affinity:
  125.         podAntiAffinity:
  126.           preferredDuringSchedulingIgnoredDuringExecution:
  127.           - weight: 100
  128.             podAffinityTerm:
  129.               labelSelector:
  130.                 matchExpressions:
  131.                   - key: k8s-app
  132.                     operator: In
  133.                     values: ["kube-dns"]
  134.               topologyKey: kubernetes.io/hostname
  135.       tolerations:
  136.         - key: "CriticalAddonsOnly"
  137.           operator: "Exists"
  138.       nodeSelector:
  139.         kubernetes.io/os: linux
  140.       containers:
  141.       - name: coredns
  142.         image: coredns/coredns:v1.8.6
  143.         imagePullPolicy: IfNotPresent
  144.         resources:
  145.           limits:
  146.             memory: 500Mi
  147.           requests:
  148.             cpu: 100m
  149.             memory: 70Mi
  150.         args: [ "-conf", "/etc/coredns/Corefile" ]
  151.         volumeMounts:
  152.         - name: config-volume
  153.           mountPath: /etc/coredns
  154.           readOnly: true
  155.         ports:
  156.         - containerPort: 53
  157.           name: dns
  158.           protocol: UDP
  159.         - containerPort: 53
  160.           name: dns-tcp
  161.           protocol: TCP
  162.         - containerPort: 9153
  163.           name: metrics
  164.           protocol: TCP
  165.         livenessProbe:
  166.           httpGet:
  167.             path: /health
  168.             port: 8080
  169.             scheme: HTTP
  170.           initialDelaySeconds: 60
  171.           timeoutSeconds: 5
  172.           successThreshold: 1
  173.           failureThreshold: 5
  174.         readinessProbe:
  175.           httpGet:
  176.             path: /ready
  177.             port: 8181
  178.             scheme: HTTP
  179.         securityContext:
  180.           allowPrivilegeEscalation: false
  181.           capabilities:
  182.             add:
  183.             - NET_BIND_SERVICE
  184.             drop:
  185.             - all
  186.           readOnlyRootFilesystem: true
  187.       dnsPolicy: Default
  188.       volumes:
  189.         - name: config-volume
  190.           configMap:
  191.             name: coredns
  192.             items:
  193.             - key: Corefile
  194.               path: Corefile
  195. ---
  196. apiVersion: v1
  197. kind: Service
  198. metadata:
  199.   name: kube-dns
  200.   namespace: kube-system
  201.   annotations:
  202.     prometheus.io/port: "9153"
  203.     prometheus.io/scrape: "true"
  204.   labels:
  205.     k8s-app: kube-dns
  206.     kubernetes.io/cluster-service: "true"
  207.     addonmanager.kubernetes.io/mode: Reconcile
  208.     kubernetes.io/name: "CoreDNS"
  209. spec:
  210.   selector:
  211.     k8s-app: kube-dns
  212.   clusterIP: 10.0.0.2
  213.   ports:
  214.   - name: dns
  215.     port: 53
  216.     protocol: UDP
  217.   - name: dns-tcp
  218.     port: 53
  219.     protocol: TCP
  220.   - name: metrics
  221.     port: 9153
  222.     protocol: TCP
复制代码
2.2 执行部署coredns

  1. kubectl apply -f coredns.yaml
  2. # 查看coredns运行是否正常
  3. kubectl get pods -n kube-system  
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

大连密封材料

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表