```
使用提供的软件包 ServiceMesh.tar.gz 将 Bookinfo 应用部署到 default 命名空间下,使用Istio Gateway 可 以 实 现 应 用 程 序 从 外 部 访 问 , 请 为 Bookinfo 应 用 创 建 一 个 名 为bookinfo-gateway 的网关,指定所有 HTTP 流量通过 80 端口流入网格,然后将网关绑定到虚拟服务 bookinfo 上。
```
1. 解压软件包,导入镜像
```
[root@master ~]# tar -xvf ServiceMesh.tar.gz
[root@master ~]# docker load -i ServiceMesh/images/image.tar
```
2. 部署book info应用(前提: 已经安装好了k8s集群和Istio灰度发布)
```
# 为default命名空间开启自动注入Sidecar
[root@k8s-master-node1 ~]# kubectl label namespace default istio-injection=enabled
[root@k8s-master-node1 ~]# kubectl apply -f ServiceMesh/bookinfo/bookinfo.yaml
service/details created
serviceaccount/bookinfo-details created
deployment.apps/details-v1 created
service/ratings created
serviceaccount/bookinfo-ratings created
deployment.apps/ratings-v1 created
service/reviews created
serviceaccount/bookinfo-reviews created
deployment.apps/reviews-v1 created
service/productpage created
serviceaccount/bookinfo-productpage created
deployment.apps/productpage-v1 created
[root@k8s-master-node1 ~]#
# 查看pod状态
[root@k8s-master-node1 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-79f774bdb9-tr5c2 2/2 Running 0 7s
productpage-v1-6b746f74dc-cqfk4 2/2 Running 0 7s
ratings-v1-b6994bb9-vmqtb 2/2 Running 0 7s
reviews-v1-545db77b95-slxhp 2/2 Running 0 7s
```
2. 编写外部网关的yaml
```
[root@k8s-master-node1 ~]# vi bookinfo-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "*"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
prefix: /static
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
```
3. 部署外部网关
```
[root@k8s-master-node1 ~]# kubectl apply -f bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
```
4. 验证
```
[root@k8s-master-node1 ~]# kubectl get svc -n istio-system |grep istio-ingressgateway
istio-ingressgateway LoadBalancer 10.96.215.87 <pending> 15021:38177/TCP,80:18334/TCP,443:39738/TCP,31400:32553/TCP,15443:38101/TCP 15m
# 这里外部网关80端口对应的svc端口为18334
# 浏览器访问http://ip:18334/productpage,页面结果如下图所示即为成功
```

2022国赛容器云k8s运维: 创建ingress gateway
本文含有隐藏内容,请 开通VIP 后查看