1. Kubernetes Service 구현
- Pod network : CNI(Container Network Interface)에서 관리하는 포트 간 통신에 사용되는 클러스터 전체 네트워크
- Service Network : Service discovery를 위해 kube-proxy가 관리하는 Cluster-wide 범위의 Virtual IP

2. Kube-proxy
- Kubernetes Network Proxy
- 각각의 Node에서 실행되고, Kubernetes Service API에 정의된 서비스를 각 노드에서 반영
- kube-proxy 역할 : iptables rule을 설정하고 외부 네트워크와 Pod를 연결시킨다.

3. Service Type
- ClusterIP(default) : Pod 그룹(동일한 서비스를 지원하는 Pod 모음)의 단일 진입점(Virtual IP:LB)생성
- NodePort : ClusterIP가 생성된 후 모든 Worker Node에 외부에서 접속 가능한 포트가 예약
- LoadBalancer : 클라우드 인프라스트럭처(AWS, Azure, GCP)에 적용, LoadBalancer를 자동으로 프로 비전하는 기능 지원
4. ClusterIP
- selector의 label이 동일한 Pod들을 그룹으로 묶어 단일 진입점(Virtual_IP)을 생성
- 클러스터 내부에서만 사용 가능
- Service type 생략 시 default로 설정
- 10.96.0.0/12 범위에서 할당됨
5. ClusterIP 서비스 운영
- LAB : 동일한 서비스를 제공하는 Pod 그룹에 ClusterIP 생성
- deployment name: web, image: nginx, port: 80, replicas: 2
- service name: web, type: clusterIP, port: 80
-
deployment 생성

-
deployment 생성 확인

- service 생성 및 확인

- worker노드 중 하나로 접속하여 CLUSTER-IP로 요청 및 확인(deployment 확인 시 생성되었던 pod 2개 중 하나가 요청에 응답함)

※ 문제1 : ClusterIP type의 서비스 운영
- 작업 클러스터 : k8s
- 'devops' namespace에서 운영되고 있는 eshop-order deployment의 Service를 만드세요.
- Service Name: eshop-order-svc
- Type: ClusterIP
- Port : 80
- 작업 클러스터 확인

- 이름이 devops인 namespace가 동작중인지 확인

- 이름이 devops인 namespace에 타입이 ClusterIP이고, port가 80이고, targetPort가 80인 이름이 eshop-order-svc인 Service를 yaml 형태로 출력하여 실제로 동작 가능한지 확인

- 이름이 eshop-order-svc인 Service 생성 및 확인

- worker노드 중 하나에 접속하여 Endpoint의 IP에 요청하여 확인(정상적으로 Service 생성)

※ 문제2 : Pod를 이용한 Named Service 구성
(참고 URL : https://kubernetes.io/ko/docs/concepts/services-networking/service/#nodeport)
- 작업 클러스터 : k8s
- 미리 배포한 'front-end'에 기존의 nginx 컨테이너의 포트 '80/tcp'를 expose하는 'http'라는 이름을 추가합니다.
- 컨테이너 포트 http를 expose하는 'front-end-svc'라는 새 service를 만듭니다.
- 또한 준비된 node의 'NodePort'를 통해 개별 Pods를 expose되도록 Service를 구성합니다.
- 작업 클러스터 확인

- 기존에 배포되었던 이름이 front-end인 deployment를 yaml 파일로 생성하여 vi 에디터로 편집 실행

- Service 추가하여 yaml 파일 수정 및 저장

- 만들었던 yaml 파일 apply 및 pod 및 service 생성 확인

- 준비된 node의 'NodePort'를 통해 개별 Pods를 expose되도록 Service를 구성해야 하므로 Service 편집 명령어 실행

- Service 편집에서 type을 'NodePort'로 수정 후 저장

- Service 조회 시 type이 NodePort로 바뀐 것을 확인

- type이 NodePort 이므로 console에서 생성된 포트로 요청 시 응답이 제대로 오는 것을 확인
