谷粒商城 - 个人笔记(集群部署篇三)

前言

  1. ​学习视频:​Java项目《谷粒商城》架构师级Java项目实战,对标阿里P6-P7,全网最强​
  2. 学习文档:

​3. 接口文档:https://easydoc.net/s/78237135/ZUqEdvA4/hKJTcbfd
4. 本内容仅用于个人学习笔记,如有侵扰,联系删

十、k8s上部署应用

1、k8s部署应用流程

在这里插入图片描述

部署应用流程:

  1. 为每一个项目准备一个Dockerfile;Docker按照这个Dockerfile将项目制作成镜像
  2. 为每一个项目生成k8s的部署描述文件
  3. Jenkins编写好Jenkinsfile

2、生产环境配置抽取

现在我们需要部署到k8s,我们需要用到的各个服务,都应该引用k8s上的服务地址

1、gulimall-auth-server
新建一个application-prod.properties配置文件

# 端口号
server.port=8080
# 应用程序名
spring.application.name=gulimall-auth-server
# nacos注册中心
spring.cloud.nacos.discovery.server-addr=gulimall-nacos-service.gulimall:8848

# 关闭thymeleaf的缓存
spring.thymeleaf.cache=false

# 配置redis
spring.redis.host=gulimall-redis.gulimall
spring.redis.port=6379

# 配置SpringSession存储类型
spring.session.store-type=redis

# Sentinel
#Sentinel控制台地址
spring.cloud.sentinel.transport.dashboard=gulimall-sentimel-service:8333
#Sentinel传输端口
spring.cloud.sentinel.transport.port=8719
#暴露的 endpoint 路径为 /actuator/sentinel
#Sentinel Endpoint 里暴露的信息非常有用。包括当前应用的所有规则信息、日志目录、
#当前实例的 IP,Sentinel Dashboard 地址,Block Page,应用与 Sentinel Dashboard 的心跳频率等等信息。
management.endpoints.web.exposure.include=*
#sentinel是不会对feign进行监控的,需要开启配置
feign.sentinel.enabled=true

# zipkin-链路追踪
#打开链路追踪日志
#logging.level.org.springframework.cloud.openfeign=debug
#logging.level.org.springframework.cloud.sleuth=debug
#链路追踪配置
#spring.zipkin.base-url=gulimall-zipkin-service.gulimall:9411/ # zipkin 服务器的地址
# 关闭服务发现,否则 Spring Cloud 会把 zipkin 的 url 当做服务名称
#spring.zipkin.discoveryClientEnabled= false
#设置使用 http 的方式传输数据
#spring.zipkin.sender.type=web
#spring.zipkin.sleuth.sampler.probability= 1 # 设置抽样采集率为 100%,默认为 0.1,即 10%

# 日志
logging.level.com.atguigu=info

2、gulimall-cart
新建一个application-prod.properties配置文件

# 服务端口号
server.port=8080

# 应用程序名
spring.application.name=gulimall-cart

# nacos注册中心
spring.cloud.nacos.discovery.server-addr=gulimall-nacos-service.gulimall:8848

# 关闭thymeleaf的缓存
spring.thymeleaf.cache=false

# 配置redis
spring.redis.host=gulimall-redis.gulimall
spring.redis.port=6379

# 配置SpringSession存储类型
spring.session.store-type=redis

# 配置线程池
gulimall.thread.core= 20
gulimall.thread.max-size= 200
gulimall.thread.keep-alive-time= 10

# Sentinel
#Sentinel控制台地址
spring.cloud.sentinel.transport.dashboard=gulimall-sentimel-service:8333
#Sentinel传输端口
spring.cloud.sentinel.transport.port=8719
#暴露的 endpoint 路径为 /actuator/sentinel
#Sentinel Endpoint 里暴露的信息非常有用。包括当前应用的所有规则信息、日志目录、
#当前实例的 IP,Sentinel Dashboard 地址,Block Page,应用与 Sentinel Dashboard 的心跳频率等等信息。
management.endpoints.web.exposure.include=*
#sentinel是不会对feign进行监控的,需要开启配置
feign.sentinel.enabled=true

