当前位置:网站首页>云原生应用综合练习上
云原生应用综合练习上
2022-07-29 00:29:00 【taoli-qiao】
前面分类介绍各模块知识,此篇博客将开展综合练习,练习的例子是Istio官网的bookinfo这个应用。bookinfo的架构如下所示,可以看到不同的服务才用了不同的技术栈,但是通过image部署,可以屏蔽掉不同技术栈带来的部署差异问题。

productpage会调用details和reviews两个微服务,用来生成前端页面。
details中包含了书籍的信息。
reviews中包含了书籍相关的评论,它会调用ratings微服务。
ratings中包含了由书籍评价组成的评级信息。
reviews有3个版本,可用来展示各服务间的链路调用关系
v1版本不会调用ratings服务。
v2版本会调用ratings服务,并使用1到5个黑色图标显示评分信息。
v3版本会调用ratings服务,并使用1到5个红色图标显示评分信息。
综合练习中将涉及9个小案例练习,具体练习如下所示:
一:接下来开始第一个Task练习:将bookInfo应用发布到Istio Ingress网关。
1.1:用如下命令安装Istio。
curl -L https://istio.io/downloadIstio | sh -
cd istio-1.xx.0
cp bin/istioctl /usr/local/bin
istioctl install --set profile=demo -y1.2:将Istio官网下的BookInfo应用和网关配置copy过来,部署到集群上,yaml文件地址如下
samples/bookinfo/platform/kube/bookinfo.yaml
samples/bookinfo/networking/bookinfo-gateway.yamlbookinfo-gateway.yaml文件的配置如下所示,可以看到VirtualService中将流量导入到后端的productpage应用上。

1.3:查看Istio Ingress的svc的端口信息。

1.4:在外网通过node节点IP地址+svc端口信息访问bookinfo应用中的productpage,访问结果如下所示,说明应用被成功发布到了网关上。

二:接下来进行第二个Task,增加安全机制,将http访问方式转换成https
2.1: 生成x509的证书并存放到secret对象里面。因为是通过node节点IP访问的应用,所有生成证书时Inc./CN=node节点IP。
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -subj '/O=cncamp Inc./CN=node节点IP' -keyout bookinfo.key -out bookinfo.crt
kubectl create -n istio-system secret tls bookinfo-credential --key=bookinfo.key --cert=bookinfo.crt2.2: 配置新的Gateway,Gateway里面配置上https的credentials.
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: https-bookinfo
number: 443
protocol: HTTPS
tls:
mode: SIMPLE
credentialName: bookinfo-credential2.3:在safari上通过https方式访问应用,信任网站后,访问成功。结果如下(备注:如果用chrome访问会失败,因为是自签发的证书)。因为是https方式,所以这里是node节点IP加31287端口。

三:接下来开始第三个Task,开启mTLS
3.1:通过productpage 的SVC地址访问应用,访问成功。


3.2:在isto-system根namespace下创建PeerAuthentication对象.
(kubectl apply -f mtls.yaml -n istio-system)
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: "default"
spec:
mtls:
mode: STRICT3.3: 再次通过SVC地址应用,访问会失败,request被peer reset了。

浏览器通过https访问应用,仍然能成功。

可以看到通过启动全链路的mTLS,这样不在Istio管控内的直接去访问后端应用是不成功,但是浏览器访问仍然成功,因为浏览器是把请求发送给Istio Ingress Gateway,Gateway再转发到后端服务。这样从浏览器到Ingress Gateway是单向的TLS访问,Gateway到后端服务是mTLS,这样就增强了访问的安全。
第四:接着再进入第四个Task,给应用进行认证和授权,保证被允许的客户端才能访问到应用。
4.1: 创建RequestAuthentication和AthorizationPoliy.RequestAuthentication中定义了如果访问details服务,需要验证token。AuthorizationPoliy中定义访问服务的客户端必须带上由“[email protected]/[email protected]”签发的Token才允许访问。
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: "details"
spec:
selector:
matchLabels:
app: details
jwtRules:
- issuer: "[email protected]"
jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.12/security/tools/jwt/samples/jwks.json"apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: require-jwt
spec:
selector:
matchLabels:
app: details
action: ALLOW
rules:
- from:
- source:
requestPrincipals: ["[email protected]/[email protected]"]4.2:查看ProductPage服务,这个服务就访问了Details服务。

4.3:创建上面的认证和授权对象后,再次访问productpage服务,可以看到details服务已经无法访问了。因为productpage在访问details服务时并没有带着token进行访问。

4.4:如果要重新访问details服务,那么productpage服务需要进行代码修改,带上有效token访问details才行。通过上面的例子可以看到通过配置认证和授权,微服务间的访问都需要带上有效token才行,而客户端在获取token时,就能对客户端进行认证和授权。通过这种方式让微服务间的访问更加安全。
五:接下来再演示如果浏览器中输入了http,如何自动跳转成https访问方式,让客户体验更好
5.1:配置Gateway,增加https redirect跳转即可完成自动跳转。
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: https-bookinfo
number: 443
protocol: HTTPS
tls:
mode: SIMPLE
credentialName: bookinfo-credential
- hosts:
- '*'
port:
name: http-bookinfo
number: 80
protocol: HTTP
tls:
httpsRedirect: true5.2:在集群里面,通过ingress gateway的svc的IP地址访问productpage,用http方式访问,http映射到80端口,可以看到会自动化跳转到443端口上,也就是https方式访问。
以上就是对前面五个场景的练习,在下一篇博客中将对后面4个场景进行练习。
边栏推荐
- js判断 数组/对象数组 1 是否包含数组/对象数组 2
- Principle and usage setting of large page memory
- Canal实时解析mysql binlog数据实战
- Univariate function integration 1__ Indefinite integral
- Main causes of IT hardware failures and best practices for prevention
- Summary of process and thread knowledge points 1
- mysql 创建索引的三种方式
- [MySQL] historical cumulative de duplication of multiple indicators
- DocuWare 移动劳动力解决方案可帮助您构建新的生产力模式:随时随地、任何设备
- Flink SQL Hudi 实战
猜你喜欢

Flask reports an error: pymysq1.err OperationalError:(1054, “Unknown column ‘None‘ in ‘field list‘“)

【Leetcode-滑动窗口问题】

Univariate function integration 1__ Indefinite integral

mysql分表之后怎么平滑上线?

可视化全链路日志追踪

The digitalization of the consumer industry is upgraded to "rigid demand", and weiit's new retail SaaS empowers enterprises!

Google play APK uploads other international app stores

Canal real-time parsing MySQL binlog data practice

How to deal with the time, scope and cost constraints in the project?

过去10年的10起重大网络安全事件
随机推荐
SQL injection of DVWA
PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
vm options、program arguments、environment property
Flink SQL Hudi actual combat
Docker compose install MySQL
Canal real-time parsing MySQL binlog data practice
可视化全链路日志追踪
Transfer: cognitive subculture
Cookies and sessions
地下水、土壤、地质、环境人看过来
Hilbert transform and instantaneous frequency
Docker-compose安装mysql
RHCE command practice (II)
C language bracket matching (stack bracket matching C language)
Flink SQL Hudi 实战
一元函数积分学之1__不定积分
RHCE命令练习(二)
[MySQL] historical cumulative de duplication of multiple indicators
Y80. Chapter 4 Prometheus big factory monitoring system and practice -- Kube state metrics component introduction and monitoring extension (XI)
Linux redis source code installation