api7 / apisix-mesh-agent

Apache License 2.0
78 stars 10 forks source link

The istio virtual service doesn't work #79

Open anonymous-zx opened 2 years ago

anonymous-zx commented 2 years ago

The attched picture shows a simple topo. A nginx proxy service will send request to service: nginx-backend which has 2 versions of pod. When the virtual-service and dest-rule are applied, try to get routes from etcd we have:

$ ETCDCTL_API=3 etcdctl get /apisix/routes --prefix --endpoints=10.64.103.216:17739 | grep testv
{"uris":["/test2*"],"name":"\u003canon\u003e#nginx-test.app:80#80","id":"e6014f0f","priority":999,"hosts":["nginx-test.app.svc.cluster.local"],"vars":[["connection_original_dst","~~","80$"]],"upstream_id":"24b015e3","status":1}

And curl the nginx-proxy, the route doesn't work. (The response distinguishes in the HTTP header - version.) qts-demo

virtual-service.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: nginx-uri
spec:
  hosts:
  - nginx-test
  http:
  - match:
    - uri:
        prefix: /test1
    route:
    - destination:
        host: nginx
        subset: v1
  - match:
    - uri:
       prefix: /test2
    route:
    - destination:
        host: nginx
        subset: v2

dest-rule.yaml

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx
spec:
  host: nginx
  trafficPolicy:
    loadBalancer:
      simple: RANDOM
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

nginx-proxy.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf
data:
  httpbin.conf: |
    server {
        listen 80 reuseport;
        location / {
            proxy_pass http://nginx-backend;
        }
    }
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx-proxy
spec:
  volumes:
  - name: conf
    configMap:
      name: nginx-conf
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
      protocol: TCP
      name: http
    volumeMounts:
    - name: conf
      mountPath: /etc/nginx/conf.d
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-proxy
spec:
  selector:
    app: nginx-proxy
  ports:
  - name: http
    targetPort: 80
    port: 80
    protocol: TCP

nginx-v1.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-backend-conf
data:
  httpbin.conf: |
    server {
        listen 80 reuseport;
        server_name nginx;
        location / {
            add_header version v1 always;   // To distinguish
        }
    }
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-v1
  labels:
    app: nginx
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      version: v1
  template:
    metadata:
      labels:
        app: nginx
        version: v1
    spec:
      volumes:
      - name: conf
        configMap:
          name: nginx-backend-conf
      containers:
      - name: nginx
        image: nginx
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          protocol: TCP
          name: http
        volumeMounts:
        - name: conf
          mountPath: /etc/nginx/conf.d
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-backend
spec:
  selector:
    app: nginx
  ports:
  - name: http
    targetPort: 80
    port: 80
    protocol: TCP

nginx-v2.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-backend-conf2
data:
  httpbin.conf: |
    server {
        listen 80 reuseport;
        server_name nginx;
        location / {
            add_header version v2 always;    // To distinguish
        }
    }
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-v2
  labels:
    app: nginx
    version: v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      version: v2
  template:
    metadata:
      labels:
        app: nginx
        version: v2
    spec:
      volumes:
      - name: conf
        configMap:
          name: nginx-backend-conf2
      containers:
      - name: nginx
        image: nginx
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          protocol: TCP
          name: http
        volumeMounts:
        - name: conf
          mountPath: /etc/nginx/conf.d
tokers commented 2 years ago

Currently the traffic-split is not implemented well, there is a gap we have to cross between the xds and apisix traffic-split plugin.