【发布时间】:2019-11-01 08:54:06
【问题描述】:
我在命名空间 myNamespace 中有一个名为 myService 的 gcp 中托管的负载平衡 kubernetes 服务。我给它一个标签“myKubeTag”。我还有一个正在运行的 vm,它本身正在运行一个想要与 myService 通信的 docker 容器。我已经创建了一个防火墙规则来允许两者之间的 tcp 流量。
我可以把服务的IP地址给vm来连接,我想问的是,如何设置名称代理,让vm直接通过名称引用?
工作负载和服务从 helm 启动,如下所示:
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: {{ template "app.prefix" . }}
spec:
selector:
matchLabels:
name: {{ template "app.prefix" . }}
template:
metadata:
labels:
name: {{ template "app.prefix" . }}
spec:
nodeSelector:
target_workload: {{ .Values.prefix }}-myApp
containers:
- name: myApp
image: {{ .Values.myApp.image }}
tolerations:
- key: "target_workload"
operator: "Equal"
value: {{ .Values.prefix }}-myApp
effect: "NoSchedule"
---
apiVersion: v1
kind: Service
metadata:
name: {{ template "app.prefix" . }}
spec:
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
type: LoadBalancer
selector:
role: {{ template "app.prefix" . }}
我已准备好以下内容: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
这让我认为主机名是 myService.myNamespace.sxc.cluster-domain.myCluster,但是在我的 VM 上运行的容器抛出了一个未知主机异常。
【问题讨论】:
-
您能否澄清它是否已经在使用 IP 地址工作(假设 GKE 集群是使用 IP 别名设置的)?展示它的工作示例会很有帮助,这样我们就有了更多的上下文。
-
你是如何设置 LB 的?
-
@AndyShinn 我已对其进行了更新以包含工作负载和服务的清单。他们非常标准。我可以从服务中请求集群 IP,并取回一个有效的 IP。我想知道的是,从在同一个项目中运行的虚拟机的角度来看,访问同一个服务的有效主机名是什么?
-
我基本上想知道您是否根据cloud.google.com/kubernetes-engine/docs/how-to/alias-ips 设置了别名 IP。但我不想只给出这个链接作为答案,所以我试图使用私有云 DNS 给出一个更好的例子。
标签: networking kubernetes google-cloud-platform hostname