好的,按照Kubernetes网站上的示例和文档以及对Google的广泛研究,我仍然无法在我的Pod中的容器之间获得DNS解析。
我有一个Service和一个定义了2个容器的PetSet。当我部署PetSet和Service时,它们会成功启动并运行,但是如果我尝试通过主机名或完整域名从另一个容器中ping我的一个容器的主机,那么我将无法访问目标。我可以通过IP地址ping。
这是我的Kubernetes配置文件:
apiVersion: v1
kind: Service
metadata:
name: ml-service
labels:
app: marklogic
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
#restartPolicy: OnFailure
clusterIP: None
selector:
app: marklogic
ports:
- protocol: TCP
port: 7997
#nodePort: 31997
name: ml7997
- protocol: TCP
port: 8000
#nodePort: 32000
name: ml8000
# ... More ports defined
#type: NodePort
---
apiVersion: apps/v1alpha1
kind: PetSet
metadata:
name: marklogic
spec:
serviceName: "ml-service"
replicas: 2
template:
metadata:
labels:
app: marklogic
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
terminationGracePeriodSeconds: 30
containers:
- name: 'marklogic'
image: "{local docker registry ip}:5000/dcgs-sof/ml8-docker-final:v1"
imagePullPolicy: Always
command: ["/opt/entry-point.sh", "-l", "/opt/mlconfig.sh"]
ports:
- containerPort: 7997
name: ml7997
- containerPort: 8000
name: ml8000
- containerPort: 8001
name: ml8001
- containerPort: 8002
name: ml8002
- containerPort: 8040
name: ml8040
- containerPort: 8041
name: ml8041
- containerPort: 8042
name: ml8042
- containerPort: 8050
name: ml8050
- containerPort: 8051
name: ml8051
- containerPort: 8060
name: ml8060
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
lifecycle:
preStop:
exec:
command: ["/etc/init.d/MarkLogic stop"]
volumeMounts:
- name: ml-data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: ml-data
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
我评论了type: NodePort
定义,因为我认为这可能是罪魁祸首,但仍然没有成功。
此外,如果我运行docker@minikube:/$ docker exec b4d21c4bc065 /bin/bash -c 'nslookup marklogic-1.marklogic.default.svc.cluster.local'
,则无法解析名称。
我缺少什么?
答案 0 :(得分:0)
您正在解析错误的域名。 见http://kubernetes.io/docs/user-guide/petset/#network-identity
你应该尝试解决:
marklogic-0.ml-service.default.svc.cluster.local
如果所有内容都在默认命名空间内,则DNS名称为:
<pod_name>.<svc_name>.default.svc.cluster.local