【k8s】【docker】web项目的部署

yaml配置文件

后端:springboot项目
前端:vue项目,之前镜像封装的nginx.conf反向代理配置直接使用了docker-compose.yml中services的名称,无法代理成功,可修改为127.0.0.1

# 后端
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kaohe-server
  namespace: default
  labels:
    app: kaohe-server
spec:
  replicas: 2
  selector:
    matchLabels:
      app: kaohe-server
  template:
    metadata:
      labels:
        app: kaohe-server
    spec:
      containers:
      - name: kaohe-server
        image: kaohe-server
        imagePullPolicy: Always 
        env:
        - name: SPRING_DATASOURCE_URL
          value: jdbc:mysql://[ip]:3306/check?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=CTT
      imagePullSecrets: 
      - name: mydocker

---
apiVersion: v1
kind: Service
metadata:
  name: kaohe-server
  namespace: default
  labels:
    app: kaohe-server
spec:
  type: NodePort
  ports:
  - port: 18892
    targetPort: 18892
    nodePort: 18892
  selector:
    app: kaohe-server

---
# 前端
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kaohe-front
  namespace: default
  labels:
    app: kaohe-front
spec:
  replicas: 2
  selector:
    matchLabels:
      app: kaohe-front
  template:
    metadata:
      labels:
        app: kaohe-front
    spec:
      containers:
      - name: kaohe-front
        image: kaohe-front
        imagePullPolicy: Always 
        ports:
        - containerPort: 80
          name: kaohe-front
      imagePullSecrets: 
      - name: mydocker

---
apiVersion: v1
kind: Service
metadata:
  name: kaohe-front
  namespace: default
  labels:
    app: kaohe-front
spec:
  type: NodePort
  ports:
  - port: 8095 #service
    targetPort: 80 #pod
    nodePort: 8095 #对外
  selector:
    app: kaohe-front

你可能感兴趣的:(运维,kubernetes,docker,前端)