场景: 我有2个群集:A和B都安装了istio。我想将群集A中的service-1公开为service-1.suffix,并让群集B中的service-2通过以下方式访问service-1:service-1.suffix。以下图片说明了我的想法。 在群集A中,我定义了一个virtualService和Gateway来将请求路由到service-1。
网关:
#aggregate method
agras <- raster::aggregate(wpras,fact=10,expand=T)
#returns "Killed"
#resamp method
reras <- raster(nrow = ceiling(nrow(wpras)/10), ncol = ceiling(ncol(wpras)/10))
reras2 <- raster::resample(wpras, reras, method="bilinear")
#returns Error: cannot allocate vector of size 1.3 Gb
VirtualService:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: service-1
spec:
selector:
istio: ingressgateway # use istio default ingress gateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "service-1.suffix"
这工作正常,因为我可以使用curl成功访问它。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: service-1
spec:
hosts:
- service-1.default.svc.cluster.local
- "service-1.suffix"
gateways:
- service-1
- mesh
http:
- route:
- destination:
host: service-1.default.svc.cluster.local
port:
number: 8080
下一步是在集群B中创建Egress和VirtualService。这是我的定义文件:
ServiceEntry:
curl -I -HHost:service-1.suffix http://cluster_A_proxy:31380
VirtualService:
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: service-1
spec:
hosts:
- "service-1.suffix" #the global suffix mcm.com could be defined in mcm.
#addresses:
#- xxx/32
ports:
- number: 80
name: http
protocol: HTTP
resolution: STATIC
location: MESH_EXTERNAL
endpoints:
- address: 1.1.1.1 #The cluster A proxy ip
ports:
http: 31380
在群集B中,当我尝试使用curl解决service-1.suffix时,出现了DNS错误,提示无法解决。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: service-1
spec:
hosts:
- "service-1.suffix"
http:
- route:
- destination:
host: "service-1.suffix"
port:
number: 80
我该如何解决?
curl: (6) Could not resolve host: service-1.suffix
编辑: 当我在serviceentry中使用其他可解析的主机名(例如www.google.com)时,我可以通过它,对www.google.com的请求将被重定向到群集A中的service-1。同样,如果我使用nip.io作为我的后缀,它很好用。但是,组成名称service-1.suffix无法解析。
答案 0 :(得分:1)
使用随机IP定义Kubernetes ExternalName服务:
kind: Service
apiVersion: v1
metadata:
name: service1
spec:
type: ExternalName
externalName: 1.1.1.1