1
我遵循https://www.mongodb.com/blog/post/running-mongodb-as-a-microservice-with-docker-and-kubernetes並嘗試在Google Cloud帳戶上運行帶有LoadBalancer服務和複製控制器的單個MongoDB實例。Kubernetes與MongoDb
以下是YAML文件:
---
apiVersion: v1
kind: Service
metadata:
name: mongo-svc-a
labels:
name: mongo-svc-a
spec:
type: LoadBalancer
ports:
- port: 27017
targetPort: 27017
protocol: TCP
name: mongo-svc-a
selector:
name: mongo-node1
instance: rod
---
apiVersion: v1
kind: ReplicationController
metadata:
name: mongo-rc1
labels:
name: mongo-rc
spec:
replicas: 1
selector:
name: mongo-node1
template:
metadata:
labels:
name: mongo-node1
instance: rod
spec:
containers:
- name: mongo-node1
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage1
mountPath: /data/db
volumes:
- name: mongo-persistent-storage1
gcePersistentDisk:
pdName: mongodb-disk1-in-cluster1
fsType: ext4
以下是創建的服務,複製控制器和豆莢的細節。一切似乎都很好。
$ kubectl describe service mongo-svc-a
Name: mongo-svc-a
Namespace: default
Labels: name=mongo-svc-a
Selector: instance=rod,name=mongo-node1
Type: LoadBalancer
IP: 10.3.241.11
LoadBalancer Ingress: 104.198.236.2
Port: mongo-svc-a 27017/TCP
NodePort: mongo-svc-a 31808/TCP
Endpoints: 10.0.0.3:27017
Session Affinity: None
No events.
$ kubectl describe rc mongo-rc1
Name: mongo-rc1
Namespace: default
Image(s): mongo
Selector: name=mongo-node1
Labels: name=mongo-rc
Replicas: 1 current/1 desired
Pods Status: 1 Running/0 Waiting/0 Succeeded/0 Failed
Volumes:
mongo-persistent-storage1:
Type: GCEPersistentDisk (a Persistent Disk resource in Google Compute Engine)
PDName: mongodb-disk1-in-cluster1
FSType: ext4
Partition: 0
ReadOnly: false
No events.
$ kubectl describe pod mongo-rc1-h0j8r
Name: mongo-rc1-h0j8r
Namespace: default
Node: gke-cluster1-default-pool-d58b6c05-74fq/10.128.0.6
Start Time: Sat, 11 Feb 2017 18:43:00 +0530
Labels: instance=rod
name=mongo-node1
Status: Running
IP: 10.0.0.3
Controllers: ReplicationController/mongo-rc1
Containers:
mongo-node1:
Container ID: docker://9f28e482d3806b74f7f595c47e6c7940c2313e95860db13d137ad6eaa88bb341
Image: mongo
Image ID: docker://sha256:ad974e767ec4f06945b1e7ffdfc57bd10e06baf66cdaf5a003e0e6a36924e30b
Port: 27017/TCP
Requests:
cpu: 100m
State: Running
Started: Sat, 11 Feb 2017 18:45:37 +0530
Ready: True
Restart Count: 0
Volume Mounts:
/data/db from mongo-persistent-storage1 (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-3wfv3 (ro)
Environment Variables: <none>
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
mongo-persistent-storage1:
Type: GCEPersistentDisk (a Persistent Disk resource in Google Compute Engine)
PDName: mongodb-disk1-in-cluster1
FSType: ext4
Partition: 0
ReadOnly: false
default-token-3wfv3:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-3wfv3
QoS Class: Burstable
Tolerations: <none>
No events.
但是,當我嘗試遠程連接mongo --hostname <Extenal_IP_of_the_service>
,到新創建的monogdb情況下,我無法連接。我相信配置似乎沒問題。任何幫助,將不勝感激。謝謝,
- 帕
我認爲這是一個有點過於廣泛,所以 - 你應該至少說明你已經採取了一切措施來解決或重現問題。 對於在Kubernetes上運行的應用程序啓動[應用程序故障排除指南](https://kubernetes.io/docs/user-guide/application-troubleshooting/)可能是一個好的開始。如果您發現錯誤,請使用您的發現編輯您的問題。 – pagid
謝謝。將添加更多的日誌。 –