我为 mongodb 创建了一个 pod,部署文件如下所示:
持久卷声明定义为:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mongodb-data-claim
annotations:
volume.beta.kubernetes.io/storage-class: vmfs1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
有状态部署 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
服务 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
入口 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"
容器已启动并正在运行。 但是当我尝试点击网址 bb-mongo-db.namespace.com 时,我得到的是 503:服务 不能利用的。
我是新手。请帮我解决这个问题。
如果您使用的是Nginx Ingress,则它不支持开箱即用的TCP/UDP服务,您正在尝试通过Http访问MongoDB,这是不起作用的,要为nginx入口配置TCP/UDP,您可以使用此方法:
https://kubernetes.github.io/ingress-nginx/user-uide/exposing-tcp-udp-services/
https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/tcp-udp