# zipkin-链路追踪
#打开链路追踪日志
#logging.level.org.springframework.cloud.openfeign=debug
#logging.level.org.springframework.cloud.sleuth=debug
#
#链路追踪配置
#spring.zipkin.base-url=http://gulimall-zipkin-service.gulimall:9411/ # zipkin 服务器的地址
#关闭服务发现,否则 Spring Cloud 会把 zipkin 的 url 当做服务名称
#spring.zipkin.discoveryClientEnabled= false
#设置使用 http 的方式传输数据
#spring.zipkin.sender.type=web
#spring.zipkin.sleuth.sampler.probability= 1 # 设置抽样采集率为 100%,默认为 0.1,即 10%

# 日志
logging.level.com.atguigu=info

3、gulimall-coupon
新建一个application-prod.properties配置文件

# 服务端口号
server.port=8080

# 应用程序名
spring.application.name=gulimall-coupon

# 数据源
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://gulimall-mysql-master.gulimall:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=123456

# nacos注册中心
spring.cloud.nacos.discovery.server-addr=gulimall-nacos-service.gulimall:8848

# mybatis-plus
mybatis-plus.mapper-locations=classpath:/mapper/**/*.xml
mybatis-plus.global-config.db-config.id-type=auto
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0

# json的日期格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

# Sentinel
#Sentinel控制台地址
spring.cloud.sentinel.transport.dashboard=gulimall-sentimel-service:8333
#Sentinel传输端口
spring.cloud.sentinel.transport.port=8719
#暴露的 endpoint 路径为 /actuator/sentinel
#Sentinel Endpoint 里暴露的信息非常有用。包括当前应用的所有规则信息、日志目录、
#当前实例的 IP,Sentinel Dashboard 地址,Block Page,应用与 Sentinel Dashboard 的心跳频率等等信息。
management.endpoints.web.exposure.include=*
#sentinel是不会对feign进行监控的,需要开启配置
feign.sentinel.enabled=true

# zipkin-链路追踪
#打开链路追踪日志
#logging.level.org.springframework.cloud.openfeign=debug
#logging.level.org.springframework.cloud.sleuth=debug
#链路追踪配置
#spring.zipkin.base-url=http://gulimall-zipkin-service.gulimall:9411/ # zipkin 服务器的地址
#关闭服务发现,否则 Spring Cloud 会把 zipkin 的 url 当做服务名称
#spring.zipkin.discoveryClientEnabled= false
#设置使用 http 的方式传输数据
#spring.zipkin.sender.type=web
#spring.zipkin.sleuth.sampler.probability= 1 # 设置抽样采集率为 100%,默认为 0.1,即 10%

# 日志
logging.level.com.atguigu=info

# 常量
coupon.user.name=zhangsan
coupon.user.age=18

新建一个bootstrap-prod.properties配置文件

# 指定应用程序的名称
spring.application.name=gulimall-coupon

4、gulimall-gateway
新建一个application-prod.properties配置文件

# 服务端口号
server.port=8080

# 应用程序名
spring.application.name=gulimall-gateway

# nacos注册中心
spring.cloud.nacos.discovery.server-addr=gulimall-nacos-service.gulimall:8848

# Sentinel
#Sentinel控制台地址
spring.cloud.sentinel.transport.dashboard=gulimall-sentimel-service:8333
#Sentinel传输端口
spring.cloud.sentinel.transport.port=8719
#暴露的 endpoint 路径为 /actuator/sentinel
#Sentinel Endpoint 里暴露的信息非常有用。包括当前应用的所有规则信息、日志目录、
#当前实例的 IP,Sentinel Dashboard 地址,Block Page,应用与 Sentinel Dashboard 的心跳频率等等信息。
management.endpoints.web.exposure.include=*
#sentinel是不会对feign进行监控的,需要开启配置
feign.sentinel.enabled=true

新建一个application-prod.yml配置文件

