I'm following the Istio doc (https://istio.io/docs/examples/advanced-egress/egress-gateway/) 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.
I have a simply docker container with a sidecar injected. After I applied a gateway config for google.com
similar to the one provided by the doc:
cat <<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
I still can't reach it from within the container:
$ 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
however, curl
from istio-proxy
works:
$ 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
...
Checked that the gateway exists:
$ kubectl describe serviceentry/google
Name: google
Namespace: default
Labels: <none>
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: <none>
Any ideas?
You can just add a wild card if you don't want to handle this. with HTTP it works. You can try something like *.google.com and now you can use all services of google without getting blocked in the future.
Your problem is that the curl request is getting a 301 redirect to www.google.com
, but your ServiceEntry has only exposed google.com
. You can fix it by adding www.google.com
as another host in your ServiceEntry like this:
cat <<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