istio 部署案例应用

1.部署 Bookinfo 示例应用

cd /home/istio-1.17.1
kubectl apply -f samples/bookinfo/platform/kube/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
deployment.apps/reviews-v2 created
deployment.apps/reviews-v3 created
service/productpage created
serviceaccount/bookinfo-productpage created
deployment.apps/productpage-v1 created

注:如果istio的安装目录已经移除,可以在这个链接下载bookinfo.yaml资源文件。https://raw.githubusercontent.com/istio/istio/release-1.17/samples/bookinfo/platform/kube/bookinfo.yaml

 2.当每个 Pod 准备就绪时,Istio 边车将伴随应用一起部署

kubectl get svc

NAME          TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
details       ClusterIP   10.0.0.63    <none>        9080/TCP       20h
kubernetes    ClusterIP   10.0.0.1     <none>        443/TCP        9d
nginx         NodePort    10.0.0.172   <none>        80:41194/TCP   7d20h
productpage   ClusterIP   10.0.0.190   <none>        9080/TCP       20h
ratings       ClusterIP   10.0.0.214   <none>        9080/TCP       20h
reviews       ClusterIP   10.0.0.76    <none>        9080/TCP       20h

kubectl get pods

NAME                             READY   STATUS    RESTARTS      AGE
details-v1-6997d94bb9-tqwxs      2/2     Running   0             13m
nginx-748c667d99-klqpt           1/1     Running   3 (20h ago)   2d1h
productpage-v1-d4f8dfd97-mwmwz   2/2     Running   2 (20h ago)   20h
ratings-v1-b8f8fcf49-kj5w7       2/2     Running   2 (20h ago)   20h
reviews-v1-5896f547f5-5dn8w      2/2     Running   0             13m
reviews-v2-5d99885bc9-pkwmp      2/2     Running   2 (20h ago)   20h
reviews-v3-589cb4d56c-l4mvz      2/2     Running   0             13m

3.确认上面的操作都正确之后,运行下面命令,通过检查返回的页面标题来验证应用是否已在集群中运行,并已提供网页服务:

kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"

<title>Simple Bookstore App</title>

4.此时,BookInfo 应用已经部署,但还不能被外界访问。 要开放访问,您需要创建 Istio 入站网关(Ingress Gateway), 它会在网格边缘把一个路径映射到路由。

kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created

5.确定入站 IP 和端口

kubectl get svc istio-ingressgateway -n istio-system

NAME                   TYPE           CLUSTER-IP   EXTERNAL-IP      PORT(S)                                                                      AGE
istio-ingressgateway   LoadBalancer   10.0.0.34    192.168.64.245   15021:32980/TCP,80:48892/TCP,443:45956/TCP,31400:30658/TCP,15443:33111/TCP   2d18h

设置入站 IP 地址和端口:

export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')

设置环境变量 GATEWAY_URL

export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT

确保 IP 地址和端口均成功地赋值给了环境变量:

echo "$GATEWAY_URL"

192.168.64.245:80

6.验证外部访问

运行下面命令,获取 Bookinfo 应用的外部访问地址。

echo "http://$GATEWAY_URL/productpage"

http://192.168.64.245:80/productpage

将输出地址复制粘贴到浏览器并访问,确认 Bookinfo 应用的产品页面是否可以打开。

7.安装仪表板

Istio 和几个遥测应用做了集成。 遥测能帮您了解服务网格的结构、展示网络的拓扑结构、分析网格的健康状态。

使用下面说明部署 Kiali 仪表板、 以及 Prometheus、 Grafana、 还有 Jaeger

安装 Kiali 和其他插件,等待部署完成。

kubectl apply -f samples/addons
kubectl rollout status deployment/kiali -n istio-system

deployment "kiali" successfully rolled out

访问 Kiali 仪表板。

istioctl dashboard kiali

修改暴露方式

kubectl edit svc kiali -n istio-system

将 type: ClusterIP 修改为 type: LoadBalancer,然后保存退出

 

posted @ 2023-03-01 12:26  SpringCore  阅读(37)  评论(0编辑  收藏  举报