docker build -t dvm.adsplatformproxy:v1.0.0 . #build images docker run -e WWNamespace=dev -e ZKServerAddress=****** -p 6000:80 6cb913a34ae3 #run container,本地起进程 docker run -ti 6cb913a34ae3 /bin/bash #远程进入image文件;exit退出 docker rmi -f b54d6e186ef4 #远程删除image docker rmi -rf b54d6e186ef4 docker build -t dvm.adsplatformproxy:v1.0.0 . #build images docker run -e WWNamespace=dev -e ZKServerAddress=****** -p 6000:80 6cb913a34ae3 #run container,本地起进程 docker run -ti 6cb913a34ae3 /bin/bash #远程进入image文件;exit退出 docker rmi -f b54d6e186ef4 #远程删除image docker rmi -rf b54d6e186ef4
镜像可以在命令行生成,如:
docker build . -t *******:v1.0.0.3
随后Tag到Docker仓库:
docker tag *******:v1.0.0.3 [ip]:5000/[path]:v1.0.0.3
如果确认无误后要推送到仓库,可以执行:
docker push [ip]:5000/[path]:v1.0.0.3:v1.0.0.3
如果要在VS中生成镜像,需要考虑把Docker-compose设置为启动项目,并至少启动项目一次。每次需要重新生成镜像时,建议先在Docker-Compose项目中先清理,再生成。
随后的Tag和Push参考上面的流程。
1、 在开发机上安装Docker,并将[ip]:5000设置为insecure registry
2、 下载kubectl.exe,并把相关的路径放入到环境变量Path中
3、 把相关的crt和key文件放入到用户根目录的.kube目录下,如C:\Users\user01\.kube
4、 打开命令行,在配置文件中新建cluster,如
kubectl config set-cluster bjoffice --server=https://[ip]:6443 --insecure-skip-tls-verify
5、 将客户信息绑定
kubectl.exe config set-credentials username --client-certificate=username.crt --client-key=username.key
6、 绑定用户Context
kubectl config set-context username-context --cluster=[] --namespace=yourns --user=username
7、 切换用户当前Context
kubectl config use-context username-context
设定完成后大家就可以按照容器模式开发和管理微服务了。
附件中包括kubernetes控制工具,相应的证书文件和示范的yaml.
1、 熟悉基于容器的微服务开发和打包(Dev)
2、 熟悉容器的部署
3、 制定相关开发规范
4、 制定管理规范,如自动发布/回滚机制和监控
5、 部署群集环境并运营
6、 考虑用不同的开发堆栈提高效率
7、 总结提高
Dev:
Build and push the image
Create the yaml
Manage dev configmap/secrets
Build custom base images if necessary
May has the view access to the online production*(TBD)
Test:
Test base on the images/yaml
Manage the test configmap/secrets
Tag the release branch/image
Push the yaml/image to production repository (manual script/CI)
OPS:
Infrastructure management(Nodes)
Online resource monitoring(CPU/Memory)
Manage the production configmap/secrets
Nodes & deployment management if necessary
Replicator control if necessary
Yaml书写应该分成三部分:
1、 Config
2、 Deployment and service
3、 Ingress
具体大家可以参考Docs\Yaml\Deploy下的Sample。
请需要更新,只更新相关部分并尽量避免delete/create方式更新,考虑使用edit模式编辑。
在某些情况下,可能需要跳过部署直接以交互模式调试镜像(如Job),可以直接用kubectl run命令,ran参数后面是deployment 名称:
kubectl -n dev run downloadimagetest --image=[ip]:5000/[path]:v1.0.0.6 -- /usr/bin/tail -f /dev/null
然后以kubecl exec -ti podname /bin/bash 命令登陆这个pod进行调试。
请注意这个过程不会设置yaml中的环境参数,如果需要请额外设置。
如果只是配置上的调整,无需delete/create整个yaml,设置deployment的image参数就可以了。
kubectl -n dev set image deployment/******-deployment dvm-adsproxyapi=[ip]:5000/[patch]:v1.0.0.412
或者用edit命令人工编辑(会弹出记事本或者vi):
kubectl -n dev edit deployment/******-deployment
如果在开发过程中无法Push/Pull 镜像,请考虑重新启动Docker。
如果需要利用Visual Studio 生成Docker镜像,需要将目标项目设置为Docker-compose,同时将模式设置为Release。
在Debug模式下,VS只会生成很少量的dll, 供VS使用。
目前我们的Dockerfile的Sample中,默认从./obj/Docker/publish中复制文件(这个目录包含所有dll)。
如果需要人工Publish但又不想build Solution级别的Docker-compose,则可以在项目目录(Dockerfile文件所在位置)执行以下命令
dotnet publish ******.WebApi.csproj -c Release -o ./obj/Docker/publish
其中项目名称和模式请根据实际替换。
然后用docker build -t tagname . 打包。
大家也可以写.cmd文件直接把这两步合并到一块。
大家在开发的使用经常遇到需要部署后调试的问题,这种情况下大家应该考虑启用本地Docker容器,如:
docker run -e WWNamespace=[] -e ZKServerAddress=[ip1],[ip2],[ip3] -p 5000:80 5aed1c78f55e
其中-e 是设置环境变量,-p 是设置端口映射,第一个端口是主机端口,第二个端口是容器的端口(对于WebApi通常是80),最后一个端口是容器编号。
如果要在后台运行,可以加入-d参数,之后结束这个进程即可。