官网下载安装包
https://www.docker.com/products/docker-desktop
手动下载镜像
https://github.com/AliyunContainerService/k8s-for-docker-desktop

git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop.gitcd k8s-for-docker-desktop

[root@liwm k8s-for-docker-desktop]# cat images.propertiesk8s.gcr.io/pause:3.2=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2k8s.gcr.io/kube-controller-manager:v1.19.7=registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.19.7k8s.gcr.io/kube-scheduler:v1.19.7=registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.19.7k8s.gcr.io/kube-proxy:v1.19.7=registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.19.7k8s.gcr.io/kube-apiserver:v1.19.7=registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.19.7k8s.gcr.io/etcd:3.4.13-0=registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.13-0k8s.gcr.io/coredns:1.7.0=registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.7.0quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.26.1=registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:0.26.1[root@liwm k8s-for-docker-desktop]#
导入GitHub上的镜像
以管理员身份运行 PowerShell
Set-ExecutionPolicy RemoteSigned
.\load_images.ps1









使用wsl Linux系统命令行管理
在微软商店里下载或者购买WSL Linux

安装kubectl 管理工具
yum install -y kubectl-1.19.7-0 --disableexcludes=kubernetes



C:\Users\Eren.kube
复制kubernetes集群管理证书

[root@liwm ~]# mkdir -p $HOME/.kube[root@liwm ~]# ll /mnt/c/Users/Eren/.kube/config-rwxrwxrwx 1 root root 5560 May 23 19:48 /mnt/c/Users/Eren/.kube/config[root@liwm ~]# sudo cp -i /mnt/c/Users/Eren/.kube/config $HOME/.kube/config[root@liwm ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config[root@liwm ~]# kubectl get nodesNAME STATUS ROLES AGE VERSIONdocker-desktop Ready master 17m v1.19.7[root@liwm ~]# source <(kubectl completion bash)[root@liwm ~]#[root@liwm ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc[root@liwm ~]#[root@liwm ~]# kubectl get nodesNAME STATUS ROLES AGE VERSIONdocker-desktop Ready master 18m v1.19.7[root@liwm ~]#
[root@liwm ~]# kubectl -n kube-system get allNAME READY STATUS RESTARTS AGEpod/coredns-f9fd979d6-8d4ct 1/1 Running 0 19mpod/coredns-f9fd979d6-fcjrv 1/1 Running 0 19mpod/etcd-docker-desktop 1/1 Running 0 18mpod/kube-apiserver-docker-desktop 1/1 Running 0 18mpod/kube-controller-manager-docker-desktop 1/1 Running 0 18mpod/kube-proxy-jgq9j 1/1 Running 0 19mpod/kube-scheduler-docker-desktop 1/1 Running 0 18mpod/storage-provisioner 1/1 Running 0 18mpod/vpnkit-controller 1/1 Running 0 18mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 19mNAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGEdaemonset.apps/kube-proxy 1 1 1 1 1 kubernetes.io/os=linux 19mNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/coredns 2/2 2 2 19mNAME DESIRED CURRENT READY AGEreplicaset.apps/coredns-f9fd979d6 2 2 2 19m[root@liwm ~]#
helm 安装rancher 图形化管理


