istio 測試域名加埠訪問 gateway tcp轉發
阿新 • • 發佈:2022-04-18
- 需求:nginx 不但可以通過80訪問還可以通過8089訪問
- istio ingressgateway修改建立指定埠的TCP轉發
kubectl get svc -n istio-system kubectl edit svc -n istio-system istio-ingressgateway ... ports: - name: status-port nodePort: 31744 port: 15021 protocol: TCP targetPort: 15021 - name: http2 nodePort: 32086 port:80 protocol: TCP targetPort: 8080 - name: https nodePort: 30277 port: 443 protocol: TCP targetPort: 8443 - name: tcp nodePort: 31512 port: 31400 protocol: TCP targetPort: 31400 - name: tls nodePort: 30806 port: 15443 protocol: TCP targetPort: 15443####新增自定義埠 - name: test8089 ##注意這個name,會在gateway中指定 nodePort: 31518 port: 8089 protocol: TCP targetPort: 31518 ....
- nginx部署及測試
- 部署
apiVersion: v1 #型別為Namespace kind: Namespace #型別為Namespace metadata: name: ns-test #名稱空間名稱 labels: name: label-test #pod標籤 --- apiVersion: apps/v1 kind: Deployment metadata: namespace: ns-test name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: namespace: ns-test name: nginx-service spec: type: ClusterIP selector: app: nginx ports: - name: tcp port: 80 targetPort: 80
k apply -f nginx.yaml
- 部署nginx配置域名加埠訪問
apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: nginx-test-8088-gw namespace: ns-test spec: selector: istio: ingressgateway # use istio default controller servers: - port: number: 8089 name: test8089 ##對應svc ingress中的name protocol: HTTP hosts: - "*" --- apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: www-8808-vs namespace: ns-test spec: hosts: - "nginx-test.xxx.com" gateways: - nginx-test-8088-gw http: - match: - uri: prefix: / route: - destination: host: nginx-service port: number: 80