I have kubernetes cluster in google cloud.
I have an external database and I need to set trusted IP range in database.
My problem is, that I don't know what outgoing ip is from my kubernetes.
Where can I find it?
If you want to connect to the cluster from outside you have to create Service. When you will create it, you will automatically receive External-IP address which you can use to connect to your cluster from outside. You can check here how to create service.
You can also create endpoints (depends on your needs) if you need more than one IP address.
Later you will just need to execute kubectl get service -o wide. You will receive output like:
$ kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
connection-to-my-db LoadBalancer 10.0.3.84 34.76.XXX.148 8080:32165/TCP 84s run=nginx
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 17d <none>
However, for a wile External-IP from that service will be in state. You just need to wait 1-2 minutes to received it.
As you are using GCP you can read this article about mapping external services.
I think you're finding the source IP of outgoing packets from kubernetes to be trusted by the external database.
There is a way to preserve source IP address and not do source NAT'ing by using the service.spec.externalTrafficPolicy field in the service manifest. Note this risks potentially imbalanced traffic spreading.
"externalTrafficPolicy": "Local"Note "externalTrafficPolicy": "Local" had issues with NodePort service type in earlier k8s versions due to the following bugs: