Rancher中使用Istio流量分配

2020-09-18  本文已影响0人  OPS_Joy
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-v1
  namespace: joy-ns
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
      version: v1
  template:
    metadata:
      labels:
        app: myapp
        version: v1
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v1
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 80
-----
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-v2
  namespace: joy-ns
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
      version: v2
  template:
    metadata:
      labels:
        app: myapp
        version: v2
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v2
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 80

service文件

apiVersion: v1
kind: Service
metadata:
  name: myappv1-svc
  namespace: joy-ns
  labels:
    app: myapp
    version: v1
spec:
  selector:
    app: myapp
    version: v1
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
-----
apiVersion: v1
kind: Service
metadata:
  name: myappv2-svc
  namespace: joy-ns
  labels:
    app: myapp
    version: v2
spec:
  selector:
    app: myapp
    version: v2
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80

通用service

apiVersion: v1
kind: Service
metadata:
  name: myapp-svc
  namespace: joy-ns
  labels:
    app: myapp
spec:
  selector:
    app: myapp
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80

创建所有yaml

kubectl apply -f .
[root@harbor myapp]# kubectl get pods -n joy-ns
NAME                        READY   STATUS    RESTARTS   AGE
busybox-65fd4885b7-hjfx9    2/2     Running   0          17h
myapp-v1-6f6788f845-r9cpm   2/2     Running   0          19h
myapp-v2-5c98456b77-r9z7r   2/2     Running   0          19h
[root@harbor myapp]# kubectl get svc -n joy-ns
NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
busybox       ClusterIP   None            <none>        42/TCP    17h
myapp-svc     ClusterIP   10.43.111.247   <none>        80/TCP    17h
myappv1-svc   ClusterIP   10.43.175.13    <none>        80/TCP    17h
myappv2-svc   ClusterIP   10.43.21.36     <none>        80/TCP    17h

进入客户端访问
使用wget -q -O - http://myapp-svc不停刷新

图片.png
可以看到默认情况下,应该是轮询状态50%分配。
现在通过启用istio虚拟服务,配置权重比例的路由
虚拟service文件
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myapp-svc-vt
  namespace: joy-ns
spec:
  hosts:
  - myapp-svc
  http:
  - route:
    - destination:
        host: myappv1-svc
      weight: 90
    - destination:
        host: myappv2-svc
      weight: 10

创建yaml,查看


图片.png
图片.png
上一篇下一篇

猜你喜欢

热点阅读