文件目录结构

编写 Dockerfile

#基础镜像
#我们打包需要依赖基础镜像
FROM java:8
#将虚拟机的war包,cp到docker容器内部
COPY mark.jar mark.jar
#说明容器开放的端口
EXPOSE 8080
#指定docker容器时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
# 脚本启动
ENTRYPOINT ["sh","-c","java -server -Dfile.encoding=utf-8 -Xms1024m -Xms1536m -jar -Dserver.port=8080  -Dspring.profiles.active=prod mark.jar"]

编写 deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mark-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mark-server
  template:
    metadata:
      labels:
        app: mark-server
    spec:
      containers:
      - name: mark-server
        image: chishishuan/mark_server:v1.0.0
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: mark-server
spec:
  selector:
    app: mark-server
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 31001
  type: NodePort

打包成镜像

docker image build -t chishishuan/mark_server:v1.0.0 .

打包到 k8s 环境

kubectl apply -f deploy.yaml

查看信息

kubectl get pod,service

升级

docker image build -t chishishuan/mark_server:v1.0.1 .

kubectl set image deployment mark-server mark-server=chishishuan/mark_server:v1.0.1 --record=true

查看历史发布版本

kubectl rollout history deployment mark-server

回滚到上一个版本

kubectl rollout undo deployment  mark-server

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