簡體   English   中英

如何讓 Google Cloud Run 使用 IPv4 而不是 IPv6 到容器應用程序

[英]How to make Google Cloud Run to use IPv4 instead of IPv6 to container app

我剛剛使用 Cloud Run 服務在 Google Cloud 上建立了一個基於 NodeJS 的站點。

有兩個 DNS 記錄:A (IPv4) 和 AAAA (IPv6)。 每當我使用 Chrome 訪問該站點時,我的 Chrome 都會選擇 IPv6 地址並且 NodeJS 應用程序很難失敗:

TypeError [ERR_INVALID_URL]: Invalid URL: http://2001:14ba:98ae:1700:****:****:****:****/
  at onParseError (internal/url.js:257:9)
  at new URL (internal/url.js:333:5)

注意:我審查了地址

如果我強制瀏覽器使用 IPv4 地址,則該站點可以正常工作。

有沒有辦法讓 Cloud Run 服務對容器/應用程序使用 IPv4? 我不介意client <-> Cloud Run級別的 IPv6。

我的 Cloud Run YAML 看起來像:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: xxx-dev-app-825af7f
  namespace: 'xxx'
  selfLink: /apis/serving.knative.dev/v1/namespaces/xxx/services/xxx-dev-app-825af7f
  uid: 2d787ef2-39a7-xxx-yyy-zzz
  resourceVersion: AAWfuzEBUYA
  generation: 5
  creationTimestamp: '2020-02-26T18:58:40.504717Z'
  labels:
    cloud.googleapis.com/location: europe-north1
  annotations:
    run.googleapis.com/client-name: gcloud
    serving.knative.dev/creator: pulumi@xxx.iam.gserviceaccount.com
    serving.knative.dev/lastModifier: xxx@cloudbuild.gserviceaccount.com
    client.knative.dev/user-image: gcr.io/xxx/app:4860b1e137457b0e42a1896d7b95e0348d8cd7e4
    run.googleapis.com/client-version: 279.0.0
spec:
  traffic:
  - percent: 100
    latestRevision: true
  template:
    metadata:
      name: xxx-dev-app-825af7f-00005-xoz
      annotations:
        run.googleapis.com/client-name: gcloud
        client.knative.dev/user-image: gcr.io/xxx/app:4860b1e137457b0e42a1896d7b95e0348d8cd7e4
        run.googleapis.com/client-version: 279.0.0
        autoscaling.knative.dev/maxScale: '1000'
    spec:
      timeoutSeconds: 900
      containerConcurrency: 80
      containers:
      - image: gcr.io/xxx/app:4860b1e137457b0e42a1896d7b95e0348d8cd7e4
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: 1000m
            memory: 256Mi
          requests:
            cpu: 200m
            memory: 64Mi
status:
  conditions:
  - type: Ready
    status: 'True'
    lastTransitionTime: '2020-02-29T18:33:33.424Z'
  - type: ConfigurationsReady
    status: 'True'
    lastTransitionTime: '2020-02-29T18:33:28.264Z'
  - type: RoutesReady
    status: 'True'
    lastTransitionTime: '2020-02-29T18:33:33.424Z'
  observedGeneration: 5
  traffic:
  - revisionName: xxx-dev-app-825af7f-00005-xoz
    percent: 100
    latestRevision: true
  latestReadyRevisionName: xxx-dev-app-825af7f-00005-xoz
  latestCreatedRevisionName: xxx-dev-app-825af7f-00005-xoz
  address:
    url: https://xxx.run.app
  url: https://xxx.run.app

AFAIK,僅全局負載均衡器支持 IPv6。 此負載均衡器代理連接並將其轉換為 IPv4,以便內部訪問 Google 網絡。因此,使用 IPv6 直接訪問 Cloud Run 似乎是不可能的。

但是,事情正在進行中,尤其是在負載平衡方面,它可以解決您的問題。 可能會在 4 月的 Cloud Next 上發布公告。 敬請關注!

對於 Cloud Run <=> 用戶瀏覽器之間的連接:您目前無法禁用 IPv6 堆棧。

(正如 Guillaume 所說,即將推出的對可配置雲 HTTPS 負載均衡器的支持將解決您的問題——事實上,IPv4 是 GCLB 的默認設置,如果您想要為您的 GCLB 使用 IPv6,您明確需要配置一個 IPv6 地址)。

對於 Cloud Run Service <=> Cloud Run Service 之間的連接:您應該在客戶端完全控制您連接到的 IP。

例如,在客戶端,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM