Kubernetes PetSet DNS 不工作
Kubernetes PetSet DNS not working
我有一个 Kubernetes PetSet,名称 == elasticsearch
和 serviceName == es
。它确实创建了 pods,并且正如预期的那样,它们的名称如 elasticsearch-0
和 elasticsearch-1
。但是,DNS 似乎不起作用。 elasticsearch-0.es
不解析(elasticsearch-0.default
也不解析,等等)。如果您查看生成的 srv 记录,它们似乎是随机的而不是可预测的:
# nslookup -type=srv elasticsearch
Server: 10.1.0.2
Address: 10.1.0.2#53
elasticsearch.default.svc.cluster.local service = 10 100 0 9627d60e.elasticsearch.default.svc.cluster.local.
有人有什么想法吗?
详情
这是实际的 PetSet 和服务定义:
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
app: elasticsearch
spec:
ports:
- name: rest
port: 9200
- name: native
port: 9300
clusterIP: None
selector:
app: elasticsearch
---
apiVersion: apps/v1alpha1
kind: PetSet
metadata:
name: elasticsearch
spec:
serviceName: "es"
replicas: 2
template:
metadata:
labels:
app: elasticsearch
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
terminationGracePeriodSeconds: 0
containers:
- name: elasticsearch
image: 672129611065.dkr.ecr.us-west-2.amazonaws.com/elasticsearch:v1
ports:
- containerPort: 9200
- containerPort: 9300
volumeMounts:
- name: es-data
mountPath: /usr/share/elasticsearch/data
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ES_CLUSTER_NAME
value: EsEvents
volumeClaimTemplates:
- metadata:
name: es-data
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
这是我误读文档的问题。 The docs 说:
The network identity has 2 parts. First, we created a headless Service that controls the domain within which we create Pets. The domain managed by this Service takes the form: $(service name).$(namespace).svc.cluster.local, where “cluster.local” is the cluster domain. As each pet is created, it gets a matching DNS subdomain, taking the form: $(petname).$(governing service domain), where the governing service is defined by the serviceName field on the Pet Set.
我的意思是serviceDomain
字段的值是"governing service domain"的值,但不是这个意思。这意味着 serviceDomain
的值必须与现有无头服务的名称相匹配,并且该服务将用作管理服务域。如果不存在此类服务,您不会收到错误 - 您只是为您的宠物获取随机 DNS 名称。
我有一个 Kubernetes PetSet,名称 == elasticsearch
和 serviceName == es
。它确实创建了 pods,并且正如预期的那样,它们的名称如 elasticsearch-0
和 elasticsearch-1
。但是,DNS 似乎不起作用。 elasticsearch-0.es
不解析(elasticsearch-0.default
也不解析,等等)。如果您查看生成的 srv 记录,它们似乎是随机的而不是可预测的:
# nslookup -type=srv elasticsearch
Server: 10.1.0.2
Address: 10.1.0.2#53
elasticsearch.default.svc.cluster.local service = 10 100 0 9627d60e.elasticsearch.default.svc.cluster.local.
有人有什么想法吗?
详情
这是实际的 PetSet 和服务定义:
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
app: elasticsearch
spec:
ports:
- name: rest
port: 9200
- name: native
port: 9300
clusterIP: None
selector:
app: elasticsearch
---
apiVersion: apps/v1alpha1
kind: PetSet
metadata:
name: elasticsearch
spec:
serviceName: "es"
replicas: 2
template:
metadata:
labels:
app: elasticsearch
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
terminationGracePeriodSeconds: 0
containers:
- name: elasticsearch
image: 672129611065.dkr.ecr.us-west-2.amazonaws.com/elasticsearch:v1
ports:
- containerPort: 9200
- containerPort: 9300
volumeMounts:
- name: es-data
mountPath: /usr/share/elasticsearch/data
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ES_CLUSTER_NAME
value: EsEvents
volumeClaimTemplates:
- metadata:
name: es-data
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
这是我误读文档的问题。 The docs 说:
The network identity has 2 parts. First, we created a headless Service that controls the domain within which we create Pets. The domain managed by this Service takes the form: $(service name).$(namespace).svc.cluster.local, where “cluster.local” is the cluster domain. As each pet is created, it gets a matching DNS subdomain, taking the form: $(petname).$(governing service domain), where the governing service is defined by the serviceName field on the Pet Set.
我的意思是serviceDomain
字段的值是"governing service domain"的值,但不是这个意思。这意味着 serviceDomain
的值必须与现有无头服务的名称相匹配,并且该服务将用作管理服务域。如果不存在此类服务,您不会收到错误 - 您只是为您的宠物获取随机 DNS 名称。