애플리케이션 노출법
배포한 애플리케이션을 노출하는 방법
- 간단한 방법
- port-forward
- HostPort
- hostNetwork
- NodePort
- LoadBalancer
- ExternalName
- ClusterIP, Headless
- Endpoints
- Ingress
간단한 방법(port-forward, HostPort, hostNetwork)
포트 포워딩
- 호스트 PC에서 가상 머신으로 접속 시 포트 포워딩 사용

port-forward 옵션

k port-forward fwd-chk-hn 80:80
: 마스터 노드의 80번 포트를 fwd-chk-hn
노드의 80번 포트로 포워딩- 노드가 재시작될 경우 포트 포워딩이 사라짐
HostPort

containerPort
: 파드의 포트hostPort
: 노드의 포트- 노드의 IP와 포트를 알고 있어야 하므로 실용적이지 않음
HostNetwork

- eth0을 그대로 쓸 수 있게 해주는 기능
- 클러스터의 노드에 직접 접속하므로 실용적이지 않음
노드포트(NodePort)
nodeport.yaml

selector
: 노출할 오브젝트nodePort
: 노드 포트, 미입력시 랜덤으로 지정port
: 서비스 포트targetPort
: 파드 포트
Overview

- 사용자가 워커 노드의 NodePort 서비스 포트로 접속
- 연결을 NodePort 서비스로 보내줌
- NodePort는 워커 노드의 파드로 연결을 보냄
로드밸런서(LoadBalancer)
loadbalancer-11.yaml

port
: 서비스 포트targetPort
: 파드 포트- Metallb로 접근
loadbalancer-12.yaml

Overview

- 사용자는
ConfigMap
을 통하여 EXT IP로 접속 - 내부의 파드로 연결됨
외부이름(ExternalName)
externalname-1.yaml

externalname-2.yaml

Overview

- 컨테이너 내부에서 외부 도메인을 aliasing 하는 데에 사용
클러스터주소(ClusterIP)와 헤드리스(Headless)
clusterip.yaml

headless.yaml

- 클러스터 IP를
None
으로 지정하면 Headless
가 됨
클러스터주소와 헤드리스 비교
- 헤드리스를 사용할 경우 IP 주소를 소진하지 않고 스테이트풀셋을 연결할 수 있음
- 스테이트풀셋 각각의 파드는 고정된 이름을 갖고 각각의 목적을 갖고 있도록 설계할 수 있음
NodePort
나 LoadBalancer
를 사용할 경우 각각의 파드에 대한 접속을 통제하기 어려움- 따라서 헤드리스를 사용하여 스테이트풀셋에 대한 연결을 관리
sts-svc-domain-headless.yaml

nslookup sts-chk-hn-0.sts-svc.domain
nslookup sts-chk-hn-1.sts-svc.domain
nslookup sts-chk-hn-2.sts-svc.domain
- 위와 같은 명령어로 스테이트풀셋 내 각각의 노드에 서비스 이름으로 접근 가능
serviceName
을 통하여 노드와 헤드리스가 결합됨LoadBalancer
로 노출은 가능하나 스테이트풀셋의 목적에 부합하지 않으므로 자주 사용하지는 않음
엔드포인트(Endpoints)
loadbalancer.yaml의 엔드포인트

- 파드의 개수만큼 엔드포인트가 자동으로 생성됨
- 외부에 노출된 서비스를 통하여 도달하는 파드의 IP를 일컬음
service-endpoints.yaml

metadata.name
을 클러스터와 일치시켜 수동으로 엔드포인트 생성- 위와 같이 로드밸런서의 IP를 엔드포인트로 지정할 경우 로드밸런서를 거쳐 최종적으로 파드에 도달
인그레스(Ingress)
NodePort와 인그레스

- 사용자가 워커 노드의 포트로 접근
- NodePort 서비스로 이동
- 접속 경로에 따라 해당하는 파드로 이동
LoadBalancer와 인그레스

- 사용자가 로드밸런서 서비스에 접근
- 접속 경로에 따라 서비스로 이동
- 각각의 서비스의 엔드포인트로 이동
ingress.yaml

레이블(labels)과 애너테이션(annotations)의 차이

Labels
: 관리자, 개발자가 인식하는 부가 정보Annotation
: 시스템이 인식하는 부가 정보
각 타입별 ingress controller 설정의 차이

NodePort
의 경우 무작위로 지정되나 실습의 편의를 위해 spec 수정LoadBalancer
는 포트를 지정할 필요 없음