Home > Blockchain >  after i config the vs and dr, it worked in default ns, but other ns doesn't worked
after i config the vs and dr, it worked in default ns, but other ns doesn't worked

Time:10-28

  1. What am i trying to achieve

i am trying to access flow dyeing

  1. what am i expecting to get out

when i visit the testaaa with header, then route to testaaa-<header-branch>, and it will pass the header route to the testbbb-<header-branch>, use curl "http://gateway:gatewayport/" --header 'project-version: release-v1', i hope it can return release-v1

  1. What did i get out (include error messages)

no error, but it did not work, i get the response of the poll of these pods what i deployed

  1. What else have you tried?

i have tried to move the server to default ns, it worked

  1. What do i think is causing it?

maybe my yaml is wrong, i think

this is my configuration yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: gateway
  namespace: test-istio
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: testaaa
  namespace: test-istio
spec:
  gateways:
    - gateway
  hosts:
    - "*"
  http:
    - match:
        - headers:
            project-version:
              exact: release-v1
      route:
        - destination:
            host: testaaa.test-istio.svc.cluster.local
            subset: release-v1
    - route:
        - destination:
            host: testaaa.test-istio.svc.cluster.local
            subset: release
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: testaaa
  namespace: test-istio
spec:
  host: testaaa.test-istio.svc.cluster.local
  subsets:
    - labels:
        version: release
      name: release
    - labels:
        version: release-v1
      name: release-v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: testbbb
  namespace: test-istio
spec:
  hosts:
    - testbbb.test-istio.svc.cluster.local
  http:
    - match:
        - headers:
            project-version:
              exact: release-v1
      route:
        - destination:
            host: testbbb.test-istio.svc.cluster.local
            subset: release-v1
    - route:
        - destination:
            host: testbbb.test-istio.svc.cluster.local
            subset: release
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: testbbb
  namespace: test-istio
spec:
  host: testbbb.test-istio.svc.cluster.local
  subsets:
    - labels:
        version: release
      name: release
    - labels:
        version: release-v1
      name: release-v1
---
  1. after i use curl, i got this
[root@k3s-release-server1 ~]# curl  "http://10.1.4.5:31380/" --header 'project-version: release-v1'
release-v1[root@k3s-release-server1 ~]# curl  "http://10.1.4.5:31380/" --header 'project-version: release-v1'
release[root@k3s-release-server1 ~]# curl  "http://10.1.4.5:31380/" --header 'project-version: release-v1'
release[root@k3s-release-server1 ~]# curl  "http://10.1.4.5:31380/" --header 'project-version: release-v1'
release-v1[root@k3s-release-server1 ~]# curl  "http://10.1.4.5:31380/" --header 'project-version: release-v1'
release[root@k3s-release-server1 ~]# curl  "http://10.1.4.5:31380/" --header 'project-version: release-v1'
release-v1[root@k3s-release-server1 ~]# curl  "http://10.1.4.5:31380/" --header 'project-version: release-v1'
release

maybe it return release-v1, maybe release, [plus: this result is label of testbbb server]

CodePudding user response:

my fault

i forgot to enable the istio inject, and service needs to add a protocol, so my yaml change to this

apiVersion: v1
kind: Service
...
spec:
  selector:
   ...
  ports:
      ...
      appProtocol: HTTP
---
apiVersion: apps/v1
kind: Deployment
metadata:
   ...
spec:
   ...
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: 'true'

then use this config to test, it worked

[root@k3s-release-server1 ~]# curl "http://<ingressgateway>/" --header 'project-version: release-v1' -w '\n'
release-v1
[root@k3s-release-server1 ~]# curl "http://<ingressgateway>/" --header 'project-version: release' -w '\n'
release
[root@k3s-release-server1 ~]# curl "http://<ingressgateway>/" --header 'project-version: release-v3' -w '\n'
release
[root@k3s-release-server1 ~]#
  • Related