K8s Dashboard UI

有 K8s Dashboard UI,可以方便在页面上管理 K8S。

1. Deploying the Dashboard UI

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.1.0/aio/deploy/recommended.yaml
1

如果执行报错,请先将该文件下载到本地,然后再 kubectl apply Unable to connect to the server: tls: first record does not look like a TLS handshake

2. Creating sample user

接着创建访问 K8S Dashboard UI 的账号

2.1 Creating a Service Account

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
EOF
1
2
3
4
5
6
7

2.2 Creating a ClusterRoleBinding

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14

2.3 获取访问Token

kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
1

3. Bind Port and Accessing the Dashboard UI

Bind Port

kubectl proxy
1

使用 上一步创建的 token,访问 K8S Dashboard UI

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/.
1

附录: K8S Dashboard 截图

  • 首页

-w1915

  • Deployments

-w1919

  • Services

-w1919

  • Pods

-w1919

  • 新建 Deployment + Services

-w1918

reference