gpt4 book ai didi

mongodb - 解析stateful.yaml时出错:将YAML转换为JSON时出错:yaml:第35行:在此上下文中不允许映射值

转载 作者:行者123 更新时间:2023-12-02 12:16:30 25 4
gpt4 key购买 nike

我正在尝试在Kubernetes上部署mongodb,但出现错误:

error parsing stateful.yaml: error converting YAML to JSON: yaml: line 35: mapping values are not allowed in this context



第35行是容器名称:-名称: uat-mongo-primary

当我尝试创建Pod时出现此错误,但是如果我注释行:

mongo --eval rs.initiate({_id: "rs0", version: 1, members: [{ _id: 0, host : "uat-mongo-primary-rc-0:27017" }]}); 53 mongo --eval "db.getSiblingDB('admin').createUser({user : \"$MONGO_USER\", pwd : \"$MONGO_PASSWORD\", roles: [ { role: 'root', db: 'admin' } ] })";



可以正常创建的Pod,但我需要启动集群,还需要创建用户和密码。

这是我使用的完整yaml文件,我将不胜感激:
apiVersion: v1
kind: Service
metadata:
name: uat-mongo-primary
labels:
name: uat-mongo-primary
spec:
type: NodePort
ports:
- port: 27017
targetPort: 27017
protocol: TCP
name: uat-mongo-primary
selector:
name: uat-mongo-primary

---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: uat-mongo-primary-rc
labels:
name: uat-mongo-primary-rc
spec:
serviceName: uat-mongo-primary
replicas: 1
template:
metadata:
labels:
role: mongo
environment: test

spec:
containers:
- name: uat-mongo-primary
image: mongo
env:
- name: "MONGO_DATA_DIR"
value: "/data/db"
- name: "MONGO_LOG_DIR"
value: "/data/logs"
- name: MONGO_USER
value: "admin"
- name: MONGO_PASSWORD
value: "password"

command: ["/bin/sh", "-c"]
args:
- echo starting;
ulimit -a;
mongod --replSet rs0 --bind_ip_all;
mongo --eval rs.initiate({_id: "rs0", version: 1, members: [{ _id: 0, host : "uat-mongo-primary-rc-0:27017" }]});
mongo --eval "db.getSiblingDB('admin').createUser({user : \"$MONGO_USER\", pwd : \"$MONGO_PASSWORD\", roles: [ { role: 'root', db: 'admin' } ] })";
ports:
- containerPort: 27017
volumes:
- name: uat-mongo-primary-db
persistentVolumeClaim:
claimName: uat-mongo-primary-pvc

最佳答案

不能使用包含冒号的YAML字符串(至少在kubectl中使用)。您应该将YAML转换为JSON(例如,使用this工具),然后将该JSON与kubectl一起应用。

关于mongodb - 解析stateful.yaml时出错:将YAML转换为JSON时出错:yaml:第35行:在此上下文中不允许映射值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55816203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com