针对TCP流量
1. 创建命名空间
[root@k8s-master01 ~]# kubectl create namespace istio-io-tcp-traffic-shifting
namespace/istio-io-tcp-traffic-shifting created
[root@k8s-master01 ~]#
[root@k8s-master01 ~]#
[root@k8s-master01 ~]# kubectl label namespaces istio-io-tcp-traffic-shifting istio-injection=enabled
namespace/istio-io-tcp-traffic-shifting labeled
[root@k8s-master01 ~]#
[root@k8s-master01 ~]# kubectl describe namespaces istio-io-tcp-traffic-shifting
Name: istio-io-tcp-traffic-shifting
Labels: istio-injection=enabled
kubernetes.io/metadata.name=istio-io-tcp-traffic-shifting
Annotations: <none>
Status: Active
No resource quota.
部署服务器
[root@k8s-master01 istio-1.17.1]# kubectl apply -f samples/tcp-echo/tcp-echo-services.yaml -n istio-io-tcp-traffic-shifting
service/tcp-echo created
[root@k8s-master01 istio-1.17.1]# kubectl get all -n istio-io-tcp-traffic-shifting
NAME READY STATUS RESTARTS AGE
pod/tcp-echo-v1-5f8f8d4ddc-qcfps 2/2 Running 0 60s
pod/tcp-echo-v2-74f8c68f8-wstp4 2/2 Running 0 60s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/tcp-echo ClusterIP 10.110.53.206 <none> 9000/TCP,9001/TCP 63s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/tcp-echo-v1 1/1 1 1 63s
deployment.apps/tcp-echo-v2 1/1 1 1 62s
NAME DESIRED CURRENT READY AGE
replicaset.apps/tcp-echo-v1-5f8f8d4ddc 1 1 1 62s
replicaset.apps/tcp-echo-v2-74f8c68f8 1 1 1 62s
[root@k8s-master01 istio-1.17.1]#
确认tcp-echo服务器处于运行状态,并获取ingress-gateway的端口和IP
[root@k8s-master01 istio-1.17.1]# export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].port}')
[root@k8s-master01 istio-1.17.1]# kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].port}'
31400
[root@k8s-master01 istio-1.17.1]#INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
[root@k8s-master01 istio-1.17.1]# echo $INGRESS_HOST
192.168.30.240
[root@k8s-master01 istio-1.17.1]# for i in {1..10}; do docker run -e INGRESS_HOST=$INGRESS_HOST -e INGRESS_PORT=$INGRESS_PORT -it --rm busybox sh -c "(date;sleep 1) | nc $INGRESS_HOST $INGRESS_PORT"; done
one Thu May 18 08:36:36 UTC 2023
one Thu May 18 08:36:39 UTC 2023
现在把v1版本20%的流量路由到v2版本上去。
[root@k8s-master01 istio-1.17.1]# kubectl apply -f samples/tcp-echo/tcp-echo-20-v2.yaml -n istio-io-tcp-traffic-shifting
virtualservice.networking.istio.io/tcp-echo configured
[root@k8s-master01 istio-1.17.1]# kubectl apply -f samples/tcp-echo/tcp-echo-20-v2.yaml -n istio-io-tcp-traffic-shifting
virtualservice.networking.istio.io/tcp-echo configured
[root@k8s-master01 istio-1.17.1]# for i in {1..10}; do docker run -e INGRESS_HOST=$INGRESS_HOST -e INGRESS_PORT=$INGRESS_PORT
-it --rm busybox sh -c "(date;sleep 1) | nc $INGRESS_HOST $INGRESS_PORT"; doneone Thu May 18 08:44:48 UTC 2023
two Thu May 18 08:44:51 UTC 2023
one Thu May 18 08:44:54 UTC 2023
one Thu May 18 08:44:57 UTC 2023
删除应用和路由规则
[root@k8s-master01 istio-1.17.1]# kubectl delete -f samples/tcp-echo/tcp-echo-all-v1.yaml -n istio-io-tcp-traffic-shifting
gateway.networking.istio.io "tcp-echo-gateway" deleted
destinationrule.networking.istio.io "tcp-echo-destination" deleted
virtualservice.networking.istio.io "tcp-echo" deleted
[root@k8s-master01 istio-1.17.1]# kubectl delete -f samples/tcp-echo/tcp-echo-services.yaml -n istio-io-tcp-traffic-shifting
deployment.apps "tcp-echo-v1" deleted
deployment.apps "tcp-echo-v2" deleted
service "tcp-echo" deleted
[root@k8s-master01 istio-1.17.1]# kubectl delete ns istio-io-tcp-traffic-shifting
namespace "istio-io-tcp-traffic-shifting" deleted
posted on 2023-05-18 16:54 FLOWERS_WAN 阅读(11) 评论(0) 编辑 收藏 举报