还是和之前一样暴露网关先
cat<<END> out-api.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: out-api-gateway
namespace: opx
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
END
cat <<END>test-v1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: http-v1
namespace: opx
labels:
server: http-v1
app: web
spec:
replicas: 1
selector:
matchLabels:
server: http-v1
app: web
template:
metadata:
name: http-v1
labels:
server: http-v1
app: web
spec:
containers:
- name: http-v1
image: registry.cn-shenzhen.aliyuncs.com/jbjb/test:nginx-v01
ports:
- containerPort: 80
END
cat test-v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: http-v2
namespace: opx
labels:
server: http-v2
app: web
spec:
replicas: 1
selector:
matchLabels:
server: http-v2
app: web
template:
metadata:
name: http-v2
labels:
server: http-v2
app: web
spec:
containers:
- name: http-v2
image: registry.cn-shenzhen.aliyuncs.com/jbjb/test:nginx-v01
ports:
- containerPort: 80
暴露svc
cat svc-all.yaml
apiVersion: v1
kind: Service
metadata:
name: http-all
namespace: opx
spec:
type: NodePort
selector:
app: web <<<----通过app标签匹配v1-v2容器
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
nodePort: 30099 <<<------nodePort可以不用,如使用便是轮询负载
最后VirtualService 负责权重 DestinationRule负责细分
cat <<END>vs+dr-88.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: test-vir
namespace: opx
spec:
hosts:
- "*"
gateways:
- out-api-gateway
http:
- route:
- destination:
host: http-all
subset: v1
weight: 90
- destination:
host: http-all
subset: v2
weight: 10
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: test-dr
namespace: opx
spec:
host: http-all
trafficPolicy:
loadBalancer:
simple: RANDOM
subsets:
- name: v1
labels:
server: http-v1 <<----通过标签容器匹配
- name: v2
labels:
server: http-v2 <<----通过标签容器匹配
END
[root@ceph194 ~]# while sleep 1; do curl 10.98.2.62:5732; done
v1111111111111111111
v1111111111111111111
v22222222222222
v1111111111111111111
v1111111111111111111
v1111111111111111111