K8S 安装 Dashboard

1、在 master 节点执行

本例 k8s 是 v1.17.2,对应的 dashboard 是 v2.0.0-rc5 这个版本,

具体去这里查看对应的版本 Releases · kubernetes/dashboard · GitHub

wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc5/aio/deploy/recommended.yaml

# 创建 pod
kubectl apply -f recommended.yaml

2、查看,成功创建

[root@master1 ~]# kubectl get pods --all-namespaces
NAMESPACE              NAME                                         READY   STATUS    RESTARTS   AGE
default                nginx-5578584966-ch9x4                       1/1     Running   1          8h
kube-system            coredns-9d85f5447-qghnb                      1/1     Running   38         6d13h
kube-system            coredns-9d85f5447-xqsl2                      1/1     Running   37         6d13h
kube-system            etcd-master1                                 1/1     Running   8          6d13h
kube-system            kube-apiserver-master1                       1/1     Running   9          6d13h
kube-system            kube-controller-manager-master1              1/1     Running   8          6d13h
kube-system            kube-flannel-ds-amd64-h2f4w                  1/1     Running   5          6d10h
kube-system            kube-flannel-ds-amd64-z57qk                  1/1     Running   1          10h
kube-system            kube-proxy-4j8pj                             1/1     Running   1          10h
kube-system            kube-proxy-xk7gq                             1/1     Running   7          6d13h
kube-system            kube-scheduler-master1                       1/1     Running   9          6d13h
kubernetes-dashboard   dashboard-metrics-scraper-7b8b58dc8b-5r22j   1/1     Running   0          15m
kubernetes-dashboard   kubernetes-dashboard-866f987876-gv2qw        1/1     Running   0          15m

3、 删除现有的dashboard服务,dashboard 服务的 namespace 是 kubernetes-dashboard,但是该服务的类型是ClusterIP,不便于我们通过浏览器访问,因此需要改成NodePort型的

# 查看 现有的服务
[root@master1 ~]# kubectl get svc --all-namespaces
NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP   10.96.0.1                443/TCP                  6d13h
default                nginx                       NodePort    10.102.220.172           80:31863/TCP             8h
kube-system            kube-dns                    ClusterIP   10.96.0.10               53/UDP,53/TCP,9153/TCP   6d13h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.100.246.255           8000/TCP                 61s
kubernetes-dashboard   kubernetes-dashboard        ClusterIP   10.109.210.35            443/TCP                  61s
# 删除
kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard

4、创建配置文件

vim dashboard-svc.yaml

# 内容
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard


# 执行
kubectl apply -f dashboard-svc.yaml

 5、再次查看服务,成功

[root@master1 ~]# kubectl get svc --all-namespaces
NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP   10.96.0.1                443/TCP                  6d13h
default                nginx                       NodePort    10.102.220.172           80:31863/TCP             8h
kube-system            kube-dns                    ClusterIP   10.96.0.10               53/UDP,53/TCP,9153/TCP   6d13h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.100.246.255           8000/TCP                 4m32s
kubernetes-dashboard   kubernetes-dashboard        NodePort    10.110.91.255            443:30432/TCP            10s

 7、想要访问dashboard服务,就要有访问权限,创建kubernetes-dashboard管理员角色

vim dashboard-svc-account.yaml

# 结果
apiVersion: v1
kind: ServiceAccount
metadata:
  name: dashboard-admin
  namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: dashboard-admin
subjects:
  - kind: ServiceAccount
    name: dashboard-admin
    namespace: kube-system
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io


# 执行
kubectl apply -f dashboard-svc-account.yaml

8、获取 token

[root@master1 ~]# kubectl get secret -n kube-system |grep admin|awk '{print $1}'
dashboard-admin-token-bwgjv


# 复制下面的 token,后面登陆的时候要用到
[root@master1 ~]# kubectl describe secret dashboard-admin-token-bwgjv -n kube-system|grep '^token'|awk '{print $2}'
eyJhbGciOiJSUzI1NiIsImtpZCI6IkJOVUhyRElPQzJzU2t6VDNVdWpTdzhNZmZPZjV0U2s1UXBFTzctNE9uOFEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tYndnanYiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOTE5NGY5YWYtZDZlNC00ZDFmLTg4OWEtMDY4ODIyMDFlOGNmIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.kEK3XvUXJGzQlBI4LIOp-puYzBBhhXSkD20vFp9ET-rGErxmMHjUuCqWxg0iawbuOndMARrpeGJKNTlD2vL81bXMaPpKb4Y2qoB6bH5ETQPUU0HPpWYmfoHl4krEXy7S95h0mWehiHLcFkrUhyKGa39cEBq0B0HRo49tjM5QzkE6PNJ5nmEYHIJMb4U62E8wKeqY9vt60AlRa_Re7IDAO9qfb5_dGEmUaIdr3tu22sa3POBsm2bhr-R3aC8vQzNuafM35s3ed8KofOTQFk8fXu4p7lquJnji4yfC77yS3yo5Jo3VPyHi3p5np_9AuSNYfI8fo1EpSeMsXOBH45hu2w

10、访问

https://192.168.2.102:30432

 把上面的 token 粘贴到令牌

K8S 安装 Dashboard_第1张图片

K8S 安装 Dashboard_第2张图片

你可能感兴趣的:(K8S,dashboard,kubernetes,docker)