如何使 Google Cloud 运行 使用 IPv4 而不是 IPv6 到容器应用程序
How to make Google Cloud Run to use IPv4 instead of IPv6 to container app
我刚刚使用云 运行 服务在 Google 云上设置了一个基于 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 地址,那么网站可以正常工作。
有没有办法让云 运行 服务对 container/app 使用 IPv4?我不介意 client <-> Cloud Run
级别的 IPv6。
我的云 运行 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
据我所知,IPv6 仅在全局负载均衡器上受支持。此负载均衡器代理连接并将其转换为 IPv4 以便内部访问 Google Network.Thereby,使用 IPv6 直接访问云 运行 似乎是不可能的。
不过,一切都在进行中,尤其是在负载平衡方面,它可以解决您的问题。可能会在 4 月份的 Cloud Next 上发布公告。敬请期待!
对于云 运行 <=> 用户浏览器之间的连接: 您目前无法禁用 IPv6 堆栈。
(正如 Guillaume 所说,即将推出的对可配置云 HTTPS 负载均衡器的支持将解决您的问题——事实上,IPv4 是 GCLB 的默认设置,如果您希望 GCLB 使用 IPv6,则明确需要配置 IPv6 地址) .
对于 Cloud 运行 Service <=> Cloud 运行 Service 之间的连接: 您应该在客户端完全控制您连接的 IP边.
比如在客户端,
- 您可以使用它们的选项强制程序使用 IPv4,例如
curl --ipv4
.
我刚刚使用云 运行 服务在 Google 云上设置了一个基于 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 地址,那么网站可以正常工作。
有没有办法让云 运行 服务对 container/app 使用 IPv4?我不介意 client <-> Cloud Run
级别的 IPv6。
我的云 运行 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
据我所知,IPv6 仅在全局负载均衡器上受支持。此负载均衡器代理连接并将其转换为 IPv4 以便内部访问 Google Network.Thereby,使用 IPv6 直接访问云 运行 似乎是不可能的。
不过,一切都在进行中,尤其是在负载平衡方面,它可以解决您的问题。可能会在 4 月份的 Cloud Next 上发布公告。敬请期待!
对于云 运行 <=> 用户浏览器之间的连接: 您目前无法禁用 IPv6 堆栈。
(正如 Guillaume 所说,即将推出的对可配置云 HTTPS 负载均衡器的支持将解决您的问题——事实上,IPv4 是 GCLB 的默认设置,如果您希望 GCLB 使用 IPv6,则明确需要配置 IPv6 地址) .
对于 Cloud 运行 Service <=> Cloud 运行 Service 之间的连接: 您应该在客户端完全控制您连接的 IP边.
比如在客户端,
- 您可以使用它们的选项强制程序使用 IPv4,例如
curl --ipv4
.