Name
Last commit
Last update
deploy init
image error image
service nodeport
settings_local use settings_local from my mac
static.dir init
README.md use settings_local from my mac
harbor.crt add crt
images init
init.sh init
load_images.sh init
static_route_table.json init

【WIP】Mac下搭建本地k8s,并进行开发、调试和部署

安装Docker/k8s

  1. 安装 Docker for Mac,Version>=18.06,低版本可能不自带Kubernetes

  2. 设置 Docker 中国官方镜像加速 registry mirror https://registry.docker-cn.com

mirror

  1. 预先从阿里云Docker镜像下载 Kubernetes 所需要的镜像, 可以通过修改 ./images 文件定制你自己需要的镜像
$ ./load_images.sh
  1. Docker for Mac 设置中启用 Kubernetes 选项, 并等待一会儿,直到 Kubernetes 开始运行。

k8s

  1. 可选的步骤: 切换Kubernetes运行上下文至 docker-for-desktop
# 一般只有在之前用其他方式运行过Kubernetes才需要
$ kubectl config use-context docker-for-desktop
  1. 验证 Kubernetes 集群状态
$ kubectl cluster-info
$ kubectl get nodes
  1. 部署 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

服务初次部署

  1. 添加证书,重启docker

    sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./harbor.crt
  2. docker login harbor.test.gengmei

    docker login harbor.test.gengmei
    username: gmuser
    password: Gengmei123!
  3. 创建项目目录,日志目录到指定位置

    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
  4. 每个项目checkout到paas分支,build镜像

    cd 项目目录
    git checkout paas
    docker build --no-cache -t 项目名:local.latest .
  5. 复制 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
  6. docker-for-mac上添加File Sharing配置 /srv/apps、/data/log,添加后点击Apply & Restart,若报错如下,可不必添加。

  7. 备份之前的路由表,用当前目录下的路由表替换之前的路由表

    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
  8. 设置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
  9. 部署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
  10. 测试服务是否正常

    kubectl get service -o wide

    找到backend-service的PORTS, 如下图就是33254,访问localhost:33254

服务调试

  1. 本地开发,对/srv/apps的服务进行开发

  2. (如果涉及依赖的更新,先切到项目目录,执行docker build --no-cache -t 项目名:local.latest .)

  3. 更新服务

    kubectl replace --force -f deploy/backend-service.yml  # 更改了哪个服务,更新时就用deploy目录下的对应文件更新
  4. 测试