[英]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.