我们需要k8s环境做各种小实验可以本地安装一个,这里介绍win11如何通过docker-desktop安装k8s以及通过helm安装dashboard。
- 下载docker-desktop地址https://www.docker.com/get-started/
 - 打开【控制面板】->打开【启用和关闭windows功能】->分别勾选【hyper-v】【window虚拟机监控程序平台】【容器】【适用于Linux的windows子系统】【虚拟机平台】等 备注:windows专业版以上才行,可能有些选项不需要这里勾选上没影响
 - 安装好Docker Desktop 4.38.0 后在【setting】的【Docker Engine】中配置源
 
            
            
              java
              
              
            
          
          {
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://reg-mirror.qiniu.com",
    "https://docker.m.daocloud.io",
    "https://huecker.io",
    "https://dockerhub.timeweb.cloud",
    "https://noohub.ru"
  ]
}
        - 
在【setting】中点击【Kubernetes】开启【
Enable Kubernetes】

这里时间会比较长。
 - 
window安装helm,通过winget安装helm比较方便,打开cmd执行winget install Helm.Helm 命令,winget可能需要安装自行百度。
 - 
下载k8s对应的dashboard包github上面有地址https://github.com/kubernetes/dashboard/releases 这里我下载的是kubernetes-dashboard-7.10.0.tgz 这个版本。
 - 
执行helm命令
 
            
            
              shell
              
              
            
          
          helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
helm upgrade --install kubernetes-dashboard D:\software\kubernetes-dashboard-7.10.0.tgz --create-namespace --namespace kubernetes-dashboard
        8.新建k8s账号
新建文件dashboard-service-account.yaml
            
            
              yaml
              
              
            
          
          apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
        执行命令kubectl apply -f .\dashboard-service-account.yaml
9.k8s账号授权
新建文件 dashboard-cluster-role-binding.yaml
            
            
              yaml
              
              
            
          
          apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: admin-user
    namespace: kubernetes-dashboard
  
        执行kubectl apply -f .\dashboard-cluster-role-binding.yaml
10.创建访问k8s-dashboard的token
kubectl -n kubernetes-dashboard create token admin-user --duration=24h
11.执行kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443 --address localhost
