Я создал две реплики (имя набора реплик = rs0) mongodb с безголовым сервисом.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: tickets-mongo-depl
spec:
replicas: 2
serviceName: tickets-mongo-srv
selector:
matchLabels:
app: tickets-mongo
template:
metadata:
labels:
app: tickets-mongo
spec:
containers:
- name: tickets-mongo
image: mongo
command:
- mongod
- '--bind_ip_all'
- '--replSet'
- rs0
---
apiVersion: v1
kind: Service
metadata:
name: tickets-mongo-srv
spec:
clusterIP: None
selector:
app: tickets-mongo
ports:
- name: tickets-db
protocol: TCP
port: 27017
targetPort: 27017
pods, и сервис работает должным образом
pod/tickets-mongo-depl-0 1/1 Running 0 50m
pod/tickets-mongo-depl-1 1/1 Running 0 50m
service/tickets-mongo-srv ClusterIP None <none> 27017/TCP 6d12h
У меня есть запустите приведенную ниже команду, чтобы открыть безголовый сервис, чтобы я мог подключиться к своей базе данных с помощью компаса mongodb GUI
kubectl port-forward service/tickets-mongo-srv 7000:27017
Forwarding from 127.0.0.1:7000 -> 27017
Forwarding from [::1]:7000 -> 2701
набор реплик уже инициализирован.
{
"set" : "rs0",
"date" : ISODate("2020-06-20T08:03:02.019Z"),
"myState" : 1,
"term" : NumberLong(1),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1592640178, 1),
"t" : NumberLong(1)
},
"lastCommittedWallTime" : ISODate("2020-06-20T08:02:58.983Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1592640178, 1),
"t" : NumberLong(1)
},
"readConcernMajorityWallTime" : ISODate("2020-06-20T08:02:58.983Z"),
"appliedOpTime" : {
"ts" : Timestamp(1592640178, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1592640178, 1),
"t" : NumberLong(1)
},
"lastAppliedWallTime" : ISODate("2020-06-20T08:02:58.983Z"),
"lastDurableWallTime" : ISODate("2020-06-20T08:02:58.983Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1592640168, 1),
"lastStableCheckpointTimestamp" : Timestamp(1592640168, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "electionTimeout",
"lastElectionDate" : ISODate("2020-06-20T06:29:48.607Z"),
"electionTerm" : NumberLong(1),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1592634577, 1),
"t" : NumberLong(-1)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2020-06-20T06:29:48.634Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2020-06-20T06:29:50.053Z")
},
"members" : [
{
"_id" : 0,
"name" : "tickets-mongo-depl-0.tickets-mongo-srv:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 5750,
"optime" : {
"ts" : Timestamp(1592640178, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-06-20T08:02:58Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1592634588, 1),
"electionDate" : ISODate("2020-06-20T06:29:48Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "tickets-mongo-depl-1.tickets-mongo-srv:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 5604,
"optime" : {
"ts" : Timestamp(1592640178, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1592640178, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-06-20T08:02:58Z"),
"optimeDurableDate" : ISODate("2020-06-20T08:02:58Z"),
"lastHeartbeat" : ISODate("2020-06-20T08:03:00.524Z"),
"lastHeartbeatRecv" : ISODate("2020-06-20T08:03:00.028Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "tickets-mongo-depl-0.tickets-mongo-srv:27017",
"syncSourceHost" : "tickets-mongo-depl-0.tickets-mongo-srv:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1592640178, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1592640178, 1)
}
Как вы можете видеть на последнем изображении, GUI пытается подключиться безуспешно.
Кто-нибудь из вас знает, почему это ??