我们可以为没有端口或公开端口的Kubernetes部署创建服务吗?

发布于 2025-01-19 11:38:23 字数 775 浏览 1 评论 0原文

我们可以为没有端口或公开端口的 Kubernetes 部署创建一个服务吗?

我的 k8s 部署没有端口,也没有公开从外部连接的端口。这是一个rabbitmq生产者/消费者应用程序。

下面是它的部署规范。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: reports-bot
spec:
  replicas: 2
  selector:
    matchLabels:
     app: reports-bot
  template:
    metadata:
     labels:
       app: reports-bot
    spec:
      containers:
      - name: reports-bot
        image: devops/reports-bot:latest
        imagePullPolicy: Always
        envFrom:
        - configMapRef:
            name: dependents-config
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: dependents-config
  labels:
    app: rabbitmq
data:
  DEV_HOST: dev-rabbitmq
  DEV_PORT: "5672"
  DEV_USERNAME: admin
  DEV_PASSWORD: admin_1265
  DEV_GPASSWORD: devops

can we create a service for a Kubernetes deployment that does not have a port or exposes a port?

I have k8s deployment which does not have a port and doesn't expose a port to connect from outside. It's a rabbitmq producer/consumer application.

Below this the deployment spec of it.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: reports-bot
spec:
  replicas: 2
  selector:
    matchLabels:
     app: reports-bot
  template:
    metadata:
     labels:
       app: reports-bot
    spec:
      containers:
      - name: reports-bot
        image: devops/reports-bot:latest
        imagePullPolicy: Always
        envFrom:
        - configMapRef:
            name: dependents-config
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: dependents-config
  labels:
    app: rabbitmq
data:
  DEV_HOST: dev-rabbitmq
  DEV_PORT: "5672"
  DEV_USERNAME: admin
  DEV_PASSWORD: admin_1265
  DEV_GPASSWORD: devops

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌倦 2025-01-26 11:38:23

公开部署清单中的端口为系统提供了有关容器使用的网络连接的其他信息,但主要是信息的。在此处未指定端口并不能阻止该端口暴露。在集装箱内部默认“ 0.0.0.0”地址上侦听的任何端口都可以从网络访问。

POD规范中的宣布容器port是可选。即使没有它,您的服务也会知道在基于其目标端口声明的信息中指导请求。

创建服务时,是必要的以定义服务将使用的端口。该端口被映射到服务目标的POD内部的目标端口。向端口中服务的传入请求将转发到POD中的目标端口。如果没有提供目标端口,则使用端口值。

Exposing a port in the deployment manifest gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default "0.0.0.0" address inside a container will be accessible from the network.

Declaring containerPort in Pod specification is optional. Even without it your Service will know where to direct the request based on the info it has declared in its targetPort.

When creating a service, it is necessary to define the port that the service will serve on. This port is mapped to a target port inside the pod that the service targets. Incoming requests to the service in port are forwarded to the target port in the pod. If no target port is provided, then the port value is used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文