关于kubernetes pods dns解析问题
About kubernetes pods dns parsing problem
我的pod命名空间是kube-test,但是服务名是这个默认的
[root@kube01 iyunv]# kubectl get pods -n kube-test
NAME READY STATUS RESTARTS AGE
business-org-deployment-c84b7d9f6-55vpl 1/1 Running 0 21h
使用defaulc解析(业务-org.default.svc.cluster.local)
[root@kube01 iyunv]# kubectl exec business-org-deployment-c84b7d9f6-55vpl -n kube-apabi -it /bin/bash
[root@business-org-deployment-c84b7d9f6-55vpl /]# ping business-org.default.svc.cluster.local
PING business-org.default.svc.cluster.local (10.254.56.71) 56(84) bytes of data.
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=2 ttl=64 time=0.047 ms
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=3 ttl=64 time=0.049 ms
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=4 ttl=64 time=0.053 ms
无法使用kube-test解析(business-org.kube-test.svc.cluster.local)
[root@business-org-deployment-c84b7d9f6-55vpl /]# ping business-org.kube-test.svc.cluster.local
ping: business-org.kube-test.svc.cluster.local: Name or service not known
猫生意-org.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: business-org
name: business-org
spec:
ports:
- port: 9051
protocol: TCP
targetPort: 9051
selector:
app: business-org
type: ClusterIP
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: business-org-deployment
namespace: kube-test
spec:
replicas: 1
template:
metadata:
labels:
app: business-org
spec:
containers:
- name: business-org
image: harbor.test.com/test/business-org:201810251757_11f8bd9
ports:
- containerPort: 9051
这个
ping: business-org.kube-test.svc.cluster.local: Name or service not known
明确表示命名空间 kube-test
中没有服务 buisness-org
以下 YAML 将解决此问题:
apiVersion: v1
kind: Service
metadata:
namespace: kube-test <---
labels:
app: business-org
name: business-org
spec:
ports:
- port: 9051
protocol: TCP
targetPort: 9051
selector:
app: business-org
type: ClusterIP
我的pod命名空间是kube-test,但是服务名是这个默认的
[root@kube01 iyunv]# kubectl get pods -n kube-test
NAME READY STATUS RESTARTS AGE
business-org-deployment-c84b7d9f6-55vpl 1/1 Running 0 21h
使用defaulc解析(业务-org.default.svc.cluster.local)
[root@kube01 iyunv]# kubectl exec business-org-deployment-c84b7d9f6-55vpl -n kube-apabi -it /bin/bash
[root@business-org-deployment-c84b7d9f6-55vpl /]# ping business-org.default.svc.cluster.local
PING business-org.default.svc.cluster.local (10.254.56.71) 56(84) bytes of data.
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=2 ttl=64 time=0.047 ms
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=3 ttl=64 time=0.049 ms
64 bytes from business-org.default.svc.cluster.local (10.254.56.71): icmp_seq=4 ttl=64 time=0.053 ms
无法使用kube-test解析(business-org.kube-test.svc.cluster.local)
[root@business-org-deployment-c84b7d9f6-55vpl /]# ping business-org.kube-test.svc.cluster.local
ping: business-org.kube-test.svc.cluster.local: Name or service not known
猫生意-org.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: business-org
name: business-org
spec:
ports:
- port: 9051
protocol: TCP
targetPort: 9051
selector:
app: business-org
type: ClusterIP
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: business-org-deployment
namespace: kube-test
spec:
replicas: 1
template:
metadata:
labels:
app: business-org
spec:
containers:
- name: business-org
image: harbor.test.com/test/business-org:201810251757_11f8bd9
ports:
- containerPort: 9051
这个
ping: business-org.kube-test.svc.cluster.local: Name or service not known
明确表示命名空间 kube-test
buisness-org
以下 YAML 将解决此问题:
apiVersion: v1
kind: Service
metadata:
namespace: kube-test <---
labels:
app: business-org
name: business-org
spec:
ports:
- port: 9051
protocol: TCP
targetPort: 9051
selector:
app: business-org
type: ClusterIP