demon下
https://gitee.com/jbjb123/istio-demon.git
自动注入
kubectl label namespace opx istio-injection=enabled
取消
istio-injection=disabled
暴露网关out-api.yaml
tee out-api.yaml <<-'EOF'
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:
- "*"
EOF
查看一下网关暴露的ip
[root@master-63 test]# kubectl get svc -n istio-system istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.106.170.129 <pending> 15020:25264/TCP,80:5732/TCP,443:42105/TCP,31400:53129/TCP,15443:18269/TCP 16d
准备V1版本
tee v1.yaml <<-'EOF'
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
---
apiVersion: v1
kind: Service
metadata:
name: http-v1
namespace: opx
spec:
type: NodePort
selector:
server: http-v1
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
nodePort: 30090
EOF
准备V2版本
tee v2.yaml <<-'EOF'
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
---
apiVersion: v1
kind: Service
metadata:
name: http-v2
namespace: opx
spec:
type: NodePort
selector:
server: http-v2
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
nodePort: 30092
EOF
最后VirtualService添加权重
tee gat.yaml <<-'EOF'
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: api-gateway-ha
namespace: opx
spec:
hosts:
- "*"
gateways:
- out-api-gateway
http:
- route:
- destination:
host: http-v1
#subset: v1
weight: 90
- destination:
host: http-v2
#subset: v2
weight: 10
EOF
打入流量测试是否生效
[root@ceph194 ~]# while sleep 1; do curl 10.98.2.62:5732; done
v22222222222222
v22222222222222
v11111111111111
v22222222222222
v22222222222222
v22222222222222
v22222222222222
v22222222222222
v22222222222222
v22222222222222
查看virtualservice 和 gateway
[root@master-63 test]# kubectl get gateway -n opx
NAME AGE
out-api-gateway 66m
[root@master-63 test]# kubectl get virtualservice -n opx
NAME GATEWAYS HOSTS AGE
api-gateway-ha [out-api-gateway] [*] 53m