k8s的Dashboard

 前面章节 Kubernetes 所有的操作我们都是通过命令行工具 kubectl 完成的。为了提供更丰富的用户体验,Kubernetes 还开发了一个基于 Web 的 Dashboard,用户可以用 Kubernetes Dashboard 部署容器化的应用、监控应用的状态、执行故障排查任务以及管理 Kubernetes 各种资源。

在 Kubernetes Dashboard 中可以查看集群中应用的运行状态,也能够创建和修改各种 Kubernetes 资源,比如 Deployment、Job、DaemonSet 等。用户可以 Scale Up/Down Deployment、执行 Rolling Update、重启某个 Pod 或者通过向导部署新的应用。Dashboard 能显示集群中各种资源的状态以及日志信息。

可以说,Kubernetes Dashboard 提供了 kubectl 的绝大部分功能,大家可以根据情况进行选择。

1.Dashboard安装

Kubernetes 默认没有部署 Dashboard,可通过如下命令安装:

kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

Dashboard 会在 kube-system namespace 中创建自己的 Deployment 和 Service。

执行了配置半天pod起不来

查看日志

[root@k8s-master k8s]# kubectl describe pods --namespace=kube-system kubernetes-dashboard-77fd78f978-v6zcx 

不能科学上网导致镜像pull失败,那就在能下载镜像的地方下载然后将镜像改成需要的名字(所有节点都要执行)

[root@k8s-master k8s]# docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0
v1.10.0: Pulling from mirrorgooglecontainers/kubernetes-dashboard-amd64
d66237a56abc: Pull complete 
Digest: sha256:e4b764fa9df0a30c467e7cec000920ea69dcc2ba8a9d0469ffbf1881a9614270
Status: Downloaded newer image for mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0
[root@k8s-master k8s]# docker images|grep kubernetes-dashboard
mirrorgooglecontainers/kubernetes-dashboard-amd64   v1.10.0             0dab2435c100        2 months ago        122MB
[root@k8s-master k8s]# docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0
[root@k8s-master k8s]# docker rmi  mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0 

 指定删除重新apply一下配置

kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

 

 Dashboard 会在 kube-system namespace 中创建自己的 Deployment 和 Service。

因为 Service 是 ClusterIP 类型,为了方便使用,我们可通过 kubectl --namespace=kube-system edit service kubernetes-dashboard 修改成 NodePort 类型。

 保存修改,此时已经为 Service 分配了端口 31551。

创建rdbc授权文件kubernetes-dashboard-rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system
 
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system
kubectl apply -f kubernetes-dashboard-rbac.yaml
#查看admin-user用户token
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
 
#复制token,在浏览器上选择令牌方式
使用火狐浏览器,https://ip:port

 

原文地址:https://www.cnblogs.com/benjamin77/p/9978287.html