Cannot connect to a mongodb service in a Kubernetes cluster

前端 未结 1 501
北恋
北恋 2021-01-18 15:30

I have a Kubernetes cluster on Google Cloud, I have a database service, which is running in front of a mongodb deployment. I also have a series of microservices, which are a

相关标签:
1条回答
  • 2021-01-18 16:28

    First, check that the service is created

    kubectl describe svc mongo

    You should see it show that it is both created and routing to your pod's IP. If you're wondering what your pod's IP is you can check it out via

    kubectl get po | grep mongo

    Which should return something like: mongo-deployment-<guid>-<guid>, then do

    kubectl describe po mongo-deployment-<guid>-<guid>

    You should make sure the pod is started correctly and says Running not something like ImagePullBackoff. It looks like you're mounting a volume from a gcePersistentDisk. If you're seeing your pod just hanging out in the ContainerCreating state it's very likely you're not mounting the disk correctly. Make sure you create the disk before you try and mount it as a volume.

    If it looks like your service is routing correctly, then you can check the logs of your pod to make sure it started mongo correctly:

    kubectl logs mongo-deployment-<guid>-<guid>

    If it looks like the pod and logs are correct, you can exec into the pod and make sure mongo is actually starting and working: kubectl exec -it mongo-deployment-<guid>-<guid> sh

    Which should get you into the container (Pod) and then you can try something like this to see if your DB is running.

    0 讨论(0)
提交回复
热议问题