【k8s-1】基于docker Desktop一键式搭建k8s环境

【k8s-1】基于docker Desktop一键式搭建k8s环境_第1张图片

在docker desktop中一键启动k8s环境很简单。

下面介绍如何启动dashboard,dashboard仪表盘是新手学习k8s至关重要的一个工具。

1、配置控制台

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

2、开启 API Server 访问代理

kubectl proxy

3、通过如下 URL 访问 Kubernetes dashboard

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

4、授权kube-system默认服务账号

kubectl apply -f kube-system-default.yaml

kube-system-default.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kube-system-default
  labels:
    k8s-app: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: default
    namespace: kube-system

---

apiVersion: v1
kind: Secret
metadata:
  name: default
  namespace: kube-system
  labels:
    k8s-app: kube-system
  annotations:
    kubernetes.io/service-account.name: default
type: kubernetes.io/service-account-token

5、获取token

TOKEN=$(kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}')
kubectl config set-credentials docker-desktop --token="${TOKEN}"
echo $TOKEN

6、登录dashboard

【k8s-1】基于docker Desktop一键式搭建k8s环境_第2张图片

你可能感兴趣的:(k8s,kubernetes,docker,java)