wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc5/aio/deploy/recommended.yaml
 
# 创建 pod
kubectl apply -f recommended.yaml
#当镜像 ImagePullBackOff拉取不下来的时候  可配置本地镜像仓库  
vim /etc/docker/daemon.json
"insecure-registries":["192.168.10.130"]
  • 3、查看,成功创建
[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
  • 4、删除现有的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        <none>        443/TCP                  6d13h
default                nginx                       NodePort    10.02.20.172   <none>        80:31863/TCP             8h
kube-system            kube-dns                    ClusterIP   10.9.0.10       <none>        53/UDP,53/TCP,9153/TCP   6d13h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.10.26.255   <none>        8000/TCP                 61s
kubernetes-dashboard   kubernetes-dashboard        ClusterIP   10.109.20.35    <none>        443/TCP                  61s

# 删除
kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard
  • 5、创建svc配置文件并执行
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
  • 6、再次查看服务,成功
[root@master1 ~]# kubectl get svc --all-namespaces
NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP   10.96.0.1        <none>        443/TCP                  6d13h
default                nginx                       NodePort    10.102.20.172   <none>        80:31863/TCP             8h
kube-system            kube-dns                    ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   6d13h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.100.246.25   <none>        8000/TCP                 4m32s
kubernetes-dashboard   kubernetes-dashboard        NodePort    10.110.91.25    <none>        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-l6xh8 -n kube-system|grep '^token'|awk '{print $2}'
IkJOVUhyRElPQzJzU2t6VDNVdWpTdzhNZmZPZjV0U2s1UXBFTzctNE9uOFEifQ.dGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9L3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOTE5NGY5YWYtZDZlNC00ZDFmLTg4OWEtMDY4ODIyMDFlOGNmIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.kEK3XvUXJGzQlBI4LIOp-puYzBBhhXSkD20vFp9ET-rGErxmMHjUuCqWxg0iawbuOndMARrEXy7S95h0mWehiHLcFkrUhyKGa39cEBq0B0HRo49tjM5QzkE6PNJ5nmEYHIJMb4U62E8wKeqY9vt60AlRa_Re7IDAO9qfb5_dGEmUaIdr3tu22sa3POBsm2bhr-R3aC8vQzNuafM35s3ed8KofOTQFk8fXu4p7lquJnji4yfC77yS3yo5Jo3VPyHi3p5np_9A
  • 9、访问
https://SERVER_IP:10010
  • 10、复制9中查询出来的token,然后粘贴至图中位置
    在这里插入图片描述
    在这里插入图片描述
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