일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 클라우드 국비지원교육
- keda
- HPA
- Jenkins
- POD
- AWS
- k8s
- EKS
- observability
- VPA
- aews ci/cd
- 클라우드 국비지원교육 후기
- 합격 후기
- aews
- karpenter
- Terraform
- 클라우드 엔지니어
- CAS
- Python
- kubernetes
- 외부 모듈
- docker
- storageclass
- 공부 방법
- eks endpoint access
- volume
- 도커
- 단기 합격
- 국비지원교육
- aews vault
- Today
- Total
모험가
Service - Headless, Endpoint, ExternalName 본문
이 글은 인프런의 대세는 쿠버네티스 강의를 보며 정리한 글입니다.
Headless
- 보통 DNS에서 볼때 이름들이 Pod, Service들은 긴 도메인 이름과 IP가 저장됨
- 이를 Service는 사용자가 이름을 만드는거니까 Pod에 직접 저장해놓을 수 있음
But
Pod의 경우 계속 IP도 바뀌고 이름이 너무 복잡하므로 직접연결하려면
- Service의 clusterIP : None 을 해주면 해결됨
- Pod4와 Pod5의 hostname을 넣어주고 (pod4, pod5) subdomain에 headless1을 넣음
- 그러면 Service의 IP가 없으므로 모든 Pod의 IP를 넘겨줌
- 그래서 미리 할당된 pod4.headless1.default.svc.cluster.local을 활용 가능함
- 이러한 것들을 Pod에 미리 저장해두면 쉽게 연결이 가능함(IP의 재변동과 상관없이)
Endpoint
서비스와 파드를 직접 연결하는 것
- Service와 Pod를 만들 때, Endpoint를 직접 만들면 됨
- Service의 이름과 Pod의 IP 정보를 넣으면 됨.
이러면 IP가 계속 바뀔 수 있으므로 ExternalName이라는 속성을 이용하는 것
ExternalName
- Service에 ExternalName을 넣어 도메인을 넣으면 DNS cache을 통해 IP를 찾아냄
- Pod는 service만 가리키고 있으면 Service는 필요할때마다 도메인 주소를 변경할 수 있어서 접속할 곳이 변경되더라도
Pod를 수정하고 재배포를 안해도 됨.
실습
Headless
1-1) Service
apiVersion: v1
kind: Service
metadata:
name: clusterip1
spec:
selector:
svc: clusterip
ports:
- port: 80
targetPort: 8080
1-2) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod1
labels:
svc: clusterip
spec:
containers:
- name: container
image: kubetm/app
1-3) Request Pod
apiVersion: v1
kind: Pod
metadata:
name: request-pod
spec:
containers:
- name: container
image: kubetm/init
kubectl exec request-pod -it /bin/bash
nslookup
nslookup clusterip1
nslookup clusterip1.default.svc.cluster.local
curl
curl clusterip1/hostname
curl clusterip1.default.svc.cluster.local/hostname
2-1) Service
apiVersion: v1
kind: Service
metadata:
name: headless1
spec:
selector:
svc: headless
ports:
- port: 80
targetPort: 8080
clusterIP: None
2-2) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod4
labels:
svc: headless
spec:
hostname: pod-a
subdomain: headless1
containers:
- name: container
image: kubetm/app
Nslookup
nslookup headless1
nslookup pod-a.headless1
nslookup pod-b.headless1
Curl
curl pod-a.headless1:8080/hostname
curl pod-b.headless1:8080/hostname
Endpoint
3-1) Service
apiVersion: v1
kind: Service
metadata:
name: endpoint1
spec:
selector:
svc: endpoint
ports:
- port: 8080
3-2) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod7
labels:
svc: endpoint
spec:
containers:
- name: container
image: kubetm/app
kubectl describe endpoints endpoint1
4-1) Service
apiVersion: v1
kind: Service
metadata:
name: endpoint2
spec:
ports:
- port: 8080
4-2) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod9
spec:
containers:
- name: container
image: kubetm/app
4-3) Endpoint
apiVersion: v1
kind: Endpoints
metadata:
name: endpoint2
subsets:
- addresses:
- ip: 20.109.5.12
ports:
- port: 8080
curl endpoint2:8080/hostname
5-1) Service
apiVersion: v1
kind: Service
metadata:
name: endpoint3
spec:
ports:
- port: 80
Github - Ip Address
nslookup https://www.github.com
curl -O 185.199.110.153:80/kubetm/kubetm.github.io/blob/master/sample/practice/intermediate/service-sample.md
5-2) Endpoint
apiVersion: v1
kind: Endpoints
metadata:
name: endpoint3
subsets:
- addresses:
- ip: 185.199.110.153
ports:
- port: 80
curl -O endpoint3/kubetm/kubetm.github.io/blob/master/sample/practice/intermediate/service-sample.md
ExternalName
6-1) Service
apiVersion: v1
kind: Service
metadata:
name: externalname1
spec:
type: ExternalName
externalName: github.github.io
curl -O externalname1/kubetm/kubetm.github.io/blob/master/sample/practice/intermediate/service-sample.md
yaml
Service
apiVersion: v1
kind: Service
metadata:
name: headless1
spec:
selector: # 생략시 Endpoints 직접 생성해서 사용
svc: headless
ports:
- port: 80
targetPort: 8080
clusterIP: None # headless 서비스
type: ExternalName # ExternalName Service 설정시 사용
externalName: github.github.io # ExternalName사용시 연결 Domain지정
Endpoints
apiVersion: v1
kind: Endpoints
metadata:
name: headless1 # Service의 이름과 동일하게 지정
subsets:
- addresses:
- ip: 20.109.5.12 # Pod의 ClusterIp
ports:
- port: 8080 # Pod의 Container Port
Pod
apiVersion: v1
kind: Pod
metadata:
name: pod4
labels:
svc: headless
spec:
hostname: pod-a # 호스트네임 설정, 생략시 Pod Name이 적용됨
subdomain: headless1 # headless 서비스 사용시 Service의 이름으로 지정
containers:
- name: container
image: kubetm/app
kubectl
Exec
# Pod이름이 request-pod인 Container로 들어가기 (나올땐 exit)
kubectl exec request-pod -it /bin/bash
Describe
# Endpoints 상세보기
kubectl describe endpoints endpoint1
'쿠버네티스 > 중급' 카테고리의 다른 글
Volume - Dynamic Provisioning, StorageClass, Status, ReclaimPolicy (0) | 2022.08.10 |
---|---|
Pod - QoS Classes, Node Scheduling (0) | 2022.08.08 |
Pod - Lifecycle, Probe (0) | 2022.08.08 |