【WIP】Mac下搭建本地k8s,并进行开发、调试和部署
安装Docker/k8s
安装 Docker for Mac,Version>=18.06,低版本可能不自带Kubernetes
设置
Docker
中国官方镜像加速 registry mirrorhttps://registry.docker-cn.com
- 预先从阿里云
Docker
镜像下载Kubernetes
所需要的镜像, 可以通过修改 ./images 文件定制你自己需要的镜像
$ ./load_images.sh
- 在
Docker for Mac
设置中启用Kubernetes
选项, 并等待一会儿,直到Kubernetes
开始运行。
- 可选的步骤: 切换
Kubernetes
运行上下文至docker-for-desktop
# 一般只有在之前用其他方式运行过Kubernetes才需要
$ kubectl config use-context docker-for-desktop
- 验证
Kubernetes
集群状态
$ kubectl cluster-info
$ kubectl get nodes
- 部署
Kubernetes dashboard
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
# 开启本机访问代理
$ kubectl proxy
通过下面的连接访问 Dashboard
:
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
获取 Dashboard
admin
权限:
https://github.com/kubernetes/dashboard/wiki/Access-control#admin-privileges
服务初次部署
-
添加证书,重启docker
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./harbor.crt
-
docker login harbor.test.gengmei
docker login harbor.test.gengmei username: gmuser password: Gengmei123!
-
创建项目目录,日志目录到指定位置
sudo mkdir -p /data/log/backend/app /data/log/gaia/app /data/log/mimas/app /data/log/doris/app # ... sudo mkdir -p /srv/apps cd /srv/apps git clone git@git.wanmeizhensuo.com:backend/backend.git git clone git@git.wanmeizhensuo.com:backend/gaia.git git clone git@git.wanmeizhensuo.com:backend/Mimas.git git clone git@git.wanmeizhensuo.com:rank/doris.git
-
每个项目checkout到paas分支,build镜像
cd 项目目录 git checkout paas docker build --no-cache -t 项目名:local.latest .
-
复制 settings_local 到项目目录下
cp ./settings_local/backend/settings_local.py /srv/apps/backend/gengmei cp ./settings_local/gaia/settings_local.py /srv/apps/gaia/gaia cp ./settings_local/mimas/settings_local.py /srv/apps/mimas/settings/settings_local.py cp ./settings_local/mimas/deploy_prod.xml /srv/apps/mimas/ cp ./settings_local/doris/devel.py /srv/apps/doris/doris/devel.py cp ./settings_local/doris/deploy_prod.xml /srv/apps/doris/deploy_prod.xml
docker-for-mac上添加File Sharing配置 /srv/apps、/data/log,添加后点击Apply & Restart,若报错如下,可不必添加。
-
备份之前的路由表,用当前目录下的路由表替换之前的路由表
mv /etc/gm-config/storage/static.dir/helios.dir/static_route_table.json /etc/gm-config/storage/static.dir/helios.dir/static_route_table.json.old cp ./static_route_table.json /etc/gm-config/storage/static.dir/helios.dir/static_route_table.json
-
设置configmap
kubectl create configmap static-route-table --from-file=/etc/gm-config/storage/static.dir/helios.dir/static_route_table.json kubectl create configmap backend-settings --from-file=/srv/apps/backend/gengmei/settings_local.py kubectl create configmap gaia-settings --from-file=/srv/apps/gaia/gaia/settings_local.py kubectl create configmap mimas-settings --from-file=/srv/apps/mimas/settings/settings_local.py kubectl create configmap doris-settings --from-file=/srv/apps/doris/doris/devel.py
-
部署Pod和Service
# Pod kubectl create -f deploy/backend-deploy.yml kubectl create -f deploy/gaia-deploy.yml kubectl create -f deploy/mimas-deploy.yml kubectl create -f deploy/doris-deploy.yml # Service kubectl create -f service/backend-service.yml kubectl create -f service/gaia-service.yml kubectl create -f service/mimas-service.yml kubectl create -f service/doris-service.yml
-
测试服务是否正常
kubectl get service -o wide
服务调试
本地开发,对/srv/apps的服务进行开发
(如果涉及依赖的更新,先切到项目目录,执行
docker build --no-cache -t 项目名:local.latest .
)-
更新服务
kubectl replace --force -f deploy/backend-service.yml # 更改了哪个服务,更新时就用deploy目录下的对应文件更新
测试