bookinfo项目部署

需要一个搭建完成的k8s集群,且必须安装了metrics组件和ingress组件

1.png

1 . istioctl安装

使用提供的istio-1.10.1-linux-amd64.tar.gz进行istio的部署安装,并配置到系统环境变量中。完成后使用istioctl命令查看istio的版本信。

1
2
3
4
5
6
7
8
[root@master ~]# tar -xzvf istio-1.10.1-linux-amd64.tar.gz
[root@master ~]# cd istio-1.10.1/
[root@master ~]# export PATH=$PWD/bin:$PATH
[root@master ~]# cd bin/
[root@master ~]# cp -ar istioctl /usr/bin/
[root@master ~]# istioctl version
no running Istio pods in "istio-system"
1.10.1

2 . 导入镜像

需要先在harbor仓库上新建一个istio项目,将提供的bookinfo项目镜像、istio以及engress-proxy镜像上传至Harbor仓库中。

2.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 导入
docker load -i examples-bookinfo-details.tar.gz
docker load -i examples-bookinfo-reviews-v1.tar.gz
docker load -i examples-bookinfo-productpage.tar.gz
docker load -i examples-bookinfo-reviews-v2.tar.gz
docker load -i examples-bookinfo-ratings.tar.gz
docker load -i examples-bookinfo-reviews-v3.tar.gz
docker load -i istio-1-10-1.tar.gz
docker load -i engress-proxyv2-1-10-1.tar.gz

# 改标签(192.168.1.30为harbor仓库地址)
docker tag istio/examples-bookinfo-details-v1:1.15.0 192.168.1.30/istio/examples-bookinfo-details-v1:1.15.0
docker tag istio/examples-bookinfo-reviews-v1:1.15.0 192.168.1.30/istio/examples-bookinfo-reviews-v1:1.15.0
docker tag istio/examples-bookinfo-reviews-v2:1.15.0 192.168.1.30/istio/examples-bookinfo-reviews-v2:1.15.0
docker tag istio/examples-bookinfo-reviews-v3:1.15.0 192.168.1.30/istio/examples-bookinfo-reviews-v3:1.15.0
docker tag istio/examples-bookinfo-ratings-v1:1.15.0 192.168.1.30/istio/examples-bookinfo-ratings-v1:1.15.0
docker tag istio/examples-bookinfo-productpage-v1:1.16.2 192.168.1.30/istio/examples-bookinfo-productpage-v1:1.16.2
docker tag istio/pilot:1.10.1 192.168.1.30/istio/pilot:1.10.1
docker tag istio/proxyv2:1.10.1 192.168.1.30/istio/proxyv2:1.10.1

# 上传
docker push 192.168.1.30/istio/examples-bookinfo-details-v1:1.15.0
docker push 192.168.1.30/istio/examples-bookinfo-reviews-v1:1.15.0
docker push 192.168.1.30/istio/examples-bookinfo-reviews-v2:1.15.0
docker push 192.168.1.30/istio/examples-bookinfo-reviews-v3:1.15.0
docker push 192.168.1.30/istio/examples-bookinfo-ratings-v1:1.15.0
docker push 192.168.1.30/istio/examples-bookinfo-productpage-v1:1.16.2
docker push 192.168.1.30:/istio/pilot:1.10.1
docker push 192.168.1.30:/istio/proxyv2:1.10.1

3.png

3 . 安装istio

使用istioctl命令安装istio,并设置profile为demo,安装成功后查看安装istio所创建的所有资源。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 这个命令执行个大约1-2分钟
[root@master ~]# istioctl install --set profile=demo -y
Detected that your cluster does not support third party JWT authentication. Falling back to less secure first party JWT. See https://istio.io/v1.10/docs/ops/best-practices/security/#configure-third-party-service-account-tokens for details.
! values.global.jwtPolicy is deprecated; use Values.global.jwtPolicy=third-party-jwt. See http://istio.io/latest/docs/ops/best-practices/security/#configure-third-party-service-account-tokens for more information instead
✔ Istio core installed
✔ Istiod installed
✔ Egress gateways installed
✔ Ingress gateways installed
✔ Installation complete Thank you for installing Istio 1.10. Please take a few minutes to tell us about your install/upgrade experience! https://forms.gle/KjkrDnMPByq7akrYA


