Infra/k8s
[k8s] Next.js를 pod로 띄우기
개발자 쿠키
2025. 6. 8. 15:12
1. Next.js 프로젝트 만들기
환경 : VSCode
npx create-next-app
2. 프로젝트 실행
npm run dev
3. Dockerfile 작성
FROM node:20-alpine
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
EXPOSE 3000
ENTRYPOINT [ "npm", "run", "start" ]
package.json과 dockerfile이 같은 디렉토리에 있어야합니다.
4. .dockerignore 작성
node_modules
5. dockerfile 이미지 빌드
docker build -t next-server .
6. 이미지 생성 확인
docker image ls
7. 매니페스트 파일 작성
apiVersion: v1
kind: Pod
metadata:
name: next-pod
spec:
containers:
- name: next-container
image: next-server
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
8. 매니페스트 파일 기반 파드 생성
kubectl apply -f next-pod.yaml
9. 포트 포워딩 next.js 서버 실행 확인
kubectl port-forward next-pod 3000:3000

10. 파드 삭제
kubectl delete pod next-pod