Why can not reach the service from outside?

12/4/2019

I have the following services and would like to call those outside from 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\

The greeter-service is the first candidate, that I would like to reach from outside. I've created a virtual services as follows:

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

then after the deployment:

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

as you can see, the virtual service for greeter-service is created. Then I tried to call it from outside via 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

The ingress controller is configured as follows:

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

As you can see, I can not reach the service. What is wrong?

-- zero_coding
istio
kubernetes

1 Answer

12/4/2019

Your query didn't match the host. Try

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