前言

Dashboard 是基于网页的 Kubernetes 用户界面。 你可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群资源。 你可以使用 Dashboard 获取运行在集群中的应用的概览信息,也可以创建或者修改 Kubernetes 资源 (如 Deployment,Job,DaemonSet 等等)。 例如,你可以对 Deployment 实现弹性伸缩、发起滚动升级、重启 Pod 或者使用向导创建新的应用

官方文档

YAML文件下载

# 官方安装文件
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
# 下载到指定目录
curl https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml -o /home/lixing/kubernetes-dashboard.yaml

注意:如果在线下载慢,可以在本地下载上传到服务器

YAML文件安装

配置 Service暴露服务类型 为 NodePort(追加)

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  type: NodePort # Service暴露服务的类型
  ports:
    - port: 443 # Service端口
      targetPort: 8443 # Pod端口
      nodePort: 30000 # Node节点端口
  selector:
    k8s-app: kubernetes-dashboard

Creating Service Account(追加)

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard

Creating ClusterRoleBinding(追加)

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

安装

kubectl apply -f kubernetes-dashboard.yaml
kubectl delete -f kubernetes-dashboard.yaml

查询 kubernetes-dashboard 空间下的资源

kubectl get deployment,replicaSet,pod,service -n kubernetes-dashboard -o wide --show-labels

在这里插入图片描述

浏览器访问 Dashboard

为了保护你的集群数据,默认情况下,Dashboard 会使用最少的 RBAC 配置进行部署。 当前,Dashboard 仅支持使用 Bearer 令牌登录

获取 Bearer Token

# kubectl -n kubernetes-dashboard create token <Service Account Name>
kubectl -n kubernetes-dashboard create token admin-user
eyJhbGciOiJSUzI1NiIsImtpZCI6Ik1PSHYtX1NVa1pvXzlvY2Z4UFlTd1ZsNmhBZmZzaHZNWjBlYWJrclJXSVEifQ.eyJhdWQiOlsiYXBpIl0sImV4cCI6MTY4MjE1NTYyMSwiaWF0IjoxNjgyMTUyMDIxLCJpc3MiOiJhcGkiLCJrdWJlcm5ldGVzLmlvIjp7Im5hbWVzcGFjZSI6Imt1YmVybmV0ZXMtZGFzaGJvYXJkIiwic2VydmljZWFjY291bnQiOnsibmFtZSI6ImFkbWluLXVzZXIiLCJ1aWQiOiJiNGMwMzM3Ni05NmExLTQyMzAtYjQ0ZS1lMjNlNzVkNDVkZmQifX0sIm5iZiI6MTY4MjE1MjAyMSwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmVybmV0ZXMtZGFzaGJvYXJkOmFkbWluLXVzZXIifQ.nMk9s80xj4SjRC9AbxeeEyktlketw6oCV7SsQDqBzAZX5EVtxPXHPRmLok6RorjF8McORbpH9EBWHWdwUh41yy_ODx2hiO4A5SMsSu5oMGGTSYAVd2deAUhvOIloIBThdk7xODV04cpy1gh3_BQnpC5ys6gMO1b5nbyBETKrIkrvheRoJtm8cv560KZrGJyt-FumMjSlZej6ynnFGCprnmcs2QBeOZuzxRhNgPavCdeHuyItug1lLM0UAuegAy5jpkYq3bAgUJmnNlfu2xaDiPCR6LhnXYup2X6CsKjcrbCieQ5Obrz1jkPPcyw_6rwXUZeB_C7FIzpuyREUxLEDxA

Remove admin ServiceAccount and ClusterRoleBinding

# kubectl -n kubernetes-dashboard delete serviceaccount <Service Account Name> # 删除
kubectl -n kubernetes-dashboard delete serviceaccount admin-user
# kubectl -n kubernetes-dashboard delete clusterrolebinding <Service Account Name> # 删除
kubectl -n kubernetes-dashboard delete clusterrolebinding admin-user

登陆

https://192.168.111.40:30000

在这里插入图片描述

操作手册(未完待续)

Logo

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

更多推荐