为什么无法从外部获得服务?

时间:2019-12-04 20:36:32

标签: kubernetes istio

我有以下服务,并且想从kubernetes外部打电话给他们:

k get services                              
NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
greeter-service   ClusterIP   10.233.35.214   <none>        3000/TCP   4d9h
helloweb          ClusterIP   10.233.8.173    <none>        3000/TCP   4d9h
kubernetes        ClusterIP   10.233.0.1      <none>        443/TCP    4d13h
movieweb          ClusterIP   10.233.12.155   <none>        3000/TCP   3d9h\

问候服务是我想从外部联系的第一位候选人。我已经创建了一个虚拟服务,如下所示:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
    name: greeter-service
spec:
    hosts:
        - greeter-service.default.svc.cluster.local
    http:
        - match:
              - uri:
                    prefix: /greeting
          rewrite:
              uri: /hello
          route:
              - destination:
                    host: greeter-service.default.svc.cluster.local
                    port:
                        number: 3000
                    subset: v2
        - route:
              - destination:
                    host: greeter-service.default.svc.cluster.local
                    port:
                        number: 3000
                    subset: v1

然后在部署后:

k get virtualservices                       
NAME              GATEWAYS    HOSTS                                         AGE
greeter-service               [greeter-service.default.svc.cluster.local]   3d2h
helloweb          [gateway]   [helloweb.dev]                                4d5h
movieweb          [gateway]   [movieweb.dev]                                3d9h

如您所见,创建了 greeter-service 的虚拟服务。 然后我尝试通过curl从外部调用它:

curl -v 172.17.8.180:80/greeting
*   Trying 172.17.8.180...
* TCP_NODELAY set
* Connected to 172.17.8.180 (172.17.8.180) port 80 (#0)
> GET /greeting HTTP/1.1
> Host: 172.17.8.180
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< date: Wed, 04 Dec 2019 20:34:55 GMT
< server: istio-envoy
< content-length: 0
< 
* Connection #0 to host 172.17.8.180 left intact

入口控制器的配置如下:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - '*'

如您所见,我无法获得服务。怎么了?

1 个答案:

答案 0 :(得分:4)

您的查询与主机不匹配。试试

curl -v -H 'Host: greeter-service.default.svc.cluster.local' 172.17.8.180:80/greeting