my pod namespace is kube-test,But the service name is this default
[root@kube01 iyunv]# kubectl get pods -n kube-test
NAME READY STATUS RESTARTS AGE
business-org-deployment-c84b7d9f6-55vpl 1/1 Running 0 21h
Use defaulc to parse ( business-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
Cannot be parsed using 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
cat business-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
This
ping: business-org.kube-test.svc.cluster.local: Name or service not known
unambiguously signaled there's no service buisness-org
in the namespace kube-test
following YAML will fix this:
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