spring:
  cloud:
    gateway:
      routes:
        - id: test_route
          uri: https://www.baidu.com
          predicates:
            - Query=url,baidu

        - id: qq_route
          uri: https://www.qq.com
          predicates:
            - Query=url,qq

        - id: product_route
          uri: lb://gulimall-product
          predicates:
            - Path=/api/product/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{
   
   segment}

        - id: third_party_route
          uri: lb://gulimall-third-party
          predicates:
            - Path=/api/thirdparty/**
          filters:
            - RewritePath=/api/thirdparty/(?<segment>.*),/$\{
   
   segment}

        - id: member_route
          uri: lb://gulimall-member
          predicates:
            - Path=/api/member/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{
   
   segment}

        - id: order_route
          uri: lb://gulimall-order
          predicates:
            - Path=/api/order/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{
   
   segment}

        - id: ware_route
          uri: lb://gulimall-ware
          predicates:
            - Path=/api/ware/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{
   
   segment}

        - id: coupon_route
          uri: lb://gulimall-coupon
          predicates:
            - Path=/api/coupon/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{
   
   segment}

        - id: admin_route
          uri: lb://gulimall-admin
          predicates:
            - Path=/api/**
          filters:
            - RewritePath=/api/(?<segment>.*),/gulimall-admin/$\{
   
   segment}

        - id: gulimall_host_route
          uri: lb://gulimall-product
          predicates:
            - Host=gulimall.com,item.gulimall.com

        - id: gulimall_search_route
          uri: lb://gulimall-search
          predicates:
            - Host=search.gulimall.com

        - id: gulimall_auth_route
          uri: lb://gulimall-auth-server
          predicates:
            - Host=auth.gulimall.com

        - id: gulimall_cart_route
          uri: lb://gulimall-cart
          predicates:
            - Host=cart.gulimall.com

        - id: gulimall_order_route
          uri: lb://gulimall-order
          predicates:
            - Host=order.gulimall.com

        - id: gulimall_member_route
          uri: lb://gulimall-member
          predicates:
            - Host=member.gulimall.com

        - id: gulimall_seckill_route
          uri: lb://gulimall-seckill
          predicates:
            - Host=seckill.gulimall.com

  ## 前端项目,/api
  ## http://localhost:88/api/captcha.jpg   http://localhost:8080/renren-fast/captcha.jpg
  ## http://localhost:88/api/product/category/list/tree http://localhost:10000/product/category/list/tree

5、gulimall-member
新建一个application-prod.properties配置文件

# 服务端口
server.port=8080

# 应用程序名
spring.application.name=gulimall-member

# 数据源
spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://gulimall-mysql-master.gulimall:3306/gulimall_ums?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username: root
spring.datasource.password: 123456

# nacos注册中心
spring.cloud.nacos.discovery.server-addr=gulimall-nacos-service.gulimall:8848

# 配置redis
spring.redis.host=gulimall-redis.gulimall
spring.redis.port=6379

# 配置SpringSession存储类型
spring.session.store-type=redis

# 关闭thymeleaf的缓存
spring.thymeleaf.cache=false

# mybatis-plus
mybatis-plus.mapper-locations=classpath:/mapper/**/*.xml
mybatis-plus.global-config.db-config.id-type=auto
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0

# Sentinel
#Sentinel控制台地址
spring.cloud.sentinel.transport.dashboard=gulimall-sentimel-service:8333
#Sentinel传输端口
spring.cloud.sentinel.transport.port=8719
#暴露的 endpoint 路径为 /actuator/sentinel
#Sentinel Endpoint 里暴露的信息非常有用。包括当前应用的所有规则信息、日志目录、
#当前实例的 IP,Sentinel Dashboard 地址,Block Page,应用与 Sentinel Dashboard 的心跳频率等等信息。
management.endpoints.web.exposure.include=*
#sentinel是不会对feign进行监控的,需要开启配置
feign.sentinel.enabled=true

# zipkin-链路追踪
#打开链路追踪日志
#logging.level.org.springframework.cloud.openfeign=debug
#logging.level.org.springframework.cloud.sleuth=debug
#链路追踪配置
#spring.zipkin.base-url=http://gulimall-zipkin-service.gulimall:9411/ # zipkin 服务器的地址
#关闭服务发现,否则 Spring Cloud 会把 zipkin 的 url 当做服务名称
#spring.zipkin.discoveryClientEnabled= false
#设置使用 http 的方式传输数据
#spring.zipkin.sender.type=web
#spring.zipkin.sleuth.sampler.probability= 1 # 设置抽样采
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值