Preparation before installation

Make sure Docker Desktop is installed and started locally

Pull the k8s image (if the local network is good, the official k8s image can be pulled normally, you can skip this step)

Clone git repository to local

 git clone https://github.com/gotok8s/k8s-docker-desktop-for-mac.git

Enter the project directory and execute

 ./load_images.sh

Wait for all image pulls to complete
image.png

deploy k8s

Enter the settings page of --- Docker Decktop Kubernetes configuration page, click the Apply & Restart button in the lower right corner, and wait for k8s to complete the deployment
image.png

After completion, you can verify the deployment status

 kubectl cluster-info

kubectl get nodes

kubectl describe node

image.png

Install k8s Dashboard

The recommended configuration of the application needs to be modified here v2.6.0 is compatible with the version of kubelet installed above. For details, please refer to https://github.com/kubernetes/dashboard/releases

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

image.png

Create user and get token

Create admin-user

Copy the following configuration and save the file as dashboard-adminuser.yaml

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

then execute

 kubectl apply -f dashboard-adminuser.yaml

Bind cluster-admin authorization

Copy the following configuration and save the file as dashboard-clusteradmin.yaml

 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

then execute

 kubectl apply -f dashboard-clusteradmin.yaml

Get login token

Enable proxy and set proxy port to 8001

 kubectl proxy --port=8001

Open a new command window and execute

Check if user information exists

 curl 'http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/serviceaccounts/admin-user'

Get token without parameters

 curl 'http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/serviceaccounts/admin-user/token' -H "Content-Type:application/json" -X POST -d '{}'

Get token with parameters

 curl 'http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/serviceaccounts/admin-user/token' -H "Content-Type:application/json" -X POST -d '{"kind":"TokenRequest","apiVersion":"authentication.k8s.io/v1","metadata":{"name":"admin-user","namespace":"kubernetes-dashboard"},"spec":{"audiences":["https://kubernetes.default.svc.cluster.local"],"expirationSeconds":7600}}'

image.png

Login to k8s Dashboard

Copy the token information returned in the previous step, visit the following address in the browser, fill in the token to log in

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

image.png


MartinDai
1.5k 声望236 粉丝

保持学习心态,持续成长