Headless 服务上的 DNS 查找没有 return 任何 IP 地址
DNS lookup on Headless service doesn't return any IP addresses
我正在使用 minikube 和 VirtualBox 在 Kubernetes 中运行集群。
这是我的无头服务
apiVersion: v1
kind: Service
metadata:
labels:
service: test
name: test-group-ping
spec:
clusterIP: None
ports:
- port: 4444
name: ping
protocol: TCP
targetPort: 4444
selector:
service: test
sessionAffinity: None
type: ClusterIP
我就是这样部署 pods
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
app: test
spec:
replicas: 3
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: image
env:
- name: KC_PROXY
value: "edge"
- name: PROXY_ADDRESS_FORWARDING
value: "true"
ports:
- containerPort: 8080
- containerPort: 4444
- containerPort: 8888
readinessProbe:
httpGet:
path: "/test"
port: 8080
initialDelaySeconds: 600
periodSeconds: 30
我有另一个用于 pods
的负载均衡器
当我使用 kubectl get services
时,我得到 test-group-ping
作为无头服务
test-group-ping ClusterIP None <none> 4444/TCP 8h
kubectl describe service test-group-ping
Name: test-group-ping
Namespace: default
Labels: service=test
Annotations: <none>
Selector: service=test
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: None
IPs: None
Port: ping 4444/TCP
TargetPort: 4444/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
我需要此无头服务的 DNS 查询
我尝试了 test-group-ping.default.svc.cluster.local
,但是当我尝试对此进行 DNS 查找时,它 return 没有任何 pod 的 IP 地址
% dig +search test-group-ping.default.svc.cluster.local
; <<>> DiG 9.10.6 <<>> +search test-group-ping.default.svc.cluster.local
;; 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: NXDOMAIN, id: 8544
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;test-group-ping.default.svc.cluster.local. IN A
;; AUTHORITY SECTION:
. 10800 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2022032100 1800 900 604800 86400
;; Query time: 140 msec
;; SERVER: 2600:1702:8c0:e100::1#53(2600:1702:8c0:e100::1)
;; WHEN: Mon Mar 21 10:33:50 CDT 2022
;; MSG SIZE rcvd: 151
;; Query time: 140 msec
;; SERVER: 2600:1702:8c0:e100::1#53(2600:1702:8c0:e100::1)
;; WHEN: Mon Mar 21 10:33:50 CDT 2022
;; MSG SIZE rcvd: 151
您的服务选择器 service: test
与 Pod 标签 app: test
不匹配。
我正在使用 minikube 和 VirtualBox 在 Kubernetes 中运行集群。
这是我的无头服务
apiVersion: v1
kind: Service
metadata:
labels:
service: test
name: test-group-ping
spec:
clusterIP: None
ports:
- port: 4444
name: ping
protocol: TCP
targetPort: 4444
selector:
service: test
sessionAffinity: None
type: ClusterIP
我就是这样部署 pods
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
app: test
spec:
replicas: 3
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: image
env:
- name: KC_PROXY
value: "edge"
- name: PROXY_ADDRESS_FORWARDING
value: "true"
ports:
- containerPort: 8080
- containerPort: 4444
- containerPort: 8888
readinessProbe:
httpGet:
path: "/test"
port: 8080
initialDelaySeconds: 600
periodSeconds: 30
我有另一个用于 pods
的负载均衡器当我使用 kubectl get services
时,我得到 test-group-ping
作为无头服务
test-group-ping ClusterIP None <none> 4444/TCP 8h
kubectl describe service test-group-ping
Name: test-group-ping
Namespace: default
Labels: service=test
Annotations: <none>
Selector: service=test
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: None
IPs: None
Port: ping 4444/TCP
TargetPort: 4444/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
我需要此无头服务的 DNS 查询
我尝试了 test-group-ping.default.svc.cluster.local
,但是当我尝试对此进行 DNS 查找时,它 return 没有任何 pod 的 IP 地址
% dig +search test-group-ping.default.svc.cluster.local
; <<>> DiG 9.10.6 <<>> +search test-group-ping.default.svc.cluster.local
;; 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: NXDOMAIN, id: 8544
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;test-group-ping.default.svc.cluster.local. IN A
;; AUTHORITY SECTION:
. 10800 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2022032100 1800 900 604800 86400
;; Query time: 140 msec
;; SERVER: 2600:1702:8c0:e100::1#53(2600:1702:8c0:e100::1)
;; WHEN: Mon Mar 21 10:33:50 CDT 2022
;; MSG SIZE rcvd: 151
;; Query time: 140 msec
;; SERVER: 2600:1702:8c0:e100::1#53(2600:1702:8c0:e100::1)
;; WHEN: Mon Mar 21 10:33:50 CDT 2022
;; MSG SIZE rcvd: 151
您的服务选择器 service: test
与 Pod 标签 app: test
不匹配。