Kubernetes Dashboard 與DNS部署
環境說明
Node-1(Master): 10.0.0.1
Node-2: 10.0.0.2
Node-3: 10.0.0.3
集群使用二進制安裝,並已部署flannel網絡插件。
kube-DNS
在進行如下的操作時,你必須已經部署好了K8S的集群,如果你還沒有這樣的集群,請參考我之前的博文。
1、在官網找到對應的yaml文件,地址為:https://github.com/kubernetes/kubernetes/tree/2f011d01fa542633184cde4bba97d006b8d06309/cluster/addons/dns/coredns , 我們修改相關配置,主要是ClusterIP的配置信息和鏡像路徑:
apiVersion: v1 kind: ServiceAccount metadata: name: coredns namespace: kube-system labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: Reconcile name: system:coredns rules: - apiGroups: - "" resources: - endpoints - services - pods - namespaces verbs: - list - watch --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "true" labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: EnsureExists name: system:coredns roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:coredns subjects: - kind: ServiceAccount name: coredns namespace: kube-system --- apiVersion: v1 kind: ConfigMap metadata: name: coredns namespace: kube-system labels: addonmanager.kubernetes.io/mode: EnsureExists data: Corefile: | .:53 { errors health kubernetes cluster.local. in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa } prometheus :9153 proxy . /etc/resolv.conf cache 30 } --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: coredns namespace: kube-system labels: k8s-app: coredns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "CoreDNS" spec: replicas: 2 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 selector: matchLabels: k8s-app: coredns template: metadata: labels: k8s-app: coredns spec: serviceAccountName: coredns tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule - key: "CriticalAddonsOnly" operator: "Exists" containers: - name: coredns image: coredns/coredns:1.0.6 imagePullPolicy: IfNotPresent resources: limits: memory: 170Mi requests: cpu: 100m memory: 70Mi args: [ "-conf", "/etc/coredns/Corefile" ] volumeMounts: - name: config-volume mountPath: /etc/coredns ports: - containerPort: 53 name: dns protocol: UDP - containerPort: 53 name: dns-tcp protocol: TCP livenessProbe: httpGet: path: /health port: 8080 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 dnsPolicy: Default volumes: - name: config-volume configMap: name: coredns items: - key: Corefile path: Corefile --- apiVersion: v1 kind: Service metadata: name: coredns namespace: kube-system labels: k8s-app: coredns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "CoreDNS" spec: selector: k8s-app: coredns clusterIP: 10.222.0.100 ports: - name: dns port: 53 protocol: UDP - name: dns-tcp port: 53 protocol: TCP
執行此yaml文件:
kubectl create -f coredns.yaml
查看文件狀態:
[root@node-1 ~]# kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-77c989547b-2rg9h 1/1 Running 0 1h coredns-77c989547b-cbj5h 1/1 Running 0 1h [root@node-1 ~]# kubectl get rs -n kube-system NAME DESIRED CURRENT READY AGE coredns-77c989547b 2 2 2 1h [root@node-1 ~]# kubectl get svc -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE coredns ClusterIP 10.222.0.100 <none> 53/UDP,53/TCP 1h
配置Dashboard
下載官方的yaml文件,執行如下命令:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
只有安裝了dns服務才能使用dashboard,否則將無法找到dashboard的service。
當dashboard服務啟動後查看服務是否正常:
[root@node-1 ~]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-77c989547b-2rg9h 1/1 Running 0 2h
coredns-77c989547b-cbj5h 1/1 Running 0 2h
kubernetes-dashboard-7d5dcdb6d9-h66fs 1/1 Running 0 1h
[root@node-1 ~]# kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
coredns ClusterIP 10.222.0.100 <none> 53/UDP,53/TCP 2h
kubernetes-dashboard ClusterIP 10.222.251.161 <none> 443/TCP 1h
使用代理,執行如下命令:
[root@node-1 ~]# kubectl proxy --port=8001 --address=‘10.0.0.1‘ --accept-hosts=‘^.*‘
Starting to serve on 10.0.0.1:8001
在瀏覽器中輸入地址:http://10.0.0.1:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
如果不出意外,會看到如下界面:
按照此提示創建用戶 https://github.com/kubernetes/dashboard/wiki/Creating-sample-user
之後獲取token,使用token登錄:
kubectl describe secret -n kube-system `kubectl get secret -n kube-system |grep admin-user |awk ‘{print $1}‘`
也可以通過master節點登錄,訪問此地址:https://10.0.0.1:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
登錄成功後顯示主界面:
Kubernetes Dashboard 與DNS部署