helm rancher仓库
https://artifacthub.io/packages/helm/rancher-stable/rancher
部署rancher 证书认证cattle-system cert-manager
[root@liwm home]# kubectl create namespace cattle-systemnamespace/cattle-system created[root@liwm home]# kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v1.0.4/cert-manager.crds.yamlcustomresourcedefinition.apiextensions.k8s.io/certificaterequests.cert-manager.io createdcustomresourcedefinition.apiextensions.k8s.io/certificates.cert-manager.io createdcustomresourcedefinition.apiextensions.k8s.io/challenges.acme.cert-manager.io createdcustomresourcedefinition.apiextensions.k8s.io/clusterissuers.cert-manager.io createdcustomresourcedefinition.apiextensions.k8s.io/issuers.cert-manager.io createdcustomresourcedefinition.apiextensions.k8s.io/orders.acme.cert-manager.io created[root@liwm home]# kubectl get pods --namespace cert-managerNo resources found in cert-manager namespace.[root@liwm home]# kubectl create namespace cert-managernamespace/cert-manager created[root@liwm home]# helm repo add jetstack https://charts.jetstack.ioWARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/configWARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config"jetstack" has been added to your repositories[root@liwm home]# helm install \> cert-manager jetstack/cert-manager \> --namespace cert-manager \> --version v1.0.4WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/configWARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/configNAME: cert-managerLAST DEPLOYED: Sun May 23 20:42:39 2021NAMESPACE: cert-managerSTATUS: deployedREVISION: 1TEST SUITE: NoneNOTES:cert-manager has been deployed successfully!In order to begin issuing certificates, you will need to set up a ClusterIssueror Issuer resource (for example, by creating a 'letsencrypt-staging' issuer).More information on the different types of issuers and how to configure themcan be found in our documentation:https://cert-manager.io/docs/configuration/For information on how to configure cert-manager to automatically provisionCertificates for Ingress resources, take a look at the `ingress-shim`documentation:https://cert-manager.io/docs/usage/ingress/[root@liwm home]# kubectl get pods --namespace cert-managerNAME READY STATUS RESTARTS AGEcert-manager-6d87886d5c-s6zq4 0/1 ContainerCreating 0 9scert-manager-cainjector-55db655cd8-h6qmt 0/1 ContainerCreating 0 9scert-manager-webhook-6846f844ff-lwwnr 0/1 ContainerCreating 0 9s[root@liwm home]#
使用 helm部署rancher
cert-manager-webhook-6846f844ff-lwwnr 1/1 Running 0 56s[root@liwm home]# helm install rancher rancher-latest/rancher \> --namespace cattle-system \> --set hostname=rancher.my.orgWARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/configWARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/configNAME: rancherLAST DEPLOYED: Sun May 23 20:45:33 2021NAMESPACE: cattle-systemSTATUS: deployedREVISION: 1TEST SUITE: NoneNOTES:Rancher Server has been installed.NOTE: Rancher may take several minutes to fully initialize. Please standby while Certificates are being issued and Ingress comes up.Check out our docs at https://rancher.com/docs/rancher/v2.x/en/Browse to https://rancher.my.orgHappy Containering![root@liwm home]#
查看helm安装状态
[root@liwm Eren]# helm ls --all-namespacesWARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/configWARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/configNAME NAMESPACE REVISION UPDATED STATUS CHARTAPP VERSIONcert-manager cert-manager 1 2021-05-23 20:42:39.3257997 +0800 CST deployed cert-manager-v1.0.4 v1.0.4fleet fleet-system 2 2021-05-23 12:48:46.4524648 +0000 UTC deployed fleet-0.3.5000.3.5rancher cattle-system 1 2021-05-23 20:45:33.0318282 +0800 CST deployed rancher-2.5.8v2.5.8rancher-operator rancher-operator-system 1 2021-05-23 12:47:30.1734295 +0000 UTC deployed rancher-operator-0.1.400 0.1.4rancher-webhook cattle-system 1 2021-05-23 12:47:46.7790814 +0000 UTC deployed rancher-webhook-0.1.000 0.1.0[root@liwm Eren]# kubectl -n cattle-system rollout status deploy/rancherdeployment "rancher" successfully rolled out[root@liwm Eren]# kubectl -n cattle-system get deploy rancherNAME READY UP-TO-DATE AVAILABLE AGErancher 3/3 3 3 139m[root@liwm Eren]#
[root@liwm ~]# kubectl -n cattle-system get podNAME READY STATUS RESTARTS AGEhelm-operation-4j29b 1/2 Error 0 27mhelm-operation-9rsb4 1/2 Error 0 27mhelm-operation-dl24c 0/2 Completed 0 40mhelm-operation-ffxjv 1/2 Error 0 12mhelm-operation-nbnqm 1/2 Error 0 12mhelm-operation-rm68h 0/2 Completed 0 40mhelm-operation-sfqqs 1/2 Error 0 40mhelm-operation-wwp76 0/2 Completed 0 41mhelm-operation-wxrsr 1/2 Error 0 40mhelm-operation-xkpnz 0/2 Completed 0 41mrancher-7cbb45db4-57nmm 1/1 Running 0 43mrancher-7cbb45db4-dsd8g 1/1 Running 0 43mrancher-7cbb45db4-xgp4d 1/1 Running 0 43mrancher-webhook-65f558c486-fxbxj 1/1 Running 0 41m[root@liwm ~]# kubectl -n cattle-system get serviceNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGErancher ClusterIP 10.101.123.206 <none> 80/TCP,443/TCP 43mrancher-webhook ClusterIP 10.102.182.200 <none> 443/TCP 41m[root@liwm ~]# kubectl -n cattle-system get ingressWarning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 IngressNAME CLASS HOSTS ADDRESS PORTS AGErancher <none> rancher.my.org 80, 443 43m[root@liwm ~]#
添加本地域名解析
127.0.0.1 rancher.my.org

修改 server的ClusterIP类型为:NodePort
[root@liwm Eren]# kubectl -n cattle-system get serviceNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGErancher NodePort 10.101.123.206 <none> 80:30053/TCP,443:30155/TCP 150mrancher-webhook ClusterIP 10.102.182.200 <none> 443/TCP 148m[root@liwm Eren]#
本地浏览器访问
rancher-server管理



参考文档
https://docs.docker.com/docker-for-windows/wsl
https://blog.csdn.net/simongame/article/details/106727108

