istio bookinfo微服务搭建流程
使用istio的Demo——bookinfo可以很方便的进行配置变更和故障注入,在这篇博客编写之时,博客内贴附的文档皆是有效的,但是文档会有更新和废弃,请按照文章思路自行寻找对应的最新文档。
部分文档可能需要访问Google资源,请提前准备。
1. 安装kubectl和minikube
安装kubectl可参考:https://kubernetes.io/docs/tasks/tools/install-kubectl/
安装minikube可参考:https://v1-18.docs.kubernetes.io/docs/tasks/tools/install-minikube/
# 下载最新kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
# 安装
sudo install kubectl /usr/bin/
# 下载minikube
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \&& chmod +x minikube
# 安装minikube
sudo install minikube /usr/bin/minikube
2. 搭建istio所需平台
搭建istio可使用多种平台,这里我使用的是minikube。创建minikube虚拟机参考文档:https://istio.io/latest/zh/docs/setup/platform-setup/minikube/。
安装minikube kvm2驱动参考文档:https://minikube.sigs.k8s.io/docs/drivers/kvm2/,https://minikube.sigs.k8s.io/docs/start/#install-a-hypervisor,https://help.ubuntu.com/community/KVM/Installation。
# 在ubuntu18.04中创建基于kvm2的minikube虚拟机
sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
sudo adduser `id -un` libvirt # 添加当前用户到 libvirt用户组
sudo adduser `id -un` kvm # 添加当前用户到kvm用户组
# 如果你的操作系统版本不是Ubtuntu18.04 请自行从上方文档链接中寻找对应的操作系统安装方式# 启动基于kvm2驱动的minikube虚拟机
minikube config set vm-driver kvm2
minikube start --memory=16384 --cpus=4 --kubernetes-version=v1.18.2 # 注意这里的版本应该与kubectl --version的版本应该接近,否则可能不兼容
至此,一个基于kvm2驱动的minikube虚拟机搭建完成
# 在minikube中查看内存使用的方式
$ minikube ssh
$ top
3. 安装istio
# 下载istio
curl -L https://istio.io/downloadIstio | sh -
# 进入根目录,文章编写之时是istio-1.8.2的版本
cd istio-1.8.2
# 该文件夹下有istioctl等一些工具,因此需要配置环境变量
export PATH=$PWD/bin:$PATH # 也可以在~/.bashrc中配置
# 使用官方提供的Demo配置文件安装istio即可(满足大部分的需求)
istioctl manifest install --set profile=demo
# 至此,istio安装完成,下面是监测是否正确安装的流程
kubectl get svc -n istio-system # 查看所有的服务
kubectl get pods -n istio-system # 查看所有的Pod
4. 安装Demo : bookinfo
这个示例官方给了比较多的文档说明,说明了如何配置变更和故障注入:https://istio.io/latest/zh/docs/examples/bookinfo/
# 进入istio根目录(即上面所说的istio-1.8.2)
# 为default命名空间打上标签:istio-injection=enabled
kubectl label namespace default istio-injection=enabled
# 使用kubectl 部署应用
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
# 检查服务是否正常启动:
kubectl get services
# 检查Pods是否正常启动:
kubectl get Pods # bookinfo服务启动的比较慢,建议等久一点
# Service和Pods都启动完毕后通过下面指令检查服务是否正常运行:
$ kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
# 输出应该是:<title>Simple Bookstore App</title>
5. 确定Ingress的IP和端口
这一步的目的是使得可以从集群外部访问集群的服务
# 为程序定义Ingress网关:
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
# 确认网关创建完成
kubectl get gateway
# 接着设置 INGRESS_HOST 和 INGRESS_PORT 变量
# 参考文档:https://istio.io/latest/zh/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-i-p-and-ports
# 按照上面的流程,我们没有使用外部的负载均衡,因此操作如下:
# 设置INGRESS_PORT 环境变量
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
# 设置SECURE_INGRESS_PORT 环境变量(暂时没用)
export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
# 设置INGRESS_HOST 环境变量
export INGRESS_HOST=$(minikube ip)
设置gateway URL
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
确认可以从外部进行访问:
curl -s http://${GATEWAY_URL}/productpage | grep -o "<title>.*</title>"
# 输出应该为:<title>Simple Bookstore App</title>
6. 配置Prometheus:
参考文档:https://istio.io/latest/docs/ops/integrations/prometheus/, https://istio.io/latest/zh/docs/tasks/observability/metrics/querying-metrics/
# 安装Prometheus(进入istio根目录)
kubectl apply -f samples/addons/prometheus.yaml# 验证已经运行着Prometheus
kubectl -n istio-system get svc prometheus# 进行端口转发使得可以从外部访问Prometheus
kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &# 在浏览器中访问http://localhost:9090/graph 即可打开Prometheus面板
7.相关使用和总结:
1. bookinfo的接口
${GATEWAY_URL}的值可以从上面第5步获取,请自行获取并替换!
# 这个接口可以直接发get请求,是bookinfo的前端
http://${GATEWAY_URL}/productpage
# 这个接口只能通过POST请求,并且header中Referer的值要为http://${GATEWAY_URL}/productpage
http://${GATEWAY_URL}/login
# 这个接口只能通过GET请求,并且header中Referer的值要为http://${GATEWAY_URL}/productpage
http://${GATEWAY_URL}/logout
2. Prometheus的接口
# 这是普罗米修斯的查询面板
http://localhost:9090/graph
# 这是获取指标数据的接口
http://localhost:9090/api/v1/query?query=<指标名字>&time=<时间戳的值,浮点数>
# 返回值是json数据
istio bookinfo微服务搭建流程相关推荐
- PaaS 以及全套服务微服务搭建流程
这是一篇写的很早的文章,所以有个别内容没那么新,涵盖的内容非常的全,内容太多,可以用于参考. 主要流程分为: Rancher PaaS 平台 MySQL 安装.配置.数据导入 RabbitMQ 安装. ...
- dbnetlib不存在或拒绝访问_idou老师教你学Istio 16:如何用 Istio 实现微服务间的访问控制...
本文由华为云容器Istio团队撰稿,未经允许谢绝转载. 摘要 使用 Istio 可以很方便地实现微服务间的访问控制.本文演示了使用 Denier 适配器和黑白名单两种方法. 使用场景 有时需要对微服务 ...
- SpringCloudAlibaba系列微服务搭建笔记一_Nacos
目录儿 二.SpringCloud技术栈 三.环境搭建 3.1 开发环境搭建 3.2 安装部署mysql 3.3 创建 SpringBoot 项目 3.3.1 简介 3.3.2 构建项目 3.3.3 ...
- OpenShift 4 之Service Mesh教程(1)- 创建ServiceMesh环境,部署Istio的微服务
<OpenShift 4.x HOL教程汇总> 说明:本文已经在OpenShift 4.8环境中验证 文章目录 创建ServiceMesh环境 部署Istio的微服务 参考 创建Servi ...
- SpringCloud微服务搭建(四 搭建EurekaServer集群)
在上一章的基础上 在EurekasServer里面添加三个yml: bootstrap-server1.yml: server:port: 8794eureka:instance:hostname: ...
- 巧用springboot微服务搭建一个网站
想到微服务搭建博客其实挺多的,那就用微服务简单做个记账的网站,并部署在站点 1. 首先除了要了解什么是微服务之外,因为是用Springboot框架,还要了解一下父子项目,thymeleaf,sprin ...
- SpringCloud工程搭建之网关微服务搭建(可选)
五.网关微服务搭建(可选) 完整工程源码:https://gitee.com/forwardxiang/spring-cloud-demo.git 5.1 创建网关服务子工程 5.1.1 引入依赖 创 ...
- SpringCloud工程搭建之业务微服务搭建(必选)
二.业务微服务搭建(必选) 完整工程源码:https://gitee.com/forwardxiang/spring-cloud-demo.git 2.1 创建业务服务子工程 2.1.1 IDEA操作 ...
- Java微服务开发流程及详细案例
微服务开发流程及详细案例 文章目录 微服务开发流程及详细案例 一. 微服务示例简介 二. IDEA创建父Maven工程及子项目 2.1 使用IDEA创建Maven项目 2.2创建子项目模块 2.3父项 ...
最新文章
- Windows 中 SQLite3 使用(1) -- 配置
- URL概念及与URL的区别
- python学习六:数据结构
- python 清空文件夹_Python初学者请注意!别这样直接运行python命令,否则电脑等于“裸奔”...
- Asp.Net Core 404处理
- JMM设计原理之双重检查Lock
- C++ 类访问控制public/private/protected探讨
- 信息学奥赛一本通(2061:【例1.2】梯形面积)
- 苹果发布紧急公告:老设备11月3日前再不更新就要停止服务啦
- linux下的malloc申请的是虚拟还是物理的,关于malloc申请内存
- Jsp Servlet Mysql实现的学生成绩管理系统
- Python一:【skimage】图像处理库的应用,不使用opencv的情况
- dubbo学习--导入eclipse异常Unbound classpath container(2)
- 变化世界中的军事地质学
- 非常好的油画制作软件ArtRage.v2.11
- 企业级地理数据库(2)创建并加载企业级地理数据库
- esp8266,esp32中的SPI FLASH 访问模式(QIO QOUT DIO DOUT)
- ftp(文件传输协议)服务
- 2015 4399校园招聘游戏开发笔试题
- PAT 十一章 模拟 17-24 自用