# 查看资源
[root@master ~]# kubectl get all -n istio-system
NAME READY STATUS RESTARTS AGE
pod/istio-egressgateway-c6c658767-ltlwn 1/1 Running 0 89s
pod/istio-ingressgateway-8485d56f8f-s7kzp 1/1 Running 0 89s
pod/istiod-65968f8777-95nlf 1/1 Running 0 2m1s

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/istio-egressgateway ClusterIP 10.106.244.253 <none> 80/TCP,443/TCP 88s
service/istio-ingressgateway LoadBalancer 10.104.122.240 <pending> 15021:31895/TCP,80:31815/TCP,443:31672/TCP,31400:30284/TCP,15443:31179/TCP 88s
service/istiod ClusterIP 10.100.72.88 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 2m1s

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/istio-egressgateway 1/1 1 1 89s
deployment.apps/istio-ingressgateway 1/1 1 1 89s
deployment.apps/istiod 1/1 1 1 2m1s

NAME DESIRED CURRENT READY AGE
replicaset.apps/istio-egressgateway-c6c658767 1 1 1 89s
replicaset.apps/istio-ingressgateway-8485d56f8f 1 1 1 89s
replicaset.apps/istiod-65968f8777 1 1 1 2m1s

4 . 安装bookinfo

将默认的命名空间default名称空间的标记为 istio-injection=enabled以实现自动Sidecar 注入,然后基于istio安装目录下的samples/BOOKINFO/platform/kube/bookinfo.yaml文件进行bookinfo应用的部署。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@master ~]# kubectl label namespace default istio-injection=enabled
namespace/default labeled

# 需要到istio-1.10.1目录下执行
[root@master istio-1.10.1]# kubectl apply -f samples/BOOKINFO/platform/kube/bookinfo.yaml

# 如果k8s没有安装metrics,这里不会显示任何内容
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-5f85b896db-5nhhs 2/2 Running 0 3m31s
productpage-v1-5d9b4c9849-lfcn4 2/2 Running 0 3m31s
ratings-v1-7fb7d8978-bvrmz 2/2 Running 0 3m31s
reviews-v1-68fbcc5c9b-bchnf 2/2 Running 0 3m31s
reviews-v2-6cc5bc759d-bjmz6 2/2 Running 0 3m31s
reviews-v3-67d78d98d4-cbn8b 2/2 Running 0 3m31s

5 . 网关配置

基于samples/BOOKINFO/networking/bookinfo-gateway.yaml文件部署bookinfo的服务网关,创建成功后查看所有的service。查看网关对应的接口,然后在浏览器通过gateway ip:访问接口/productpage进行访问查看页面信息。

1
2
3
4
5
6
7
8
9
10
[root@master istio-1.10.1]# kubectl apply -f samples/BOOKINFO/networking/bookinfo-gateway.yaml

[root@master ~]# kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-egressgateway ClusterIP 10.106.244.253 <none> 80/TCP,443/TCP 40m
istio-ingressgateway LoadBalancer 10.104.122.240 <pending> 15021:31895/TCP,80:31815/TCP,443:31672/TCP,31400:30284/TCP,15443:31179/TCP 40m
istiod ClusterIP 10.100.72.88 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 41m

# 访问http://192.168.1.10:31815/productpage
# 31815来源:看istio-ingressgateway的80端口对应的是哪个端口

6 . 访问测试

访问http://192.168.1.10:31815/productpage。

31815来源:看istio-ingressgateway的80端口对应的是哪个端口。

打开后手动刷新,如果页面在以下三张来回切换说明成功。

4.png

5.png

6.png