I have a mongodb server hosted outside GCP, I want to connect to it using Kubernetes endpoint service as shown here [https://www.youtube.com/watch?v=fvpq4jqtuZ8]. How can I do that? Can you write a sample YAML file for the same?
use static Kubernetes service, when you have got the Internal IP and Port number for externally hosted service.
kind: Service
apiVersion: v1
metadata:
name: mongo
Spec:
type: ClusterIP
ports:
- port: 27017
targetPort: 27017
As there are no Pod selectors for this service , There will not be any endpoints thus we can create a endpoint object manually.
kind: Endpoints
apiVersion: v1
metadata:
name: mongo
subsets:
- addresses:
- ip: 10.240.0.4 # Replace ME with your IP
ports:
- port: 27017
make sure that service and endpoints are having same name (for example mongo)
If the IP address changes in the future, you can update the Endpoint with the new IP address, and your applications won’t need to make any changes.mapping-external-services