kubernet手打打前端包并更新发布

环境:centos、前端的tar.gz包、使用nginx打包成images

1、编辑dockerfile

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
ADD *.gz /
RUN mv -f /dist/* /usr/share/nginx/html/
RUN chmod -R 755 /usr/share/nginx/html/
VOLUME ["/usr/share/nginx/html"]

2、编辑nginx.conf

server {
    listen 80;
    server_name  localhost; 
    location /{
       root /usr/share/nginx/html;
       index index.html index.htm;
       try_files $uri $uri/ /index.html =404;
       add_header Cache-Control no-cache;
       add_header Cache-Control private;
       expires 0s;
    }

3、编辑打包更新程序到k8s的脚本

#!/bin/bash
#获取当前路径
dir=$(cd $(dirname $0);pwd)
#images名称
i='test-ywxtpt'
docker build -t 100.98.100.234/chinapopin-test/$i:`date +%-m`.`date +%-d` -f $dir/dockerfile $dir/
docker push 100.98.100.234/chinapopin-test/$i:`date +%-m`.`date +%-d`
docker rmi -f 100.98.100.234/chinapopin-test/$i:`date +%-m`.`date +%-d`
kubectl set image deploy `kubectl get deploy -n test-project|grep ywxtpt-manager-test|awk '{print $1}'` *=100.98.100.234/chinapopin-test/$i:`date +%-m`.`date +%-d` -n test-project
kubectl delete pod `kubectl get pods -n test-project|grep ywxtpt-manager-test|awk '{print $1}'` -n test-project

 

posted @ 2020-08-11 16:20  苍茫宇宙  阅读(209)  评论(0编辑  收藏  举报