istio實現對外暴露服務

一、確認istio-ingressgateway是否有對外的IPnode

kubectl get  service istio-ingressgateway -n istio-system

若是 EXTERNAL-IP 有值(IP 地址或主機名),則說明您的環境具備可用於 Ingress 網關的外部負載均衡器。若是 EXTERNAL-IP 值是 <none>(或一直是 <pending> ),則說明可能您的環境並無爲 Ingress 網關提供外部負載均衡器的功能。nginx

能夠經過如下方法添加外部IPwindows

kubectl edit  service istio-ingressgateway -n istio-system

kubectl get  service istio-ingressgateway -n istio-system

 

 2、創建deployment、service、Gateway、VirtualServiceapi

1)新建nginx-istio-test.yaml瀏覽器

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-app
spec:
  replicas: 1
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        app: nginx-app
    spec:
      containers:
        - name: nginx-app
          image: nginx
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
  labels:
    svcname: nginx-svc
spec:
  ports:
  - port: 8088
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-app

---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: nginx-gateway
spec:
  selector:
    istio: ingressgateway # use Istio default gateway implementation
  servers:
  - port:
      number: 80
      name: nginx-http
      protocol: HTTP
    hosts:
    - istio-nginx.boshen.com

---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-vs
spec:
  hosts:
  - istio-nginx.boshen.com
  gateways:
  - nginx-gateway
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        port:
          number: 8088
        host: nginx-svc

在Gateway中app

VirtualService 映射的就是 Envoy 中的 Http Route Table,你們能夠注意到上面的 VirtualService 配置文件中有一個 gateways 字段,若是有這個字段,就表示這個 Http Route Table 是綁在 ingressgateway 的 Listener 中的;若是沒有這個字段,就表示這個 Http Route Table 是綁在 Istio 所管理的全部微服務應用的 Pod 上的。負載均衡

2)部署yamlide

kubectl apply -f nginx-istio-test.yaml

3)在k8s的master節點和node節點的/etc/hosts裏面加上如下內容微服務

 

4)在windows機器上的C:\Windows\System32\drivers\etc\hosts裏面加上spa

5)在瀏覽器訪問:http://istio-nginx.boshen.com/

相關文章
相關標籤/搜索