Istio網(wǎng)關(guān)Gateway概述
Istio網(wǎng)關(guān)Gateway是一個負(fù)責(zé)處理南北向流量的組件,它通常會暴露服務(wù)網(wǎng)格內(nèi)部的服務(wù),以便外部的請求能夠訪問到服務(wù)網(wǎng)格中的服務(wù)。Istio網(wǎng)關(guān)Gateway支持多種協(xié)議,包括HTTP、HTTPS和GRPC等。
在Istio網(wǎng)關(guān)Gateway中,每個服務(wù)器都包含一個或多個端口,每個端口都定義了一種協(xié)議和相應(yīng)的配置。Istio網(wǎng)關(guān)Gateway還可以定義多個TLS證書,以便對傳輸?shù)臄?shù)據(jù)進(jìn)行加密和解密。
在配置Istio網(wǎng)關(guān)Gateway時,我們需要指定其所使用的負(fù)載均衡算法和服務(wù)發(fā)現(xiàn)機制。Istio網(wǎng)關(guān)Gateway支持多種服務(wù)發(fā)現(xiàn)機制,包括Kubernetes服務(wù)發(fā)現(xiàn)、Consul服務(wù)發(fā)現(xiàn)和Eureka服務(wù)發(fā)現(xiàn)等。
先來部署有TLS的網(wǎng)關(guān)。

首選來生成密鑰對,-keyout是生成私鑰。-out是公鑰,生成的密鑰對。生成好了要放在指定的目錄下,在/etc/istio/ingressgateway-certs/。
[root@k8s-master ~]# mkdir -p /etc/istio/ingressgateway-certs
[root@k8s-master ~]# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/istio/ingressgateway-certs/mykey.key -out /etc/istio/ingressgateway-certs/mycrt.crt -subj "/CN=mytest/O=my-test"
Generating a 2048 bit RSA private key
..............................................................................+++
........................+++
writing new private key to '/etc/istio/ingressgateway-certs/mykey.key'
-----
[root@k8s-master ~]# ls /etc/istio/ingressgateway-certs
mycrt.crt mykey.key
這個證書并不是合法的CA頒發(fā)的,而是我們自己生成的。
2.創(chuàng)建tls類型的secret
[root@k8s-master ~]# kubectl create secret generic istio-ingressgateway-certs --from-file /etc/istio/ingressgateway-certs/mykey.key --from-file /etc/istio/ingressgateway-certs/mycrt.crt -n istio
這里的證書正常情況下是CA幫我們頒發(fā)的,只不過我們這里并沒有使用到CA。
serverCertificate: /etc/istio/ingressgateway-certs/mycrt.crt
privateKey: /etc/istio/ingressgateway-certs/mykey.key
?
?
?
多套證書,基于多個域名
其實也就是兩套證書,兩套證書分配給不同的域名。?
上面是直接服務(wù)器端生成了公鑰和私鑰。如果是生產(chǎn)環(huán)境那么就需要去購買證書,購買證書可以到阿里云等廠商。
前提
- EKS集群可用
- istio-gateway可用
創(chuàng)建TLS證書secret
kubectl create secret generic shanhaitls-credential -n istio-system \
--from-file=cert=$Path/certs/server.cer \
--from-file=key=$Path/certs/server.key
Gateway添加TLS配置
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: swbom-g-gateway
namespace: istio-system
spec:
selector:
istio: ingressgateway # use Istio default gateway implementation
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "swbom-dev-g.shanhai.huawei.com"
- "swbom-g-test-kuboard-elb.shanhai.huawei.com"
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
credentialName: shanhaitls-credential # must be the same as secret
hosts:
- "swbom-dev-g.shanhai.huawei.com"
- "swbom-g-test-kuboard-elb.shanhai.huawei.com"
---
?Gateway配置示例
以下是一個使用Istio Gateway進(jìn)行南北流量管理的示例:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- my-service.com
tls:
mode: SIMPLE
serverCertificate: /etc/certs/server.pem
privateKey: /etc/certs/private_key.pem
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- my-service.com
tls:
mode: SIMPLE
serverCertificate: /etc/certs/server.pem
privateKey: /etc/certs/private_key.pem
- port:
number: 8443
name: https-admin
protocol: HTTPS
hosts:
- my-admin.com
tls:
mode: SIMPLE
serverCertificate: /etc/certs/server.pem
privateKey: /etc/certs/private_key.pem
- port:
number: 8080
name: grpc
protocol: GRPC
hosts:
- my-service.com
tls:
mode: SIMPLE
serverCertificate: /etc/certs/server.pem
privateKey: /etc/certs/private_key.pem
在上述示例中,我們首先定義了一個名為my-gateway的Gateway對象。該對象有一個標(biāo)簽選擇器istio: ingressgateway,用于將其指定為Istio Ingress Gateway。
在該Gateway對象中,我們定義了四個服務(wù)器,分別處理不同的端口和協(xié)議。文章來源:http://www.zghlxwxcb.cn/news/detail-612584.html
其中,第一個服務(wù)器用于處理HTTP流量,第二個服務(wù)器用于處理HTTPS流量,第三個服務(wù)器用于處理HTTPS管理員流量,第四個服務(wù)器用于處理GRPC流量。每個服務(wù)器都定義了一個名為port的子對象,用于指定其所使用的端口、協(xié)議和端口名稱。每個服務(wù)器還定義了一個名為hosts的子對象,用于指定其所支持的主機名。此外,每個服務(wù)器還定義了一個名為tls的子對象,用于指定其所使用的TLS證書的相關(guān)配置。文章來源地址http://www.zghlxwxcb.cn/news/detail-612584.html
到了這里,關(guān)于Istio網(wǎng)關(guān)Gateway 啟用TLS的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!