閘道
Gateway
描述一個在網格邊緣運作的負載平衡器,接收傳入或傳出的 HTTP/TCP 連線。此規格描述了一組應該公開的埠、要使用的協定類型、負載平衡器的 SNI 設定等等。
例如,以下 Gateway 設定建立一個代理伺服器,作為負載平衡器,公開埠 80 和 9080 (http)、443 (https)、9443(https) 以及用於入口的埠 2379 (TCP)。此閘道將應用於標籤為 app: my-gateway-controller
的 Pod 上執行的代理伺服器。雖然 Istio 會設定代理伺服器監聽這些埠,但使用者有責任確保允許外部流量進入網格的這些埠。
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-gateway
namespace: some-config-namespace
spec:
selector:
app: my-gateway-controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- uk.bookinfo.com
- eu.bookinfo.com
tls:
httpsRedirect: true # sends 301 redirect for http requests
- port:
number: 443
name: https-443
protocol: HTTPS
hosts:
- uk.bookinfo.com
- eu.bookinfo.com
tls:
mode: SIMPLE # enables HTTPS on this port
serverCertificate: /etc/certs/servercert.pem
privateKey: /etc/certs/privatekey.pem
- port:
number: 9443
name: https-9443
protocol: HTTPS
hosts:
- "bookinfo-namespace/*.bookinfo.com"
tls:
mode: SIMPLE # enables HTTPS on this port
credentialName: bookinfo-secret # fetches certs from Kubernetes secret
- port:
number: 9080
name: http-wildcard
protocol: HTTP
hosts:
- "*"
- port:
number: 2379 # to expose internal service via external port 2379
name: mongo
protocol: MONGO
hosts:
- "*"
上述的 Gateway 規格描述了負載平衡器的 L4-L6 屬性。然後,可以將 VirtualService
綁定到閘道,以控制到達特定主機或閘道埠的流量轉發。
例如,以下 VirtualService 將 https://uk.bookinfo.com/reviews
、https://eu.bookinfo.com/reviews
、http://uk.bookinfo.com:9080/reviews
、http://eu.bookinfo.com:9080/reviews
的流量分割到內部 reviews 服務的兩個版本(prod 和 qa),埠號為 9080。此外,包含 cookie 「user: dev-123」的請求將被發送到 qa 版本的特殊埠 7777。相同的規則也適用於網格內部對 「reviews.prod.svc.cluster.local」 服務的請求。此規則適用於埠 443、9080。請注意,http://uk.bookinfo.com
會重新導向到 https://uk.bookinfo.com
(即 80 重新導向到 443)。
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: bookinfo-rule
namespace: bookinfo-namespace
spec:
hosts:
- reviews.prod.svc.cluster.local
- uk.bookinfo.com
- eu.bookinfo.com
gateways:
- some-config-namespace/my-gateway
- mesh # applies to all the sidecars in the mesh
http:
- match:
- headers:
cookie:
exact: "user=dev-123"
route:
- destination:
port:
number: 7777
host: reviews.qa.svc.cluster.local
- match:
- uri:
prefix: /reviews/
route:
- destination:
port:
number: 9080 # can be omitted if it's the only port for reviews
host: reviews.prod.svc.cluster.local
weight: 80
- destination:
host: reviews.qa.svc.cluster.local
weight: 20
以下 VirtualService 將到達(外部)埠 27017 的流量轉發到埠 5555 上的內部 Mongo 伺服器。此規則不適用於網格內部,因為閘道清單省略了保留名稱 mesh
。
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: bookinfo-mongo
namespace: bookinfo-namespace
spec:
hosts:
- mongosvr.prod.svc.cluster.local # name of internal Mongo service
gateways:
- some-config-namespace/my-gateway # can omit the namespace if gateway is in same namespace as virtual service.
tcp:
- match:
- port: 27017
route:
- destination:
host: mongo.prod.svc.cluster.local
port:
number: 5555
可以使用主機欄位中的命名空間/主機名稱語法,限制可以綁定到閘道伺服器的虛擬服務集合。例如,以下閘道允許 ns1 命名空間中的任何虛擬服務綁定到它,同時限制只有 ns2 命名空間中具有 foo.bar.com 主機的虛擬服務才能綁定到它。
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-gateway
namespace: some-config-namespace
spec:
selector:
app: my-gateway-controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "ns1/*"
- "ns2/foo.bar.com"
閘道
Gateway 描述一個在網格邊緣運作的負載平衡器,接收傳入或傳出的 HTTP/TCP 連線。
伺服器
Server
描述指定負載平衡器埠上代理伺服器的屬性。例如,
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-ingress
spec:
selector:
app: my-ingressgateway
servers:
- port:
number: 80
name: http2
protocol: HTTP2
hosts:
- "*"
另一個範例
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-tcp-ingress
spec:
selector:
app: my-tcp-ingressgateway
servers:
- port:
number: 27018
name: mongo
protocol: MONGO
hosts:
- "*"
以下是埠 443 的 TLS 設定範例
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: my-tls-ingress
spec:
selector:
app: my-tls-ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- "*"
tls:
mode: SIMPLE
credentialName: tls-cert
埠
Port 描述服務特定埠的屬性。
ServerTLSSettings
ServerTLSSettings.TLSmode
代理伺服器強制執行的 TLS 模式
名稱 | 描述 |
---|---|
PASSTHROUGH | 用戶端提供的 SNI 字串將在 VirtualService TLS 路由中用作比對條件,以確定服務註冊表中的目標服務。 |
SIMPLE | 使用標準 TLS 語意保護連線。在此模式下,在交握期間不會要求提供用戶端憑證。 |
MUTUAL | 使用相互 TLS 保護到下游的連線,方法是提供伺服器憑證進行驗證。在交握期間,也會要求提供用戶端憑證,並且用戶端必須至少傳送一個有效的憑證。 |
AUTO_PASSTHROUGH | 與 passthrough 模式類似,但具有此 TLS 模式的伺服器不需要關聯的 VirtualService 來將 SNI 值對應到註冊表中的服務。目標詳細資訊(例如,服務/子集/埠)編碼在 SNI 值中。代理伺服器將轉發到由 SNI 值指定的上游 (Envoy) 叢集(一組端點)。此伺服器通常用於在不相鄰 L3 網路中的服務之間提供連線,這些服務的各自端點之間沒有直接連線。使用此模式表示來源和目的地都使用 Istio mTLS 來保護流量。 |
ISTIO_MUTUAL | 使用相互 TLS 保護來自下游的連線,方法是提供伺服器憑證進行驗證。與 Mutual 模式相比,此模式使用由 Istio 自動產生的憑證(代表閘道工作負載身分)進行 mTLS 驗證。使用此模式時, |
OPTIONAL_MUTUAL | 與 MUTUAL 模式類似,但用戶端憑證為選用。與 SIMPLE 模式不同,在交握期間仍會明確要求提供用戶端憑證,但不要求用戶端傳送憑證。如果提供用戶端憑證,則會進行驗證。應指定 ca_certificates 以驗證用戶端憑證。 |
ServerTLSSettings.TLSProtocol
TLS 協定版本。
名稱 | 描述 |
---|---|
TLS_AUTO | 自動選擇最佳 TLS 版本。 |
TLSV1_0 | TLS 版本 1.0 |
TLSV1_1 | TLS 版本 1.1 |
TLSV1_2 | TLS 版本 1.2 |
TLSV1_3 | TLS 版本 1.3 |