設定入口閘道¶
Knative 使用共享的入口閘道來服務 Knative 服務網格內的所有傳入流量,即 knative-ingress-gateway
閘道,位於 knative-serving
命名空間下。預設情況下,我們使用 istio-system
命名空間下的 Istio 閘道服務 istio-ingressgateway
作為其底層服務。您可以依照以下步驟,將服務和閘道替換為您自己的。
取代預設的 istio-ingressgateway
服務¶
步驟 1:建立閘道服務和部署實例¶
您需要先建立閘道服務和部署實例來處理流量。假設您將預設的 istio-ingressgateway
自訂為 custom-ingressgateway
,如下所示。
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
components:
ingressGateways:
- name: custom-ingressgateway
enabled: true
namespace: custom-ns
label:
istio: custom-gateway
步驟 2:更新 Knative 閘道¶
更新 knative-serving
命名空間下的閘道實例 knative-ingress-gateway
kubectl edit gateway knative-ingress-gateway -n knative-serving
將標籤選取器替換為您服務的標籤
istio: ingressgateway
對於前面提到的範例 custom-ingressgateway
服務,應該更新為
istio: custom-gateway
如果服務連接埠發生變化 (與 istio-ingressgateway
相比),請相應地更新閘道中的連接埠資訊。
步驟 3:更新閘道 ConfigMap¶
-
更新
knative-serving
命名空間下的閘道 configmapconfig-istio
kubectl edit configmap config-istio -n knative-serving
此命令會開啟您的預設文字編輯器,讓您編輯 config-istio ConfigMap。
apiVersion: v1 data: _example: | ################################ # # # EXAMPLE CONFIGURATION # # # ################################ # ... external-gateways: | - name: knative-ingress-gateway namespace: knative-serving service: istio-ingressgateway.istio-system.svc.cluster.local
-
編輯該檔案,新增
external-gateways
欄位,其中包含您服務的完整 URL。對於前面提到的範例custom-ingressgateway
服務,應該更新為apiVersion: v1 data: external-gateways: | - name: knative-ingress-gateway namespace: knative-serving service: custom-ingressgateway.custom-ns.svc.cluster.local kind: ConfigMap [...]
取代 knative-ingress-gateway
閘道¶
到目前為止,我們自訂了閘道服務,但我們也可能想使用自己的閘道。我們可以按照以下步驟,將預設閘道替換為我們自己的閘道。
步驟 1:建立閘道¶
假設您將預設的 knative-ingress-gateway
閘道替換為 custom-ns
中的 knative-custom-gateway
。首先,建立 knative-custom-gateway
閘道
-
使用以下範本建立 YAML 檔案
其中apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: knative-custom-gateway namespace: custom-ns spec: selector: istio: <service-label> servers: - port: number: 80 name: http protocol: HTTP hosts: - "*"
<service-label>
是用於選取您服務的標籤,例如,ingressgateway
。 -
執行以下命令來套用 YAML 檔案
其中kubectl apply -f <filename>.yaml
<filename>
是您在上一步中建立的檔案名稱。
步驟 2:更新閘道 ConfigMap¶
-
更新
knative-serving
命名空間下的閘道 configmapconfig-istio
kubectl edit configmap config-istio -n knative-serving
此命令會開啟您的預設文字編輯器,讓您編輯 config-istio ConfigMap。
apiVersion: v1 data: _example: | ################################ # # # EXAMPLE CONFIGURATION # # # ################################ # ... external-gateways: | - name: knative-ingress-gateway namespace: knative-serving service: istio-ingressgateway.istio-system.svc.cluster.local
-
編輯該檔案,新增
external-gateways
欄位,其中包含自訂閘道。對於前面提到的範例knative-custom-gateway
,應該更新為apiVersion: v1 data: external-gateways: | - name: knative-custom-gateway namespace: custom-ns service: istio-ingressgateway.istio-system.svc.cluster.local kind: ConfigMap [...]
組態格式應該是
external-gateways: |
- name: <gateway-name>
namespace: <gateway-namespace>
service: <fully-qualified-url-of-istio-ingress-service>