为 google 容器引擎配置端口范围映射到 containers.yaml
Configure port range mapping into containers.yaml for google container engine
我按照所有 google 文档将 docker 图像部署到 goole compute (this one),但我找不到有关 google-container 的更多信息-清单选项。
例如,我无法添加端口范围。
我试过了,但没有成功:
ports:
- containerPort: 80
hostPort: 80
- containerPort: 443
hostPort: 443
- containerPort: "10000-20000"
hostPort: "10000-20000"
我们在哪里可以找到可用于 google 容器清单的所有参数?
是否可以添加端口范围映射?
感谢
[使用@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 虚拟机上。
不要忘记配置网络以公开您需要的所有端口:
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
正如该文档页面下方提到的那样:
Documentation for the container manifest can be found in the
Kubernetes API Pod Specification. The container VM is running a
simple Kubelet and not the entire Kubernetes control plane, so the
v1.PodSpec
honored by the container VM is limited to containers
,
volumes
, and restartPolicy
.
不过,关于添加如此大范围的端口,您介意解释一下您的用例吗?当前 API 不支持任意端口范围,仅支持显式端口列表。如果你真正想要的是机器上的所有端口都可以被你的容器使用,你可能需要考虑 v1.PodSpec
中的 hostNetwork
选项,它将直接 运行 你的容器在主机的网络上,无需端口映射。
我按照所有 google 文档将 docker 图像部署到 goole compute (this one),但我找不到有关 google-container 的更多信息-清单选项。
例如,我无法添加端口范围。 我试过了,但没有成功:
ports:
- containerPort: 80
hostPort: 80
- containerPort: 443
hostPort: 443
- containerPort: "10000-20000"
hostPort: "10000-20000"
我们在哪里可以找到可用于 google 容器清单的所有参数? 是否可以添加端口范围映射?
感谢
[使用@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 虚拟机上。
不要忘记配置网络以公开您需要的所有端口:
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
正如该文档页面下方提到的那样:
Documentation for the container manifest can be found in the Kubernetes API Pod Specification. The container VM is running a simple Kubelet and not the entire Kubernetes control plane, so the
v1.PodSpec
honored by the container VM is limited tocontainers
,volumes
, andrestartPolicy
.
不过,关于添加如此大范围的端口,您介意解释一下您的用例吗?当前 API 不支持任意端口范围,仅支持显式端口列表。如果你真正想要的是机器上的所有端口都可以被你的容器使用,你可能需要考虑 v1.PodSpec
中的 hostNetwork
选项,它将直接 运行 你的容器在主机的网络上,无需端口映射。