인프라/시스템 구축

[ service ] Type ExternalName

김붕어87 2023. 6. 29. 18:27
반응형

 

[ Service의 Type ]
  • ClusterIP
    • EKS Cluster IP할당, 내부 통신
  • NodePort
    • 워커노드에 외부에서 접근할 수 있는 Port를 할당
    • 워커노드 Port를 통해서 외부에서 접근 가능
    • 워커노드 port으로 접근하면 Pod으로 Redirection
  • LoadBalancer
    • 외부에서 ELB을 통해서 접근 가능
    • ELB으로 접근하면 Pod으로 Redirection
  • ExternalName
    • 외부의 특정 FQDN에 대한 CNAME 매핑
    • Pod가 ExternalName에 지정된 CNAME을 통해서 FQDN에 접근



 

 

ExternalName

  • ExternalName은 외부에서 Pod으로 접근하기 위한 셋팅이 아님
  • Pod들이 ExternalName(SVC)을 이용해서 외부 FQDN에 접근 용도

 

Service.yaml 생성

  • Type: ExternalName 생성
# yaml 생성
vi service.yaml

apiVersion: v1
kind: Service
metadata:
  name: test-externalname
spec:
  type: ExternalName
  externalName: www.google.com
  
# 배포
kubectl apply -f service.yaml

 

 

 

Service 생성 확인

kubectl get all

NAME                        TYPE           CLUSTER-IP   EXTERNAL-IP      PORT(S)   AGE
service/test-externalname   ExternalName   <none>       www.google.com   <none>    10s

 

 

Pod 생성

vi pod.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: php-apache1
spec:
  selector:
    matchLabels:
      run: php-apache1
  replicas: 1
  template:
    metadata:
      labels:
        run: php-apache1
    spec:
      containers:
      - name: php-apache1
        image: registry.k8s.io/hpa-example
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: http
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 1
        ports:
        - containerPort: 80
        
kubectl apply -f pod.yaml

 

 

 

 

 

 

 

테스트

1. pod 접속

kubectl get pod
NAME                           READY   STATUS    RESTARTS   AGE
php-apache1-6b968447dd-w22wx   1/1     Running   0          4m25s

kubectl exec pod/php-apache1-6b968447dd-w22wx -it /bin/bash

 

 

2. nslookup 명령어 설치

apt-get update
apt-get install dnsutils

 

 

3. nslookup & ping 테스트
- test-externalname은 방금 생성한 SVC 이름

# ExternalName 정보
nslookup test-externalname
Server:		172.20.0.10
Address:	172.20.0.10#53

test-externalname.dw.svc.cluster.local	canonical name = www.google.com.
Name:	www.google.com
Address: 142.250.4.103
Name:	www.google.com
Address: 142.250.4.104
Name:	www.google.com
Address: 142.250.4.105
Name:	www.google.com
Address: 142.250.4.147
Name:	www.google.com
Address: 142.250.4.106
Name:	www.google.com
Address: 142.250.4.99


# www.google.com 정보
nslookup www.google.com
Server:		172.20.0.10
Address:	172.20.0.10#53

Non-authoritative answer:
Name:	www.google.com
Address: 142.250.4.103
Name:	www.google.com
Address: 142.250.4.147
Name:	www.google.com
Address: 142.250.4.105
Name:	www.google.com
Address: 142.250.4.106
Name:	www.google.com
Address: 142.250.4.99
Name:	www.google.com
Address: 142.250.4.104

# ping 테스트
ping -c 5 test-externalname
PING www.google.com (142.250.4.147): 56 data bytes
64 bytes from 142.250.4.147: icmp_seq=0 ttl=49 time=1.989 ms
64 bytes from 142.250.4.147: icmp_seq=1 ttl=49 time=1.603 ms
64 bytes from 142.250.4.147: icmp_seq=2 ttl=49 time=1.576 ms
64 bytes from 142.250.4.147: icmp_seq=3 ttl=49 time=1.562 ms
64 bytes from 142.250.4.147: icmp_seq=4 ttl=49 time=1.574 ms
--- www.google.com ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.562/1.661/1.989/0.165 ms

 

반응형