本文主要是介绍备考ICA----Istio实验5---流量转移 TCP Traffic Shifting 实验,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
备考ICA----Istio实验5—流量转移 TCP Traffic Shifting 实验
1. 应用部署
1.1 测试服务部署
该服务通过标签app: tcp-echo选择服务,服务tcp-echo存在2个版本,分别是v1和v2
istio/samples/tcp-echo/tcp-echo-services.yaml
# Copyright 2018 Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.apiVersion: v1
kind: Service
metadata:name: tcp-echolabels:app: tcp-echoservice: tcp-echo
spec:ports:- name: tcpport: 9000- name: tcp-otherport: 9001# Port 9002 is omitted intentionally for testing the pass through filter chain.selector:app: tcp-echo
---
apiVersion: apps/v1
kind: Deployment
metadata:name: tcp-echo-v1labels:app: tcp-echoversion: v1
spec:replicas: 1selector:matchLabels:app: tcp-echoversion: v1template:metadata:labels:app: tcp-echoversion: v1spec:containers:- name: tcp-echoimage: docker.io/istio/tcp-echo-server:1.2imagePullPolicy: IfNotPresentargs: [ "9000,9001,9002", "one" ]ports:- containerPort: 9000- containerPort: 9001
---
apiVersion: apps/v1
kind: Deployment
metadata:name: tcp-echo-v2labels:app: tcp-echoversion: v2
spec:replicas: 1selector:matchLabels:app: tcp-echoversion: v2template:metadata:labels:app: tcp-echoversion: v2spec:containers:- name: tcp-echoimage: docker.io/istio/tcp-echo-server:1.2imagePullPolicy: IfNotPresentargs: [ "9000,9001,9002", "two" ]ports:- containerPort: 9000- containerPort: 9001
部署服务
kubectl apply -f istio/samples/tcp-echo/tcp-echo-services.yaml
1.2 部署测试容器
这个sleep容器是为了通过它执行测试命令
istio/samples/sleep/sleep.yaml
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.##################################################################################################
# Sleep service
##################################################################################################
apiVersion: v1
kind: ServiceAccount
metadata:name: sleep
---
apiVersion: v1
kind: Service
metadata:name: sleeplabels:app: sleepservice: sleep
spec:ports:- port: 80name: httpselector:app: sleep
---
apiVersion: apps/v1
kind: Deployment
metadata:name: sleep
spec:replicas: 1selector:matchLabels:app: sleeptemplate:metadata:labels:app: sleepspec:terminationGracePeriodSeconds: 0serviceAccountName: sleepcontainers:- name: sleepimage: curlimages/curlcommand: ["/bin/sleep", "infinity"]imagePullPolicy: IfNotPresentvolumeMounts:- mountPath: /etc/sleep/tlsname: secret-volumevolumes:- name: secret-volumesecret:secretName: sleep-secretoptional: true
部署测试容器
kubectl apply -f istio/samples/sleep/sleep.yaml
2. 流量转移
2.1 100%流量到V1
2.1.1 部署Gw,Dr,Vs资源
istio/samples/tcp-echo/tcp-echo-all-v1.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:name: tcp-echo-gateway
spec:selector:istio: ingressgatewayservers:- port:number: 31400name: tcpprotocol: TCPhosts:- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:name: tcp-echo-destination
spec:host: tcp-echosubsets:- name: v1labels:version: v1- name: v2labels:version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:name: tcp-echo
spec:hosts:- "*"gateways:- tcp-echo-gatewaytcp:- match:- port: 31400route:- destination:host: tcp-echoport:number: 9000subset: v1
部署gw,dr,vs
kubectl apply -f istio/samples/tcp-echo/tcp-echo-all-v1.yaml
2.1.2 访问测试
可以看到所有流量都被转发到v1上
export GATEWAY_URL=`kubectl get svc -n istio-system istio-ingressgateway | awk 'IF NR!=1{print $4}'`
for i in {1..20};do kubectl exec deploy/sleep -- sh -c "(date; sleep 1) | nc $GATEWAY_URL 31400";done
2.2 80%流量v1,20%流量v2
2.2.1 部署vs
istio/samples/tcp-echo/tcp-echo-20-v2.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:name: tcp-echo
spec:hosts:- "*"gateways:- tcp-echo-gatewaytcp:- match:- port: 31400route:- destination:host: tcp-echoport:number: 9000subset: v1weight: 80- destination:host: tcp-echoport:number: 9000subset: v2weight: 20
部署
kubectl apply -f istio/samples/tcp-echo/tcp-echo-20-v2.yaml
2.2.2 访问测试
可以看到20个包里有4个被分配到了v2上
for i in {1..20};do kubectl exec deploy/sleep -- sh -c "(date; sleep 1) | nc $GATEWAY_URL 31400";done
总的来说TCP Traffice Shifting的实验和之前DestinationRule的实验异曲同工,一样也是通过DestinationRule定义了2个subnet,再通过vs的weight来配置转发的权重
至此流量转移 TCP Traffic Shifting 实验完成
这篇关于备考ICA----Istio实验5---流量转移 TCP Traffic Shifting 实验的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!