欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > istio从入门到精通(1)

istio从入门到精通(1)

2025/3/11 21:00:29 来源:https://blog.csdn.net/weixin_43806846/article/details/146081984  浏览:    关键词:istio从入门到精通(1)

1、以单个的nginx举例

部署nginx服务

# nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx
spec:replicas: 2selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.19.0ports:- containerPort: 80
---
# nginx-service.yaml
apiVersion: v1
kind: Service
metadata:name: nginx
spec:selector:app: nginxports:- protocol: TCPport: 80targetPort: 80
kubectl apply -f nginx.yml

启用istio

kubectl label namespace default istio-injection=enabled

我们需要重新部署nginx服务

kubectl delete -f nginx.yaml
kubectl apply -f nginx.yaml

我们需要部署istio gateway 和vs服务

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:name: nginx-gateway
spec:selector:istio: ingressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- "*"
---
# nginx-virtualservice.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:name: nginx
spec:hosts:- "*"gateways:- nginx-gatewayhttp:- match:- uri:prefix: /route:- destination:host: nginxport:number: 80

使用 kubectl 部署 Gateway 和 VirtualService:

kubectl apply -f nginx-gateway.yaml
kubectl apply -f nginx-virtualservice.yaml

访问 Nginx 服务

kubectl get svc istio-ingressgateway -n istio-system

然后,使用该 IP 地址访问 Nginx:

curl http://<INGRESS_GATEWAY_IP>>

重点注意:
由于上面采用了hosts 字段的作用,我们需要了解其含义

当 hosts 设置为 "*" 时,表示该虚拟服务适用于所有通过 Istio Gateway 的请
求,无论请求的主机或域名是什么。意味着无论客户端请求的是 example.com、foo.bar 还是任何其他域名,Istio 都会将该请求路由到该虚拟服务中定义的规则。

注意事项

安全性:在生产环境中,使用 "*" 可能会带来安全风险,因为它会将所有流量路由到该虚
拟服务。建议明确指定适用的域名。
​优先级:如果有多个虚拟服务匹配同一个请求,Istio 会按照最长匹配原则选择最具体的
规则。例如,hosts: ["example.com"] 的优先级高于 hosts: ["*"]。```

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词