- 安装参考:
- 安装docker+k8s
- 安装k8s-dashboard
- dashborad forbidden 问题
- 解决
- kubernetes-dashboard管理员角色">创建创建kubernetes-dashboard管理员角色
- 获取dashboard管理员角色token
- 解决
安装参考:
https://github.com/AliyunContainerService/k8s-for-docker-desktop
安装docker+k8s
mac 直接下载 docker-desktop,就包含k8s
docker-desktop更新版本后k8s启动失败
原因是k8s版本从v1.22.4 —> v1.22.5, 但是原来下载的k8s镜像还是1.22.4版本
github仓库还未更新,所以本地手动修改版本,
重新./load_images.sh 下载新版本镜像,重新启动
安装k8s-dashboard
https://yeasy.gitbook.io/docker_practice/setup/dashboard
If you use K8S dashboard v2.0.0-betax,
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
Then use this to access the dashboard:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
If you use K8S dashboard v1.10.1,
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
Then use this to access the dashboard:
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
I also faced the same problem, but then i realized that dashboard v2.0.0-betax and v1.10.1 use different namespace. Latest version use kubernetes-dashboard namespace, but the older one use kube-system namespace
遇到问题
Kubenetes 部署 Dashboard | HelloWood
原来是拉取镜像失败
Failed to pull image “k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1”
命令行代理
你可以使用 kubectl 命令行工具访问 Dashboard,命令如下:
kubectl proxy
kubectl 会使得 Dashboard 可以通过
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ (这个地址具体的看上面那个版本)
访问。
UI 只能 通过执行这条命令的机器进行访问。更多选项参见 kubectl proxy —help。
生成token
TOKEN=$(kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}')
kubectl config set-credentials docker-desktop --token="${TOKEN}"
echo $TOKEN
Docker Desktop for Mac用户手册 | Docker文档
dashborad forbidden 问题
某次重新安装k8s+dashboard后,
打开dashboard网址,可以打开dashboard 控制台,进入后,提示被拒绝等消息
namespaces is forbidden: User “system:serviceaccount:kube-system:default” cannot list resource “namespaces” in API group “” at the cluster scope
解决
参考:https://jimmysong.io/kubernetes-handbook/practice/dashboard-addon-installation.html
创建创建kubernetes-dashboard管理员角色
vim k8s-admin.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard-admin
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1 (网上大部分还是写的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 create -f k8s-admin.yaml
获取dashboard管理员角色token
kubectl describe secret dashboard-admin -n kube-system
使用该token 登录后正常