- Dockerfile文件配置:
#下載最新nginx
FROM nginx
MAINTAINER zr
#vue dist包上傳到容器nginx默認(rèn)目錄
ADD dist.tar.gz /usr/share/nginx/html
#復(fù)制本地nginx配置文件覆蓋容器nginx默認(rèn)配置文件
COPY nginx.conf /etc/nginx/nginx.conf
#暴漏容器端口
EXPOSE 8088
#指定容器時(shí)區(qū)
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai">/etc/timezone
#啟動nginx容器服務(wù)
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 #標(biāo)注
spec:
replicas: 1 #運(yùn)行容器的副本數(shù),修改這里可以快速修改分布式節(jié)點(diǎn)數(shù)量
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鏡像時(shí)機(jī),
ports:
- containerPort: 8088 #容器對外開放端口,需與springboot配置文件一致
#從私有倉庫拉取鏡像憑證
imagePullSecrets:
- name: rz-dt-miyue
- k8s 一鍵發(fā)布pod/service/ingress 腳本 deploy.sh配置
echo "開始制作鏡像..."
image_tag=`date +%Y-%m-%d-%H-%M-%S` #_%H%M
image_name=k8s-vue-demo
echo "當(dāng)前時(shí)間版本號:$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配置文件
#基礎(chǔ)鏡像,如果本地倉庫沒有,會從遠(yuǎn)程倉庫拉取 openjdk:8
FROM openjdk:8
#暴露端口
EXPOSE 8080
#容器中創(chuàng)建目錄
RUN mkdir -p /usr/local/java
#編譯后的jar包c(diǎn)opy到容器中創(chuàng)建到目錄內(nèi)
COPY target/k8s-realize-master.jar /usr/local/java/k8s-realize-master.jar
#指定容器時(shí)區(qū)
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai">/etc/timezone
#指定容器啟動時(shí)要執(zhí)行的命令
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 #標(biāo)注
spec:
replicas: 1 #運(yùn)行容器的副本數(shù),修改這里可以快速修改分布式節(jié)點(diǎn)數(shù)量
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鏡像時(shí)機(jī),
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一鍵發(fā)布pod|service|ingress腳本 deploy.sh:
echo "開始制作鏡像..."
image_name=k8s-realize-master
image_tag=`date +%Y-%m-%d-%H-%M-%S` #_%H%M
echo "當(dāng)前時(shí)間版本號:$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 -
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