<p>I'm following the Istio doc (<a href="https://istio.io/docs/examples/advanced-egress/egress-gateway/" rel="nofollow noreferrer">https://istio.io/docs/examples/advanced-egress/egress-gateway/</a>) to set up an egress gateway. The results I got is different from what the doc describes and I wonder how can I fix it.</p>

<p>I have a simply docker container with a sidecar injected. After I applied a gateway config for <code>google.com</code> similar to the one provided by the doc:</p>

<pre><code>cat &lt;&lt;EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: google
spec:
  hosts:
  - google.com
  ports:
  - number: 80
    name: http-port
    protocol: HTTP
  - number: 443
    name: https
    protocol: HTTPS
  resolution: DNS
EOF
</code></pre>

<p>I still can't reach it from within the container:</p>

<pre><code>$ kubectl exec -it $SOURCE_POD -c $CONTAINER_NAME -- curl -sL -o /dev/null -D - http://google.com
HTTP/1.1 301 Moved Permanently
location: http://www.google.com/
content-type: text/html; charset=UTF-8
... 

HTTP/1.1 404 Not Found
date: Thu, 18 Oct 2018 22:55:57 GMT
server: envoy
content-length: 0
</code></pre>

<p>however, <code>curl</code> from <code>istio-proxy</code> works:</p>

<pre><code>$ kubectl exec -it $SOURCE_POD -c istio-proxy -- curl -sL -o /dev/null -D - http://google.com
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
...

HTTP/1.1 200 OK
Date: Thu, 18 Oct 2018 22:55:43 GMT
Expires: -1
...
</code></pre>

<p>Checked that the gateway exists:</p>

<pre><code>$ kubectl describe serviceentry/google
Name:         google
Namespace:    default
Labels:       &lt;none&gt;
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"networking.istio.io/v1alpha3","kind":"ServiceEntry","metadata":{"annotations":{},"name":"google","namespace":"default"},"sp...
API Version:  networking.istio.io/v1alpha3
Kind:         ServiceEntry
Metadata:
  Cluster Name:
  Creation Timestamp:  2018-10-18T22:36:34Z
  Generation:          1
  Resource Version:    2569394
  Self Link:           /apis/networking.istio.io/v1alpha3/namespaces/default/serviceentries/google
  UID:                 4482d584-...
Spec:
  Hosts:
    google.com
  Ports:
    Name:      http-port
    Number:    80
    Protocol:  HTTP
    Name:      https
    Number:    443
    Protocol:  HTTPS
  Resolution:  DNS
Events:        &lt;none&gt;
</code></pre>

<p>Any ideas? </p>

Justin Zhang
<p>Your problem is that the curl request is getting a 301 redirect to <code>www.google.com</code>, but your ServiceEntry has only exposed <code>google.com</code>. You can fix it by adding <code>www.google.com</code> as another host in your ServiceEntry like this:</p>

<pre><code>cat &lt;&lt;EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: google
spec:
  hosts:
  - google.com
  - www.google.com
  ports:
  - number: 80
    name: http-port
    protocol: HTTP
  - number: 443
    name: https
    protocol: HTTPS
  resolution: DNS
EOF
</code></pre>
