728x90
1. 서비스 배포
## docker 파일 작성
$ vi Dockerfile
# 1. Node.js 베이스 이미지를 사용 (최신 LTS 버전)
FROM node:18
# 2. 작업 디렉토리 생성
WORKDIR /app
# 3. 애플리케이션 코드 복사
COPY app.js .
# 4. 애플리케이션 실행에 필요한 명령어 설정
CMD ["node", "app.js"]
# 5. 컨테이너가 사용하는 포트 노출
EXPOSE 3000
## docker 이미지 빌드 및 푸쉬
$ docker build -t hello-world-app .
$ docker images
$ docker run -d -p 3000:3000 hello-world-app
$ docker login
$ docker tag hello-world-app jinnidevi/hello-world-app
$ docker push jinnidevi/hello-world-app
## deployment 생성
$ vi hello-world-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-deployment
spec:
replicas: 2 # 실행할 파드 수
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: jinnidevi/hello-world-app:latest
ports:
- containerPort: 3000
$ kubectl apply -f hello-world-deployment.yaml
## service 파일 생성
$ vi hello-world-service.yaml
apiVersion: v1
kind: Service
metadata:
name: hello-world-service
spec:
selector:
app: hello-world
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer # 외부 접근 가능하도록 LoadBalancer 설정
$ kubectl apply -f hello-world-service.yaml
## ingress 생성
$ vi hello-world-ingress.yaml
apiVersion: networking.k9s.io/v1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: hello-world.local # 원하는 도메인 이름
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world-service
port:
number: 80
$ kubectl apply -f hello-world-ingress.yaml
2. hosts 파일 수정
## Ingress NGINX controller running중인 VM 확인
$ kubectl get pod -o wide --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ingress-nginx my-nginx-ingress-nginx-controller-5476b4bdf-mlp4g 1/1 Running 0 5d14h 10.88.38.206 jy-vm3 <none> <none>
## PC hosts 파일 수정
C:\Windows\System32\drivers\etc\hosts
x.x.x.3 hello-world.local
x.x.x.3: [running중인 VM 공인IP]
3. 서비스 확인 방법
(1) ClusterIP 타입
(2) NodePort 타입
(3) LoadBalancer 타입
728x90
반응형
'데브옵스 > Orchestration' 카테고리의 다른 글
[Kubernetes] 7. ReplicationController, ReplicaSet (0) | 2024.11.05 |
---|---|
[Kubernetes] 6. 쿠버네티스 아키텍처와 yaml 파일 (0) | 2024.11.04 |
[Kubernetes] 4. 서비스 배포 환경 구성 - HELM, Ingress NGINX, metalLB 설치 (1) | 2024.10.31 |
[Kubernetes] 3. 도커 및 쿠버네티스 설치, 클러스터 구성 (0) | 2024.10.31 |
[Kubernetes] 2. 클러스터 구성 환경 준비 (0) | 2024.10.31 |