我想在我的EKS Kubernetes集群v1.10.3上运行dns pod名称解析。我的理解是创建一个无头服务将创建我需要的必要的pod名称记录,但我发现这不是真的。我错过了什么吗?
还有其他关于如何使其工作的想法。找不到替代解决方案。
我不是很清楚。基本上我需要的是如此解决:worker-767cd94c5c-c5bq7 - > 10.0.10.10 worker-98dcd94c5d-cabq6 - > 10.0.10.11等等....
我真的不需要循环DNS只是在某处阅读这可能是一个解决方案。谢谢!
# my service
apiVersion: v1
kind: Service
metadata:
...
name: worker
namespace: airflow-dev
resourceVersion: "374341"
selfLink: /api/v1/namespaces/airflow-dev/services/worker
uid: 814251ac-acbe-11e8-995f-024f412c6390
spec:
clusterIP: None
ports:
- name: worker
port: 8793
protocol: TCP
targetPort: 8793
selector:
app: airflow
tier: worker
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
# my pod
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: 2018-08-31T01:39:37Z
generateName: worker-69887d5d59-
labels:
app: airflow
pod-template-hash: "2544381815"
tier: worker
name: worker-69887d5d59-6b6fc
namespace: airflow-dev
ownerReferences:
- apiVersion: extensions/v1beta1
blockOwnerDeletion: true
controller: true
kind: ReplicaSet
name: worker-69887d5d59
uid: 16019507-ac6b-11e8-995f-024f412c6390
resourceVersion: "372954"
selfLink: /api/v1/namespaces/airflow-dev/pods/worker-69887d5d59-6b6fc
uid: b8d82a6b-acbe-11e8-995f-024f412c6390
spec:
containers:
...
...
name: worker
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
...
...
dnsPolicy: ClusterFirst
nodeName: ip-10-0-1-226.us-west-2.compute.internal
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: airflow
serviceAccountName: airflow
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
...
...
status:
conditions:
- lastProbeTime: null
lastTransitionTime: 2018-08-31T01:39:37Z
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: 2018-08-31T01:39:40Z
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: 2018-08-31T01:39:37Z
status: "True"
type: PodScheduled
containerStatuses:
...
...
lastState: {}
name: worker
ready: true
restartCount: 0
state:
running:
startedAt: 2018-08-31T01:39:39Z
hostIP: 10.0.1.226
phase: Running
podIP: 10.0.1.234
qosClass: BestEffort
startTime: 2018-08-31T01:39:37Z
# querying the service dns record works!
airflow@worker-69887d5d59-6b6fc:~$ nslookup worker.airflow-dev.svc.cluster.local
Server: 172.20.0.10
Address: 172.20.0.10#53
Name: worker.airflow-dev.svc.cluster.local
Address: 10.0.1.234
# querying the pod name does not work :(
airflow@worker-69887d5d59-6b6fc:~$ nslookup worker-69887d5d59-6b6fc.airflow-dev.svc.cluster.local
Server: 172.20.0.10
Address: 172.20.0.10#53
** server can't find worker-69887d5d59-6b6fc.airflow-dev.svc.cluster.local: NXDOMAIN
airflow@worker-69887d5d59-6b6fc:~$ nslookup worker-69887d5d59-6b6fc.airflow-dev.pod.cluster.local
Server: 172.20.0.10
Address: 172.20.0.10#53
*** Can't find worker-69887d5d59-6b6fc.airflow-dev.pod.cluster.local: No answer
在内部,我建议使用服务DNS记录指向已确认可用的窗格。这当然不要求您使用Headless服务来使用服务DNS。
kube-dns自动记录以下列方式工作:
pod - >在同一命名空间中的服务:curl http://servicename
pod - >不同命名空间中的服务:curl http://servicename.namespace
在此处阅读有关服务发现的更多信息:https://kubernetes.io/docs/concepts/services-networking/service/#environment-variables
您可以在这里阅读有关服务的DNS记录的更多信息https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services
如果您需要外部自定义名称解析,我建议使用nginx-ingress:
https://github.com/helm/charts/tree/master/stable/nginx-ingress https://github.com/kubernetes/ingress-nginx