├── .github └── workflows │ └── push.yml ├── .gitignore ├── LICENSE ├── README.md ├── image └── k8s.png ├── images ├── load_images.bat └── load_images.sh /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: k8s image sync 2 | on: push 3 | jobs: 4 | k8s-image-sync: 5 | name: k8s image sync 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: sync 9 | uses: maguowei/actions/k8s-image-sync@master 10 | with: 11 | username: ${{ secrets.DOCKER_USERNAME }} 12 | password: ${{ secrets.DOCKER_PASSWORD }} 13 | repository: gotok8s 14 | kubernetes_version: v1.25.2 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vscode/ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 gotok8s 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `Docker Desktop for Mac` 开启并使用 `Kubernetes` 2 | 3 | [![github workflow](https://github.com/maguowei/k8s-docker-desktop-for-mac/workflows/k8s%20image%20sync/badge.svg)](https://github.com/maguowei/k8s-docker-desktop-for-mac/actions) 4 | 5 | `Docker Desktop` 可以方便的启用 `Kubernetes` 集群, 为学习 `Kubernetes` 提供了极大的便利, 但是由于众所周知的原因, 国内的网络下不能很方便的下载 `Kubernetes` 集群所需要的镜像, 导致集群启用失败. 这里提供了一个简单的方法, 利用 [GitHub Actions](https://developer.github.com/actions/creating-github-actions/) 实现 `k8s.gcr.io` 上 `kubernetes` 依赖镜像自动同步到 [Docker Hub](https://hub.docker.com/) 上指定的仓库中。 通过 [load_images.sh](./load_images.sh) 将所需镜像从 `Docker Hub` 的同步仓库中取回,并重新打上原始的`tag`. 镜像对应关系文件可以查看: [images](./images). 6 | 7 | 说明: 8 | 9 | - 当前在 `Docker Desktop (Mac) Version 4.14.1 (Kubernetes: v1.25.2)`上经过测试可用 10 | - 使用 `Kubeadm` 在`Ubuntu`上安装 `Kubernetes` 请查看 [gotok8s](https://github.com/maguowei/gotok8s) 11 | 12 | ## 安装并启动 13 | 14 | 1. 下载安装 [Docker Desktop (Mac)](https://desktop.docker.com/mac/stable/Docker.dmg) 15 | 16 | 2. 从 `Docker Hub` 的同步仓库中取回,并重新打上原始的`tag`. 17 | 18 | ```bash 19 | ./load_images.sh 20 | ``` 21 | 22 | 3. 在`Docker for Mac` 设置中启用 `Kubernetes` 选项, 并等待一会儿,直到 `Kubernetes` 开始运行。 23 | 24 | ![k8s](./image/k8s.png) 25 | 26 | 4. 可选的步骤: 切换`Kubernetes`运行上下文至 `docker-desktop` 27 | 28 | ```bash 29 | # 一般只有在之前用其他方式运行过Kubernetes才需要 30 | $ kubectl config use-context docker-desktop 31 | ``` 32 | 33 | 5. 验证 `Kubernetes` 集群状态 34 | 35 | ```bash 36 | $ kubectl cluster-info 37 | $ kubectl get nodes 38 | $ kubectl describe node 39 | ``` 40 | 41 | ## 参考 42 | 43 | - [部署 Kubernetes Dashboard](https://github.com/maguowei/k8s-cookbook#%E9%83%A8%E7%BD%B2-kubernetes-dashboard) 44 | - [Helm 的使用](https://github.com/maguowei/k8s-cookbook#helm) 45 | -------------------------------------------------------------------------------- /image/k8s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maguowei/k8s-docker-desktop-for-mac/0fa210a6851b327ae5c66ce8567bfa0375ca936b/image/k8s.png -------------------------------------------------------------------------------- /images: -------------------------------------------------------------------------------- 1 | k8s.gcr.io/kube-proxy:v1.25.2=gotok8s/kube-proxy:v1.25.2 2 | k8s.gcr.io/kube-controller-manager:v1.25.2=gotok8s/kube-controller-manager:v1.25.2 3 | k8s.gcr.io/kube-scheduler:v1.25.2=gotok8s/kube-scheduler:v1.25.2 4 | k8s.gcr.io/kube-apiserver:v1.25.2=gotok8s/kube-apiserver:v1.25.2 5 | k8s.gcr.io/coredns:v1.9.3=gotok8s/coredns:v1.9.3 6 | k8s.gcr.io/pause:3.8=gotok8s/pause:3.8 7 | k8s.gcr.io/etcd:3.5.4-0=gotok8s/etcd:3.5.4-0 -------------------------------------------------------------------------------- /load_images.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set file=images 3 | if exist %file% ( 4 | echo %file% found. 5 | for /f "tokens=1,2 delims==" %%i in (%file%) do ( 6 | echo pulling %%j ... 7 | docker pull %%j 8 | docker tag %%j %%i 9 | docker rmi %%j 10 | ) 11 | ) else ( 12 | echo %file% not found. 13 | ) 14 | pause 15 | -------------------------------------------------------------------------------- /load_images.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | file="images" 4 | 5 | if [ -f "$file" ] 6 | then 7 | echo "$file found." 8 | 9 | while IFS='=' read -r key value 10 | do 11 | #echo "${key}=${value}" 12 | docker pull ${value} 13 | docker tag ${value} ${key} 14 | docker rmi ${value} 15 | done < "$file" 16 | 17 | else 18 | echo "$file not found." 19 | fi 20 | --------------------------------------------------------------------------------