我的服务没有以dns作为主机名或任何我可以用来连接到它的名称

时间:2019-08-18 07:31:16

标签: kubernetes coredns

我在Kubernetes集群(ubuntu 16.04)上创建了一个服务(grpc-service),但找不到它的dns主机名

作为辅助节点,我的pod也不会显示在nslookup上(它与busybox一起使用)

 kubectl exec -ti server-pod -- nslookup kubernetes.default
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"nslookup\": executable file not found in $PATH": unknown

期望类似以下内容的东西

grpc-service.<namespace>.svc.<cluster-domain> which is usually
grpc-service.default.svc.cluster.local

但找不到它,也无法ping /卷曲 (curl -I grpc-service)

2 个答案:

答案 0 :(得分:0)

@Tanmay Shrivastava

clusterIP: None
However, you can use headless service,  use statefulset

apiVersion: v1
kind: Service
metadata:
  name: httpd-service
  labels:
    app: httpd
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: httpd

检查此链接:https://supergiant.io/blog/creating-stateful-apps-with-kubernetes-statefulsets/

答案 1 :(得分:0)

以下面为例。确保使用正确的标签/选择器。 并使用busybox版本<= busybox:1.28.4进行测试。使用较新版本的dns无法正常工作。


$client->request('GET', 'http://localhost:8001/api/tests')

检查:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-pod
  labels:
    app: busybox
spec:
  containers:
  - image: busybox:1.28.4
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: busybox
  restartPolicy: Always
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
spec:
  hostNetwork: true
  containers:
  - name: client-pod
    image: nginx        
---
apiVersion: v1
kind: Service
metadata:
  name: server
  labels:
    app: nginx
spec:
  clusterIP: None
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: nginx
---