πŸ“Œ Spring Cloud Config μ„€μ • 쀑앙화와 ν™˜κ²½λ³„ ꡬ성 관리 정리

ghgh2505380Β·2026λ…„ 3μ›” 21일

MSA(Microservice Architecture)

λͺ©λ‘ 보기
7/13

πŸ“– κ°œμš”

Spring Cloud Config
λΆ„μ‚° μ‹œμŠ€ν…œ ν™˜κ²½μ—μ„œ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 섀정을 μ€‘μ•™μ—μ„œ κ΄€λ¦¬ν•˜λŠ” ꡬ성 관리 μ„œλ²„

  • λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€ ν™˜κ²½μ—μ„œ μ„€μ • 쀑앙 관리 κ°€λŠ₯
  • ν™˜κ²½λ³„(local, dev, qa, prod λ“±) μ„€μ • 뢄리 지원
  • μ„€μ • λ³€κ²½ μ‹œ 재배포 없이 반영 κ°€λŠ₯

μ™œ μ‚¬μš©ν•˜λŠ”μ§€

  • μ„œλΉ„μŠ€ 증가 μ‹œ μ„€μ • 관리 λ³΅μž‘λ„ 증가
  • DB, API, 포트 섀정이 μ„œλΉ„μŠ€λ§ˆλ‹€ 뢄산됨
  • μ„€μ • λ³€κ²½ μ‹œ 일괄 관리 어렀움 λ°œμƒ

ν•΄κ²°ν•˜λŠ” 문제

  • μ„€μ • 파일 쀑앙 관리
  • ν™˜κ²½λ³„ μ„€μ • 뢄리
  • μ„€μ • λ³€κ²½ 반영 방식 톡일

βš™οΈ 핡심 κ°œλ…

1️⃣ Config Server

μ„€μ • νŒŒμΌμ„ μ €μž₯ν•˜κ³  μ œκ³΅ν•˜λŠ” μ„œλ²„ μ—­ν•  μˆ˜ν–‰
쀑앙 μ €μž₯μ†Œ μ—­ν•  λ‹΄λ‹Ή

@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

2️⃣ Config Client

각 μ„œλΉ„μŠ€λŠ” Config Serverμ—μ„œ 섀정을 κ°€μ Έμ™€μ„œ μ‚¬μš©

spring:
  application:
    name: product-service
  config:
    import: "configserver:"
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server
  • μ„œλΉ„μŠ€ 이름 κΈ°μ€€ μ„€μ • λ§€μΉ­
  • Config Serverμ—μ„œ μ„€μ • 쑰회 ν›„ 적용

3️⃣ ν™˜κ²½λ³„ ν”„λ‘œν•„ 관리

ν™˜κ²½λ³„ μ„€μ • 파일 뢄리 κ°€λŠ₯

product-service.yml
product-service-local.yml
product-service-dev.yml
product-service-qa.yml
product-service-prod.yml
spring:
  profiles:
    active: local
  • active κ°’μœΌλ‘œ ν™˜κ²½ 선택
  • application name + profile κΈ°μ€€ μ„€μ • λ‘œλ“œ

β€» ν”„λ‘œν•„ 이름은 κ³ μ • κ·œμΉ™μ΄ μ•„λ‹Œ νŒ€ 정책에 따라 ꡬ성
(local, dev, qa, staging, prod λ“±)

4️⃣ μ„€μ • κ°±μ‹  방식

μ„€μ • λ³€κ²½ ν›„ 반영 방식

  • /actuator/refresh 호좜 β†’ μˆ˜λ™ κ°±μ‹ 
  • Spring Cloud Bus β†’ μžλ™ κ°±μ‹ 

이번 κ΅¬μ„±μ—μ„œλŠ” μˆ˜λ™ κ°±μ‹  방식 μ‚¬μš©


πŸ” λ™μž‘ 원리

Client Service β†’ Eureka β†’ Config Server β†’ μ„€μ • 파일 쑰회 β†’ Client 적용

μ‹€ν–‰ 흐름

Product Service μ‹€ν–‰
β†’ Eureka 등둝
β†’ Config Server μœ„μΉ˜ 쑰회
β†’ product-service-local.yml λ‘œλ“œ
β†’ μ„€μ • 적용

μ„€μ • λ³€κ²½ 흐름

μ„€μ • 파일 μˆ˜μ •
β†’ Config Server 반영
β†’ /actuator/refresh 호좜
β†’ μ„€μ • 재적용

ꡬ쑰

Eureka Server β†’ Config Server β†’ Product Service


πŸ’» μ½”λ“œ μ˜ˆμ‹œ

1️⃣ Config Server μ„€μ •

server:
  port: 18080

spring:
  profiles:
    active: native
  application:
    name: config-server
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config-repo

eureka:
  client:
    service-url:
      defaultZone: http://localhost:19090/eureka/
  • native λͺ¨λ“œ μ‚¬μš© β†’ 둜컬 파일 기반 μ„€μ • 제곡

2️⃣ Config Client μ„€μ •

server:
  port: 0

spring:
  profiles:
    active: local
  application:
    name: product-service
  config:
    import: "configserver:"
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server

management:
  endpoints:
    web:
      exposure:
        include: refresh

eureka:
  client:
    service-url:
      defaultZone: http://localhost:19090/eureka/

3️⃣ μ„€μ • 파일 μ˜ˆμ‹œ

# product-service.yml
server:
  port: 19093
message: "product-service message"
# product-service-local.yml
server:
  port: 19083
message: "product-service-local message"

4️⃣ μ„€μ • κ°’ 쑰회 API

@RefreshScope
@RestController
@RequestMapping("/product")
public class ProductController {

    @Value("${server.port}")
    private String serverPort;

    @Value("${message}")
    private String message;

    @GetMapping
    public String getProduct() {
        return "Product detail from PORT : " + serverPort + " and message : " + message;
    }
}
  • @RefreshScope μ‚¬μš© β†’ μ„€μ • λ³€κ²½ ν›„ 재반영 κ°€λŠ₯

πŸš€ μ‚¬μš© 사둀

  • DB μ—°κ²° 정보 ν™˜κ²½λ³„ 뢄리
  • μ™ΈλΆ€ API URL 관리
  • 곡톡 μ„€μ • 쀑앙 관리
  • 운영 ν™˜κ²½ μ„€μ • λ³€κ²½ λŒ€μ‘
  • feature flag 관리

🧠 TIL (Today I Learned)

Spring Cloud Config μ‚¬μš© μ‹œ μ„€μ • 쀑앙 관리 κ°€λŠ₯
application name + profile κΈ°μ€€μœΌλ‘œ ν™˜κ²½λ³„ μ„€μ • 뢄리
native λͺ¨λ“œλ‘œ 둜컬 ν™˜κ²½ ꡬ성 κ°€λŠ₯
/actuator/refresh 호좜둜 μˆ˜λ™ μ„€μ • κ°±μ‹  처리
ν”„λ‘œν•„ 이름은 νŒ€ 정책에 따라 자유둭게 ꡬ성 κ°€λŠ₯

profile

0개의 λŒ“κΈ€