1. Install the Docker-Desktop and check the installation method
2. Download and rename the file k3D. exe. You can set the file to win environment variables
https://github.com/rancher/k3d/releases/tag/v5.0.1-rc.1
3. Start k3d.exe in the CMD window
4. Create a K8S cluster
k3d cluster create k8s-cluster --port 8080:80@loadbalancer --port 8443:443@loadbalancer --api-port 6443 --servers 1 --agents 2
INFO[0000] Prep: Network
INFO[0000] Created network 'k3d-k8s-cluster'
INFO[0000] Created volume 'k3d-k8s-cluster-images'
INFO[0001] Creating node 'k3d-k8s-cluster-server-0'
INFO[0001] Creating node 'k3d-k8s-cluster-agent-0'
INFO[0001] Creating node 'k3d-k8s-cluster-agent-1'
INFO[0001] Creating LoadBalancer 'k3d-k8s-cluster-serverlb'
INFO[0001] Starting cluster 'k8s-cluster'
INFO[0001] Starting servers...
INFO[0001] Starting Node 'k3d-k8s-cluster-server-0'
INFO[0008] Starting agents...
INFO[0008] Starting Node 'k3d-k8s-cluster-agent-0'
INFO[0020] Starting Node 'k3d-k8s-cluster-agent-1'
INFO[0028] Starting helpers...
INFO[0028] Starting Node 'k3d-k8s-cluster-serverlb'
INFO[0029] (Optional) Trying to get IP of the docker host and inject it into the cluster as 'host.k3d.internal' for easy access
INFO[0031] Successfully added host record to /etc/hosts in 4/4 nodes and to the CoreDNS ConfigMap
INFO[0031] Cluster 'k8s-cluster' created successfully!
INFO[0031] --kubeconfig-update-default=false --> sets --kubeconfig-switch-context=false
INFO[0031] You can now use it like this:
kubectl config use-context k3d-k8s-cluster
kubectl cluster-info
Copy the code
>kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3d-k8s-cluster-agent-1 Ready <none> 8m49s v121.. 5+k3s2
k3d-k8s-cluster-agent-0 Ready <none> 8m49s v121.. 5+k3s2
k3d-k8s-cluster-server-0 Ready control-plane,master 8m59s v121.. 5+k3s2
Copy the code
5. Install the K8S cluster console
Kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created
Copy the code
6. Create a console login user
kubectl create -f dashboard-admin-user.yml
kubectl create -f dashboard-admin-user-role.yml
7. Check the token
kubectl -n kubernetes-dashboard describe secret admin-user-token
8. Use proxy to start the K8S console
kubectl proxy
Starting to serve on 127.0. 01.:8001
Copy the code
9. Log in to the console and copy the obtained token
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
10. K3d command
- Stopping a cluster:
k3d cluster stop k8s-cluster
- Restarting the cluster:
k3d cluster start k8s-cluster
- Deleting a cluster:
k3d cluster delete k8s-cluster