Service

호제로·2022년 9월 25일
0

Container

목록 보기
4/4

— Definition

  • 클러스터 내부에 생성된 POD를 외부와 통신하기 위해 지원되는 기능

  • Service 는 3가지의 종류로 분류됨
    - NodePort
    - 노드의 포트와 클러스터 내부 POD의 포트를 연결시켜, 외부 IP를 통해 내부 POD를 접근할 수 있게 하는 기능
    - TargetPort - POD 내부 포트
    - Port - 서비스 포트
    - NodePort - 외부에 공개되는 노드 포트

    		- Example Yaml
---
apiVersion: v1
kind: Service
metadata:
  name: webapp-service
spec:
  type: NodePort
  ports:
    - targetPort: 8080
      port: 8080
      nodePort: 30080
  selector:
    name: simple-webapp   # Label이 Deployments나 ReplicaSet에 정의된 Lable을 입력하면 연결된다. 
- ClusterIP
	- POD간 기능별로 묶어 여러 개의 POD를 하나의 서비스로 요청하여 처리할 수 있게끔 지원하는 서비스 
	- 아래 그림에서 Back-End, Redis 처럼 각 기능을 담당하는 POD를 하나로 묶어서 처리 



- LoadBalancer 
	- 여러 노드들을 하나의 로드밸런서로 묶어 지원하는 서비스 

— 서비스 관련 명령어

# 이미 존재하는 “redis” POD의 6379 포트에 ClusterIP 타입 형태의 서비스를 생성

— Expose 명령어를 통한 Service 생성 방법 
$ kubectl expose pod redis --port 6379 --name=redis-service --type=ClusterIP

— 서비스 조회

$ kubetcl get services

— Expose를 통한 서비스 배포

# 어떤 POD에 Service 연결하기
$ kubectl expose pod some-pod \
  --type=ClusterIP \
  --port=80 \
  --target-port=8000 \
  --dry-run=client -o yaml > some-pod-svc.yaml

$ kubectl expose pod messaging --name messaging-service --type=ClusterIP --port=6379 --dry-run=client -o yaml > servce.yaml

# 어떤 Deployment에 Service 연결하기
$ kubectl expose deployment some-deploy \
  --type=ClusterIP \
  --port=80 \
  --target-port=8000 \
  --dry-run=client -o yaml > some-deploy-svc.yaml
profile
Cloud Infra Structure & Developer

0개의 댓글