ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ NestJS + Kubernetes & ๋ง์ดํฌ๋ก์๋น์ค ๋ฐฐํฌ: ์ค์ ๊ฐ์ด๋- ๋ง์ดํฌ๋ก์๋น์ค ์ํคํ ์ฒ(MSA) ๊ฐ๋ ๊ณผ NestJS ์ ์ฉ
octo54 2025. 3. 31. 09:44๐ NestJS + Kubernetes & ๋ง์ดํฌ๋ก์๋น์ค ๋ฐฐํฌ: ์ค์ ๊ฐ์ด๋
1. ๋ง์ดํฌ๋ก์๋น์ค ์ํคํ ์ฒ(MSA) ๊ฐ๋ ๊ณผ NestJS ์ ์ฉ
๐น ๋ง์ดํฌ๋ก์๋น์ค๋?
๋ง์ดํฌ๋ก์๋น์ค ์ํคํ
์ฒ(Microservices Architecture, MSA)๋ ํ๋์ ์ ํ๋ฆฌ์ผ์ด์
์ ์ฌ๋ฌ ๊ฐ์ ๋
๋ฆฝ์ ์ธ ์๋น์ค๋ก ๋ถ๋ฆฌํ์ฌ ์ด์ํ๋ ์ํคํ
์ฒ ํจํด์
๋๋ค.
NestJS๋ ๋ง์ดํฌ๋ก์๋น์ค ํจํด์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ง์ํ๋ฉฐ, ๋ง์ดํฌ๋ก์๋น์ค ๊ฐ ํต์ , API Gateway, ๋ฉ์์ง ํ(RabbitMQ, Kafka)์์ ํตํฉ ๋ฑ์ ์ฝ๊ฒ ๊ตฌํํ ์ ์์ต๋๋ค.
๐น Monolithic vs. Microservices ๋น๊ต
์ํคํ ์ฒ ํน์ง ์ฅ์ ๋จ์
Monolithic (๋ชจ๋๋ฆฌ์) | ํ๋์ ์ ํ๋ฆฌ์ผ์ด์ ์ผ๋ก ๊ตฌ์ฑ | ๋ฐฐํฌ์ ๊ฐ๋ฐ์ด ๊ฐ๋จ | ํ์ฅ์ฑ ๋ถ์กฑ, ์ ์ง๋ณด์ ์ด๋ ค์ |
Microservices (๋ง์ดํฌ๋ก์๋น์ค) | ๋ ๋ฆฝ์ ์ธ ์๋น์ค๋ก ๊ตฌ์ฑ | ํ์ฅ์ฑ ๋ฐ์ด๋๊ณ ์ ์ง๋ณด์ ์ฉ์ด | ์๋น์ค ๊ฐ ํต์ ๋ณต์ก |
๐ก ๋ง์ดํฌ๋ก์๋น์ค๋ ์๋น์ค๋ณ ๋ ๋ฆฝ์ ์ธ ํ์ฅ ๋ฐ ๋ฐฐํฌ๊ฐ ๊ฐ๋ฅํ์ฌ, ๋๊ท๋ชจ ํธ๋ํฝ์ ์ฒ๋ฆฌํ๋ ์๋น์ค์ ์ ๋ฆฌํฉ๋๋ค.
๐น NestJS์์ ๋ง์ดํฌ๋ก์๋น์ค ํจํด ์ ์ฉ
โ NestJS์์ ๋ง์ดํฌ๋ก์๋น์ค๋ฅผ ์ง์ํ๋ ๋ฐฉ์
- NestJS์ Microservices Module ํ์ฉ
- gRPC ๊ธฐ๋ฐ ํต์ ์ง์
- Kafka, RabbitMQ์ ๊ฐ์ ๋ฉ์์ง ํ ์ฐ๋ ๊ฐ๋ฅ
- API Gateway๋ฅผ ํตํ ์๋ํฌ์ธํธ ํตํฉ ๊ด๋ฆฌ
๐น NestJS ๋ง์ดํฌ๋ก์๋น์ค ๊ธฐ๋ณธ ํ๋ก์ ํธ ๊ตฌ์กฐ
nestjs-microservices/
โโโ apps/
โ โโโ api-gateway/ # API Gateway
โ โโโ user-service/ # ์ฌ์ฉ์ ์๋น์ค
โ โโโ order-service/ # ์ฃผ๋ฌธ ์๋น์ค
โโโ libs/
โ โโโ common/ # ๊ณตํต ์ ํธ๋ฆฌํฐ ๋ชจ๋
โ โโโ database/ # ๊ณตํต ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ชจ๋
๐ก ๊ฐ ์๋น์ค๋ ๋ ๋ฆฝ์ ์ผ๋ก ์คํ๋๋ฉฐ, API Gateway๋ฅผ ํตํด ์๋ํฌ์ธํธ๋ฅผ ํตํฉํ ์ ์์ต๋๋ค.
๐น NestJS ๋ง์ดํฌ๋ก์๋น์ค ๊ธฐ๋ณธ ๊ตฌํ (TCP ํต์ ์์ )
โ 1) nestjs ํ๋ก์ ํธ ์์ฑ
nest new nestjs-microservices
cd nestjs-microservices
โ 2) ์ฌ์ฉ์ ์๋น์ค ์์ฑ (user-service)
nest g app user-service
๐ apps/user-service/main.ts
import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { UserModule } from './user.module';
async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
UserModule,
{
transport: Transport.TCP,
options: { host: '127.0.0.1', port: 3001 },
},
);
await app.listen();
}
bootstrap();
โ 3) API Gateway ์์ฑ ๋ฐ ์ค์
nest g app api-gateway
๐ apps/api-gateway/main.ts
import { NestFactory } from '@nestjs/core';
import { ApiGatewayModule } from './api-gateway.module';
async function bootstrap() {
const app = await NestFactory.create(ApiGatewayModule);
await app.listen(3000);
}
bootstrap();
๐ apps/api-gateway/user.controller.ts
import { Controller, Get, Inject } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
@Controller('users')
export class UserController {
constructor(@Inject('USER_SERVICE') private readonly client: ClientProxy) {}
@Get()
async getUsers() {
return this.client.send('get_users', {});
}
}
๐ apps/user-service/user.controller.ts
import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
@Controller()
export class UserController {
@MessagePattern('get_users')
async getUsers() {
return [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
}
}
๐น ์คํ ๋ฐ ํ ์คํธ
โ 1) User Service ์คํ
npm run start:user-service
์ถ๋ ฅ ์์:
Listening on TCP: 127.0.0.1:3001
โ 2) API Gateway ์คํ
npm run start:api-gateway
โ 3) API ์์ฒญ ํ ์คํธ
curl http://localhost:3000/users
์๋ต:
[
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]
๐ก NestJS์ Microservices Module์ ํ์ฉํ์ฌ, TCP ๊ธฐ๋ฐ์ ๊ฐ๋จํ ๋ง์ดํฌ๋ก์๋น์ค๋ฅผ ๊ตฌ์ถํ ์ ์์ต๋๋ค.
๐น ๋ง์ดํฌ๋ก์๋น์ค ์ ์ฉ ์ ๊ณ ๋ คํ ์
โ ์๋น์ค ๊ฐ์ ๋
๋ฆฝ์ ์ธ ๋ฐฐํฌ ๋ฐ ํ์ฅ ๊ฐ๋ฅ
โ ํต์ ๋ฐฉ์ ์ ํ์ด ์ค์ (gRPC, Kafka, RabbitMQ ๋ฑ)
โ ์๋น์ค ๊ฐ ๋ฐ์ดํฐ ๋๊ธฐํ ๋ฐ ์ด๋ฒคํธ ๊ธฐ๋ฐ ์ค๊ณ ํ์
โ Kubernetes ๋ฐฐํฌ ์ ์๋น์ค ๊ฐ ๋คํธ์ํฌ ์ค์ ๊ณ ๋ ค ํ์
๐น ๊ฒฐ๋ก : NestJS์์ ๋ง์ดํฌ๋ก์๋น์ค ์ํคํ ์ฒ ์์ํ๊ธฐ
โ
NestJS๋ ๋ง์ดํฌ๋ก์๋น์ค๋ฅผ ์ฝ๊ฒ ๊ตฌ์ถํ ์ ์๋ ํ๋ ์์ํฌ
โ
TCP ๊ธฐ๋ฐ์ ๋ง์ดํฌ๋ก์๋น์ค๋ฅผ ์ค์ ํ๊ณ , API Gateway๋ฅผ ํตํด ์๋น์ค ํธ์ถ ๊ฐ๋ฅ
โ
Kafka, RabbitMQ, gRPC ๋ฑ ๋ค์ํ ํต์ ๋ฐฉ์ ์ ์ฉ ๊ฐ๋ฅ
โ
๋ค์ ๊ธ์์๋ NestJS ๋ง์ดํฌ๋ก์๋น์ค๋ฅผ Docker๋ก ์ปจํ
์ด๋ํํ์ฌ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ ๋ค๋ฃน๋๋ค! ๐
๐ ๋ค์ ๊ธ ์๊ณ : NestJS ๋ง์ดํฌ๋ก์๋น์ค ์ปจํ ์ด๋ํ ๋ฐ Docker ๋ฐฐํฌ
'study > ๋ฐฑ์๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
- Total
- Today
- Yesterday
- Webpack
- nodejs
- SEO ์ต์ ํ
- ํ๋ก ํธ์๋
- PostgreSQL
- Next.js
- Prisma
- kotlin
- rag
- llm
- ์น๊ฐ๋ฐ
- seo ์ต์ ํ 10๊ฐ
- REACT
- App Router
- SEO์ต์ ํ
- AI ์๋ํ
- CI/CD
- LangChain
- NestJS
- ๊ฐ๋ฐ๋ธ๋ก๊ทธ
- gatsbyjs
- AI์ฑ๋ด
- ๊ด๋ฆฌ์
- Ktor
- ์ค๋งํธ ์ปจํธ๋ํธ
- Docker
- fastapi
- nextJS
- ๋ฐฑ์๋๊ฐ๋ฐ
- github
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |