- Dockerfile文件配置:
#下载最新nginx
FROM nginx
MAINTAINER zr
#vue dist包上传到容器nginx默认目录
ADD dist.tar.gz /usr/share/nginx/html
#复制本地nginx配置文件覆盖容器nginx默认配置文件
COPY nginx.conf /etc/nginx/nginx.conf
#暴漏容器端口
EXPOSE 8088
#指定容器时区
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai">/etc/timezone
#启动nginx容器服务
ENTRYPOINT nginx -g "daemon off;"
- k8s-vue-demo.yaml文件配置:
apiVersion: v1
kind: Service
metadata:
name: $IMG_NAME
namespace: realize
labels:
app: $IMG_NAME
spec:
type: NodePort
ports:
- port: 8088
nodePort: 30088 #service对外开放端口
selector:
app: $IMG_NAME
---
apiVersion: apps/v1
kind: Deployment #对象类型
metadata:
name: $IMG_NAME #名称
namespace: realize
labels:
app: $IMG_NAME #标注
spec:
replicas: 1 #运行容器的副本数,修改这里可以快速修改分布式节点数量
selector:
matchLabels:
app: $IMG_NAME
template:
metadata:
labels:
app: $IMG_NAME
spec:
containers: #docker容器的配置
- name: $IMG_NAME
image: rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/$IMG_NAME:$IMG_TAG # pull镜像的地址 ip:prot/dir/images:tag
imagePullPolicy: Always #pull镜像时机,
ports:
- containerPort: 8088 #容器对外开放端口,需与springboot配置文件一致
#从私有仓库拉取镜像凭证
imagePullSecrets:
- name: rz-dt-miyue
- k8s 一键发布pod/service/ingress 脚本 deploy.sh配置
echo "开始制作镜像..."
image_tag=`date +%Y-%m-%d-%H-%M-%S` #_%H%M
image_name=k8s-vue-demo
echo "当前时间版本号:$image_tag"
docker build -t ${image_name}:${image_tag} .
echo "制作镜像成功!"
echo "登录"
sudo docker login --username=aliyun039851315 rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com --password=1234
echo "镜像最新版本提交"
docker tag ${image_name}:${image_tag} rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/${image_name}:${image_tag}
docker push rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/${image_name}:${image_tag}
echo "k8s一键部署"
export IMG_TAG=${image_tag}
export IMG_NAME=${image_name}
envsubst< ${image_name}.yaml | kubectl apply -f -
- nginx.conf配置
server {
listen 8088; #端口号,自定义
server_name 127.0.0.1;
root /usr/share/nginx/html/;
index index.html;
location / {
try_files $uri $uri/ @router;
index index.html index.htm index.php;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET';
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location @router {
rewrite ^.*$ /index.html last;
}
location /prod-api/ {
rewrite ^/prod-api/(.*)$ /$1 break;
proxy_pass http://k8s-realize-master.realize:8080/; #k8s访问java地址,Service名称.命名空间:pod容器端口
}
}
- Dockerfile配置文件
#基础镜像,如果本地仓库没有,会从远程仓库拉取 openjdk:8
FROM openjdk:8
#暴露端口
EXPOSE 8080
#容器中创建目录
RUN mkdir -p /usr/local/java
#编译后的jar包copy到容器中创建到目录内
COPY target/k8s-realize-master.jar /usr/local/java/k8s-realize-master.jar
#指定容器时区
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai">/etc/timezone
#指定容器启动时要执行的命令
ENTRYPOINT ["java","-jar","/usr/local/java/k8s-realize-master.jar"]
- k8s-realize-master.yaml配置文件
apiVersion: v1
kind: Service
metadata:
name: $IMG_NAME
namespace: realize
labels:
app: $IMG_NAME
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30080 #service对外开放端口
selector:
app: $IMG_NAME
---
apiVersion: apps/v1
kind: Deployment #对象类型
metadata:
name: $IMG_NAME #名称
namespace: realize
labels:
app: $IMG_NAME #标注
spec:
replicas: 1 #运行容器的副本数,修改这里可以快速修改分布式节点数量
selector:
matchLabels:
app: $IMG_NAME
template:
metadata:
labels:
app: $IMG_NAME
spec:
containers: #docker容器的配置
- name: $IMG_NAME
image: rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/$IMG_NAME:$IMG_TAG # pull镜像的地址 ip:prot/dir/images:tag
imagePullPolicy: Always #pull镜像时机,
ports:
- containerPort: 8080 #容器对外开放端口,需与springboot配置文件一致
volumeMounts:
- name: time-config
mountPath: /etc/localtime
readOnly: true
#从私有仓库拉取镜像凭证
imagePullSecrets:
- name: rz-dt-miyue
volumes:
- name: time-config
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
- k8s一键发布pod|service|ingress脚本 deploy.sh:
echo "开始制作镜像..."
image_name=k8s-realize-master
image_tag=`date +%Y-%m-%d-%H-%M-%S` #_%H%M
echo "当前时间版本号:$image_tag"
docker build -t ${image_name}:${image_tag} .
echo "制作镜像成功!"
echo "登录"
sudo docker login --username=aliyun039851315 rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com --password=1234
echo "镜像最新版本提交"
docker tag ${image_name}:${image_tag} rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/${image_name}:${image_tag}
docker push rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/${image_name}:${image_tag}
echo "k8s一键部署"
export IMG_TAG=${image_tag}
export IMG_NAME=${image_name}
envsubst< ${image_name}.yaml | kubectl apply -f -
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
分享题目:阿里云k8s部署vue+nginx+springboot-创新互联
地址分享:https://www.cdcxhl.com/article48/pjsep.html
成都网站建设公司_创新互联,为您提供响应式网站、App开发、搜索引擎优化、微信小程序、品牌网站建设、全网营销推广
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联