为Google容器引擎配置端口范围映射到container

为Google容器引擎配置端口范围映射到container

本文介绍了为Google容器引擎配置端口范围映射到container.yaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了所有的Google文档,将Docker映像部署到goole运算中(),但我找不到有关google-container-manifest选项的更多信息.

I followed all the google documentation to deploy a docker image into goole compute (this one) but I can't find more informations about google-container-manifest options.

例如,我无法添加端口范围.我尝试过但没有成功:

For example I can't add a port range.I tried that without success :

  ports:
    - containerPort: 80
      hostPort: 80
    - containerPort: 443
      hostPort: 443
    - containerPort: "10000-20000"
      hostPort: "10000-20000"

在哪里可以找到可用于Google容器清单的所有参数?是否可以添加端口范围映射?

Where can we find all parameters we can use for google container manifest ?And is it possible to add a port range mapping ?

Thx

[使用@alex解决方案进行编辑]

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  hostNetwork: true
  containers:
    - name: test1
      image: eu.gcr.io/app-1234/image
      imagePullPolicy: Always

现在docker容器上的所有端口都在Google VM上公开了.

And now all port on docker container are expose on google VM.

别忘了配置网络以暴露所需的所有端口:

Do not forget to configure a network to expose all port you need like that :

gcloud compute networks create test-network

gcloud compute firewall-rules create test-allow-http --allow tcp:80 --network test-network
gcloud compute firewall-rules create test-allow-ssh --allow tcp:22 --network test-network
gcloud compute firewall-rules create test-allow-https --allow tcp:443 --network test-network
gcloud compute firewall-rules create test-allow-video --allow udp:10000-20000,icmp --network test-network

并运行这样的实例:

gcloud compute instances create test-example \
    --image container-vm \
    --metadata-from-file google-container-manifest=containers.yaml \
    --zone europe-west1-b \
    --machine-type n1-standard-2 \
    --network test-network

推荐答案

在该文档页面的下方稍稍提到:

As mentioned a little lower down on that docs page:

不过,关于添加如此广泛的端口,您介意解释您的用例吗?当前,API不支持任意端口范围,仅支持显式端口列表.如果您真正想要的是容器可以使用机器上的所有端口,则可以考虑使用v1.PodSpec中的hostNetwork选项,该选项将直接在主机的网络上运行容器,而无需端口映射.

Regarding adding such a large range of ports, though, would you mind explaining your use case? Currently the API does not support arbitrary port ranges, only lists of explicit ports. If what you really want is for all the ports on the machine to be usable by your container, you might want to consider the hostNetwork option in the v1.PodSpec, which will run your container directly on the host's network with no need for port mapping.

这篇关于为Google容器引擎配置端口范围映射到container.yaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:25