매니페스트 예시
apiVersion: v1
kind: Service
metadata:
name: sample-externalname
namespace: default
spec:
type: ExternalName
externalName: external.example.com
생성 후 서비스 확인
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
sample-externalname ExternalName <none> external.example.com <none> 6s
컨테이너 내부에서는 ‘서비스명
’이나 ‘서비스명.네임스페이스명.svc.cluster.local
’로 정방향 질의를 하면 CNAME이 반환된다.
kubectl run --image=amsy810/tools:v2.0 --restart=Never --rm -i testpod --command -- dig sample-externalname.default.svc.cluster.local CNAME
<<>> DiG 9.16.1-Ubuntu <<>> sample-externalname.default.svc.cluster.local CNAME
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52956
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 377d457e6acfbb3c (echoed)
;; QUESTION SECTION:
;sample-externalname.default.svc.cluster.local. IN CNAME
;; ANSWER SECTION:
sample-externalname.default.svc.cluster.local. 5 IN CNAME external.example.com.
;; Query time: 0 msec
;; SERVER: 169.254.25.10#53(169.254.25.10)
;; WHEN: Mon Jan 16 04:31:12 UTC 2023
;; MSG SIZE rcvd: 165
spec.clusterIP
를 명시적으로 공란으로 만들어 두어야 한다.