1 k8s pod申请持久化卷配置
apiVersion: v1
kind: Service
metadata:name: $IMG_NAMEnamespace: rz-dtlabels:app: $IMG_NAME
spec:type: NodePortports:- port: 8091nodePort: 31082 #service对外开放端口selector:app: $IMG_NAME
---
apiVersion: apps/v1
kind: Deployment #对象类型
metadata:name: $IMG_NAME #名称namespace: rz-dtlabels:app: $IMG_NAME #标注
spec:replicas: 1 #运行容器的副本数,修改这里可以快速修改分布式节点数量progressDeadlineSeconds: 600 #在Deployment 在进度卡住6分钟后报告minReadySeconds: 120 #Pod被认为是可用状态的最小秒数。默认是0strategy:rollingUpdate:maxSurge: 1 #升级过程中激增Pod的最大数量maxUnavailable: 0 #升级过程中不可用Pod的最大数量type: RollingUpdateselector:matchLabels:app: $IMG_NAMEtemplate:metadata:labels:app: $IMG_NAMEspec:containers: #docker容器的配置- name: $IMG_NAME
# env:
# - name: aliyun_logs_catalina
# value: stdoutimage: rz-dt-image-server-registry-vpc.cn-shanghai.cr.aliyuncs.com/rz-dt/$IMG_NAME:$IMG_TAG # pull镜像的地址 ip:prot/dir/images:tagimagePullPolicy: Always #pull镜像时机,#command: ["java","-Dserver.port=8055","-jar","/usr/local/cenobitor/k8s-springboot-demo.jar"]ports:- containerPort: 8091 #容器对外开放端口,需与springboot配置文件一致volumeMounts:- name: time-configmountPath: /etc/localtimereadOnly: true- name: volume-logsmountPath: /logssubPath: logsresources:limits:cpu: 500mmemory: 1Girequests:cpu: 10mmemory: 50Mi#从私有仓库拉取镜像凭证imagePullSecrets:- name: rz-dt-miyue-vpc# 数据持久化卷申请volumes:- name: time-confighostPath:path: /usr/share/zoneinfo/Asia/Shanghai- name: volume-logspersistentVolumeClaim:claimName: rz-dt-nas-volume-claim
2 k8s发布脚本
echo "开始制作镜像..."
image_name=application-account
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=aliyun035152 rz-dt-img-server-registry-vpc.cn-shanghai.cr.aliyuncs.com --password=123
echo "镜像最新版本提交"
docker tag ${image_name}:${image_tag} rz-dt-image-server-registry-vpc.cn-shanghai.cr.aliyuncs.com/rz-dt/${image_name}:${image_tag}
docker push rz-dt-image-server-registry-vpc.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 --kubeconfig ~/.kube-rz/config apply -f -
3 k8s 里面deployment+pvc+pv+nas配置截图
- deployment绑定pvc
- pvc绑定pv管理员
- pv绑定nas云盘
- nas绑定映射到ECS云主机/mnt目录下