简体   繁体   English

无法使用 Service 和 ingress 向外部公开 pod

[英]Not able to expose pod for outside using Service and ingress

I created a pod for mongodb and deployment files looks like:我为 mongodb 创建了一个 pod,部署文件如下所示:

The persistent volume claim is defined as:持久卷声明定义为:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mongodb-data-claim
  annotations:
    volume.beta.kubernetes.io/storage-class: vmfs1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

The stateful deployment yaml :有状态部署 yaml :

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb
spec:
  serviceName: "mongodb"
  selector:
    matchLabels:
      app: mongodb
  replicas: 1
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      volumes:
       - name: mongodb-data
         persistentVolumeClaim:
           claimName: mongodb-data-claim
      containers:
        - name: mongodb       
          image: imagefromInternalRepo/mongo:4.0.12
          command:
            - mongod
            - --bind_ip
            - 0.0.0.0
          volumeMounts:
             - name: mongodb-data
               mountPath: /data/db
          ports:
            - containerPort: 27017

the service yaml is:服务 yaml 是:

apiVersion: v1
kind: Service
metadata:
  name: mongodb
  labels:
    app: mongodb
spec:
  type: NodePort
  ports:
    - port: 27017
      targetPort: 27017
      nodePort: 32017
      protocol: TCP
      name: http
  selector:
    app: mongodb

And the ingress yaml is:入口 yaml 是:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-mongodb
spec:
  rules:
    - host: "bb-mongo-db.namespace.com"
      http:
        paths:
          - path: /
            backend:
              serviceName: mongodb
              servicePort: 32017
  tls:
    - hosts:
      - "bb-mongo-db.namespace.com"

The pod is up and running. Pod 已启动并正在运行。 But when I am trying the hit the url bb-mongo-db.namespace.com, I am getting 503: service unavailable.但是,当我尝试点击 url bb-mongo-db.namespace.com 时,我收到 503: 服务不可用。

I am new to this.Please help me with this.我是新手。请帮我解决这个问题。

If you're using Nginx Ingress it doesn't support TCP/UDP services out of the box, you're trying to reach MongoDB via Http which doesn't work, to configure TCP/UDP for nginx ingress you can use this work around:如果您使用的是 Nginx Ingress,它不支持开箱即用的 TCP/UDP 服务,您正在尝试通过 Http 访问 MongoDB,但它不起作用,要为 Nginx Ingress 配置 TCP/UDP,您可以使用此解决方法:

https://kubernetes.github.io/ingress-nginx/user-uide/exposing-tcp-udp-services/ https://kubernetes.github.io/ingress-nginx/user-uide/exposing-tcp-udp-services/

https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/tcp-udp https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/tcp-udp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 使用 Ingress 时 pod 无法连接到 MongoDB - Python pod can't connect to MongoDB when using Ingress 如何在Kubernetes集群之外公开“基于选举的主从”服务? - How to expose an “election-based master and secondaries” service outside Kubernetes cluster? 如何在 Kubernetes 中公开服务 - How to expose a service in Kubernetes 使用群集外的StatefulSets在Kubernetes上公开MongoDB - Expose MongoDB on Kubernetes with StatefulSets outside cluster 如何将 mongo 容器暴露在覆盖网络之外? - How to expose mongo containers to outside of the overlay network? 入口没有为 mongo 创建地址,但正在创建外部服务 - Ingress not creating address for mongo, but external service is creating 无法将osgi服务bean作为类未接口公开 - unable to expose osgi service bean as class not interface 如何在 kubernetes 之外的 statefulset 中公开 mongodb - How can I expose mongodb in a statefulset outside kubernetes 可通过本地主机访问带有 Mongo 的 Pod,但不能访问服务名称 - Pod with Mongo reachable via localhost but not service name 一个 pod 中的 Springboot 应用程序无法通过 Openshift 连接到另一个 pod 上的 mongodb - Springboot application in one pod not able to connect to mongodb on another pod through Openshift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM