《云原生》快速部署istio(istio+k8s)

发布于:2023-01-25 ⋅ 阅读:(575) ⋅ 点赞:(0)

试验环境是一个3节点的k8s集群(一个master两个worker),k8s版本是1.8.0。

先看效果图
在这里插入图片描述

1.下载istio

转到Istio 版本页面下载操作系统的安装文件,或自动下载并解压最新版本(Linux 或 macOS):

$ curl -L https://istio.io/downloadIstio | sh -

要是下载不下来就到istio的发布页面https://github.com/istio/istio/releases/下载安装包,用sftp上传到master节点,并解压缩:

tar -zxvf istio-1.14.3-linux-amd64.tar.gz

进入解压缩后的安装包目录:

cd istio-1.14.3

tree -L 1
.
├── bin       二进制文件istioctl
├── LICENSE
├── manifests
├── manifest.yaml
├── README.md
├── samples   该目录下包含示例的应用程序(yaml)
└── tools

将istioctl添加到系统PATH环境变量:

export PATH=$PWD/bin:$PATH

2.安装istio

对于此安装,我们使用demo 配置文件。选择它具有一组良好的测试默认值,但还有其他配置文件用于生产或性能测试。生产环境部署istio时建议使用default profile,而演示和评估istio建议部署demo profile。

istioctl install --set profile=demo -y
✔ Istio core installed
✔ Istiod installed
✔ Egress gateways installed
✔ Ingress gateways installed
✔ Installation complete

安装完成后,查看一下namespace istio-system下的Pod和Service:

  kubectl get pod -n istio-system
  
NAME                                    READY   STATUS    RESTARTS   AGE
grafana-6fbd7fb4cd-8m45g                1/1     Running   0          28m
istio-egressgateway-c577988fd-9rdhb     1/1     Running   1          154m
istio-ingressgateway-7f78c4d95d-m86rv   1/1     Running   1          154m
istiod-65dfd45474-mzglb                 1/1     Running   1          155m
jaeger-78775f676f-rg2zn                 1/1     Running   0          28m
kiali-774555c697-nf7s4                  1/1     Running   0          28m
prometheus-9c555c848-jzpkg              2/2     Running   0          28m


kubectl get svc -n istio-system


NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                      AGE
grafana                ClusterIP      10.102.3.100     <none>        3000/TCP                                                                     28m
istio-egressgateway    ClusterIP      10.99.36.224     <none>        80/TCP,443/TCP                                                               154m
istio-ingressgateway   LoadBalancer   10.105.48.20     <pending>     15021:32333/TCP,80:31806/TCP,443:30052/TCP,31400:32126/TCP,15443:30997/TCP   154m
istiod                 ClusterIP      10.99.67.187     <none>        15010/TCP,15012/TCP,443/TCP,15014/TCP                                        155m
jaeger-collector       ClusterIP      10.103.123.76    <none>        14268/TCP,14250/TCP,9411/TCP                                                 28m
kiali                  ClusterIP      10.107.205.129   <none>        20001/TCP,9090/TCP                                                           28m
prometheus             ClusterIP      10.99.164.3      <none>        9090/TCP                                                                     28m
tracing                ClusterIP      10.108.27.105    <none>        80/TCP,16685/TCP                                                             28m
zipkin                 ClusterIP      10.111.136.10    <none>        9411/TCP                                                                     28m

可以看出部署了istiod, istio-ingressgateway, istio-egressgateway

因为后边要部署的示例应用是部署在default namespace中的,下面给default namespace添加istio-injection=enabled标签,指示后续在此namespace部署应用时,自动注入envoy sidecar(边车)代理。

kubectl label namespace default istio-injection=enabled
namespace/default labeled

3.部署示例应用

下面部署bookinfo示例应用,bookinfo这个应用是一个在线书店的演示系统

部署Bookinfo示例应用程序

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

应用程序将启动。随着每个 pod 准备就绪,Istio sidecar 将随之部署。

kubectl get services

NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
details       ClusterIP   10.98.209.177   <none>        9080/TCP   155m
kubernetes    ClusterIP   10.96.0.1       <none>        443/TCP    117d
productpage   ClusterIP   10.108.233.14   <none>        9080/TCP   155m
ratings       ClusterIP   10.102.56.130   <none>        9080/TCP   155m
reviews       ClusterIP   10.108.140.23   <none>        9080/TCP   155m
kubectl get pods

NAME                              READY   STATUS    RESTARTS   AGE
details-v1-96959d5b9-zjktn        2/2     Running   2          156m
productpage-v1-864f666bf9-zr2qf   2/2     Running   2          156m
ratings-v1-5ffd6f78d9-pbc4g       2/2     Running   2          156m
reviews-v1-79d4597cbf-jzkjf       2/2     Running   2          156m
reviews-v2-dfd4d6b59-qwl85        2/2     Running   1          156m
reviews-v3-c8964d889-nmgc2        2/2     Running   2          156m

重新运行之前的命令,等待所有 pod 报告 READY2/2和 STATUSRunning后再进行下一步。这可能需要几分钟,具体取决于您的平台。

验证到目前为止一切正常。运行以下命令,通过检查响应中的页面标题来查看应用程序是否在集群内运行并提供 HTML 页面:

$ 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>

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

将应用关联到istio网关:

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

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

确保配置没有问题:

istioctl analyze

✔ No validation issues found when analyzing namespace: default.

4.从集群外部访问bookinfo应用

因为这里使用的k8s集群没有cloud driver和外部负载均衡器,Service istio-ingressgateway的ExternalIP是处于Pending状态的。

kubectl get svc istio-ingressgateway -n istio-system

NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)     AGE
istio-ingressgateway   LoadBalancer   10.105.48.20   <pending>     15021:32333/TCP,80:31806/TCP,443:30052/TCP,31400:32126/TCP,15443:30997/TCP   163m

设置入口端口:

export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')

GKE:

$ export INGRESS_HOST=workerNodeAddress
 export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')
  1. 设置GATEWAY_URL

    $ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
    
  2. 确保 IP 地址和端口已成功分配给环境变量:

    $ echo "$GATEWAY_URL"
    192.168.1.107:31806
    

验证外部访问

通过使用浏览器查看 Bookinfo 产品页面,确认可以从外部访问 Bookinfo 应用程序。

  • 运行以下命令以检索 Bookinfo 应用程序的外部地址。

    $ echo "http://$GATEWAY_URL/productpage"
    
  • 将上一个命令的输出粘贴到您的 Web 浏览器中,并确认显示 Bookinfo 产品页面。

  • 使用istio-ingressgateway的NodePort从集群外部访问bookinfo应用,这里其http的NodePort是31806。 浏览器打开http://192.168.1.107:31806/productpage确保可以打开bookinfo的应用界面。

5.部署和查看Istio仪表板

Istio 集成了几个不同的遥测应用程序。这些可以帮助您了解服务网格的结构、显示网格的拓扑以及分析网格的健康状况。

使用以下说明部署Kiali仪表板以及PrometheusGrafanaJaeger

安装Kiali 和其他插件并等待它们被部署。

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

Waiting for deployment "kiali" rollout to finish: 0 of 1 updated replicas are available...
deployment "kiali" successfully rolled out

等待kiali部署完成后,使用istioctl dashboard --address 0.0.0.0 kiali命令启动istio dashboard kiali的监听,外部访问kiali(master节点ip:20001/kiali)。
在这里插入图片描述

本文基于istio官方文档https://istio.io/latest/zh/docs/setup/getting-started/。

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到