前言:

之前的Django项目直接部署到Docker容器中,简单高效;

不过生产中还是要部署到K8S中,在此总结一下工作经历

一、Harbor仓库

创建harbor仓库项目

传送门:Harbor单点仓库部署

二、编写Dockefile

Dockerfile文件

FROM python:3.6
WORKDIR /root
COPY . /root/
RUN pip install --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple -r /root/requirements.txt
CMD uwsgi --ini /root/cops_uwsgi.ini

requirements.txt文件

requests
django
djangorestframework
uwsgi
mysqlclient
ldap3
redis
boto

uwsgi配置

为什么要用uwsgi请自行百度

[uwsgi]
http=0.0.0.0:9001
chdir=/root
module = Project.wsgi
vacuum=True
master=True
workers=8
enable-threads=True
threads=32
memory-report=True

构建脚本build.sh

#!/bin/sh
REV=`git rev-parse --short HEAD`
docker build -t cloudops_test:$REV .

docker tag cloudops_test:${REV} xxxx:888/cloudops/cloudops_test:${REV}
docker push 10.60.128.219:888/cloudops/cloudops_test:${REV}

三、发布代码到仓库

3.1 拉取git仓库代码

[root@xxxx harbor]# cd /data/web/xxx/
[root@xxxx xxx]# git pull   #### 各位看官,请跟实际环境操作

3.2 Harbor项目推送示例

Django项目构建发布Harbor仓库

3.2 构建Django代码

[root@xxxx opsservice]# cat build.sh 
#!/bin/sh
REV=`git rev-parse --short HEAD`
docker build -t cloudops_test:$REV .


docker tag cloudops_test:${REV} xxxx:888/clxxxs/cxxxxx_test:${REV}
docker push xxxxx:888/xxxx/clxxxx_test:${REV}
[root@1xxx xxx]# /bin/sh build.sh

3.3 检测镜像

[root@xxxx oxxxx]# docker images|grep cloudops_test
cloxxxxt                              ffbaa25             8cd31496a16a        18 hours ago        987MB
xxx9:888/cloudops/cloudops_test   78b8ccc             ad7ef3db0a88        47 hours ago        987MB
clxxxxt                              78b8ccc             ad7ef3db0a88        47 hours ago        987MB
[root@xxxx xxxx]# 

四、K8S拉取镜像创建pod

传送门:K8S拉取Django项目创建pod

相关文章:

  • 2022-01-11
  • 2022-12-23
  • 2021-07-31
  • 2021-09-14
  • 2021-12-23
  • 2021-06-28
  • 2021-12-21
  • 2021-09-06
猜你喜欢
  • 2021-05-29
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2021-05-25
  • 2022-12-23
相关资源
相似解决方案