《OpenShift 4.x HOL教程汇总》
说明:本文已经在OpenShift 4.12环境中验证
Istio缺省是不限制服务网格中的服务对外部访问的,不过我们可以对Egress进行控制,以限制Istio上的服务对外部资源的访问。
环境准备:我们在开始之前先确保环境和完成《OpenShift 4 之Istio-Tutorial (2) 部署三个微服务》一样,只部署了3个微服务和VirtualService、Gateway,没有DestinationRule。
$ oc delete -f recommendation/kubernetes/Deployment-v1.yml -n ${ISTIO_APP}
$ oc delete -f recommendation/kubernetes/Deployment-v2.yml -n ${ISTIO_APP}
$ oc apply -f recommendation/kubernetes/Deployment-v3.yml -n ${ISTIO_APP}
$ oc get pod -n ${ISTIO_APP}
NAME READY STATUS RESTARTS AGE
customer-77dc47d7f8-szhd5 2/2 Running 16 2d11h
preference-v1-55476494cf-xm4dq 2/2 Running 0 4d8h
recommendation-v3-57556796f8-qcdl7 2/2 Running 0 151m
$ curl $INGRESS_GATEWAY/customer
customer => preference => recommendation v3 2020-01-19T11:33+01:00 from '83bbb6d11a7e': 1
$ oc get configmap istio -n -n ${ISTIO_SYSTEM} -o yaml | sed 's/mode: ALLOW_ANY/mode: REGISTRY_ONLY/g' | kubectl replace -n istio-system -f -
$ curl $INGRESS_GATEWAY/customer
customer => Error: 503 - preference => Error: 500 - <!doctype html>
...
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: worldclockapi-egress-rule
spec:
hosts:
- worldclockapi.com
ports:
- name: http-80
number: 80
protocol: http
执行命令,创建ServiceEntry对象。
$ create -f istiofiles/service-entry-egress-worldclockapi.yml -n ${ISTIO_APP}
$ curl $INGRESS_GATEWAY/customer
customer => preference => recommendation v3 2020-01-19T11:43+01:00 from '83bbb6d11a7e': 4
$ oc delete -f recommendation/kubernetes/Deployment-v3.yml -n ${ISTIO_APP}
$ oc delete -f istiofiles/service-entry-egress-worldclockapi.yml -n ${ISTIO_APP}