[英]MongoDB in Kubernetes within GCP
I'm trying to deploy mongodb on my k8s cluster as mongodb is my db of choice.我正在尝试在我的 k8s 集群上部署 mongodb,因为 mongodb 是我选择的数据库。 To do that I've config files (very similar to what I did with postgress few weeks ago).
为此,我有配置文件(与几周前我对 postgress 所做的非常相似)。
Here's mongo's deployment k8s object:这是 mongo 的部署 k8s 对象:
apiVersion: apps/v1
kind: Deployment
metadata:
name: panel-admin-mongo-deployment
spec:
replicas: 1
selector:
matchLabels:
component: panel-admin-mongo
template:
metadata:
labels:
component: panel-admin-mongo
spec:
volumes:
- name: panel-admin-mongo-storage
persistentVolumeClaim:
claimName: database-persistent-volume-claim
containers:
- name: panel-admin-mongo
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: panel-admin-mongo-storage
mountPath: /data/db
In order to get into the pod I made a service:为了进入吊舱,我做了一个服务:
apiVersion: v1
kind: Service
metadata:
name: panel-admin-mongo-cluster-ip-service
spec:
type: ClusterIP
selector:
component: panel-admin-mongo
ports:
- port: 27017
targetPort: 27017
And of cource I need a PVC as well:当然,我也需要一个 PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-persistent-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
In order to get to the db from my server I used server deployment object:为了从我的服务器访问数据库,我使用了服务器部署对象:
apiVersion: apps/v1
kind: Deployment
metadata:
name: panel-admin-api-deployment
spec:
replicas: 1
selector:
matchLabels:
component: panel-admin-api
template:
metadata:
labels:
component: panel-admin-api
spec:
containers:
- name: panel-admin-api
image: my-image
ports:
- containerPort: 3001
env:
- name: MONGO_URL
value: panel-admin-mongo-cluster-ip-service // This is important
imagePullSecrets:
- name: gcr-json-key
But for some reason when I'm booting up all containers with kubectl apply command my server says: MongoDB :: connection error: MongoParseError: Invalid connection string
但是由于某种原因,当我使用 kubectl apply 命令启动所有容器时,我的服务器说:
MongoDB :: connection error: MongoParseError: Invalid connection string
Can I deploy it like that (as it was possible with postgress)?我可以像这样部署它吗(就像 postgress 一样)? Or what am I missing here?
或者我在这里错过了什么?
Use mongodb:// in front of your panel-admin-mongo-cluster-ip-service在面板-admin-mongo-cluster-ip-service前使用mongodb://
So it should look like this: mongodb://panel-admin-mongo-cluster-ip-service
所以它应该是这样的:
mongodb://panel-admin-mongo-cluster-ip-service
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.