kubernetes-dashboard 部署
时间: 2023-08-29 17:08:56 浏览: 172
Kubernetes Dashboard 是 Kubernetes 官方提供的一个 Web 界面,用于管理 Kubernetes 集群。以下是部署 Kubernetes Dashboard 的步骤:
1. 下载 Kubernetes Dashboard YAML 文件:
```bash
curl -LO https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
```
2. 修改 Kubernetes Dashboard Service 类型:
将 recommended.yaml 文件中的 Service 类型从 ClusterIP 修改为 NodePort,这样可以通过 Node 的 IP 地址加端口号访问 Kubernetes Dashboard。
```yaml
apiVersion: v1
kind: Service
metadata:
name: kubernetes-dashboard
namespace: kubernetes-dashboard
labels:
k8s-app: kubernetes-dashboard
spec:
type: NodePort # 将类型修改为 NodePort
ports:
- port: 443
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
```
3. 部署 Kubernetes Dashboard:
```bash
kubectl apply -f recommended.yaml
```
4. 创建 Service Account:
```bash
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
EOF
```
5. 创建 Cluster Role Binding:
```bash
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
EOF
```
6. 获取 Token:
```bash
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
```
7. 访问 Kubernetes Dashboard:
使用浏览器访问 Node 的 IP 地址加端口号,输入 Token 登录即可。
阅读全文