阿东的笔记_  工具
## wsl2环境 使用kind,kubectl创建kubernetes集群 #### 安装 kubectl 参考:[https://kubernetes.io/zh-cn/docs/tasks/tools/install-kubectl-linux/](https://kubernetes.io/zh-cn/docs/tasks/tools/install-kubectl-linux/) ``` Bash # 下载 curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" # 安装 chmod +x kubectl mkdir -p ~/.local/bin mv ./kubectl ~/.local/bin/kubectl ``` #### 安装kind ``` Bash $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64 chmod +x ./kind mv ./kind /usr/local/bin/ sudo mv ./kind /usr/local/bin/ ``` #### 创建集群 - 创建 service-account-secret.yaml ``` yaml apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard --- # 授权 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 --- # 对名为admin-user的服务账户手动创建Secret apiVersion: v1 kind: Secret metadata: name: admin-user-secret namespace: kubernetes-dashboard annotations: kubernetes.io/service-account.name: admin-user type: kubernetes.io/service-account-token ``` - Shell ``` Bash ## 创建 cluster kind create cluster --name testk8s ## 下载 curl -O https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml kubectl apply -f recommended.yaml kubectl apply -f service-account-secret.yaml ## 开启代理 kubectl proxy ## 创建登录token kubectl -n kubernetes-dashboard create token admin-user ``` 使用token 打开浏览器 登录地址 http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login - [![demo](https://static.adong.wiki/static/images/md/20241019185116.png)](https://static.adong.wiki/static/images/md/20241019185116.png)
adddge@sohu.com  | 桂ICP备2022009838号-2