是否可以在一个命令中基于新部署创建公开的 kubernetes 服务?

Is it possible to create an exposed kubernetes service based on a new deployment in one command?

我觉得这一定是可能的,但还没有找到关于如何做到这一点的文档。

理想情况下,我想在部署 yaml 文件中添加服务公开详细信息,并且在使用部署 yaml 发出创建命令时,服务会提供主机名和端口。

您可以编写部署清单(如 here) then you can write your Service manifest (like here) and then you can put them in the same file with a --- between them (like here)。这是 YAML 规范的一部分,而不是 Kubernetes 特定的东西。

有关如何编写 Service 和 Deployment 以便它们针对同一组 Pods 的示例,您可以查看 nginx ingress controller 的默认后端的定义以获取灵感here.