Using NodePort to connect to Database
you won't be able to set up a proxy that way. If you have an application that receives requests and forwards them to your database.
An easier solution would be to deploy your app to the cluster (if possible) or deploy a test pod to the cluster (using a base image like debian, busybox, or alpine linux; which ever image serves your needs). You can then connect to the pod (kubectl exec -it podname
).
You could try to use NodePort
service without selector and define your own endpoint pointing to database IP address.
For instance:
vagrant@k8sMaster:~$ nslookup google.frName: google.frAddress: 216.58.207.131echo 'apiVersion: v1kind: Servicemetadata: name: my-servicespec: type: NodePort ports: - protocol: TCP port: 443 targetPort: 443' >> svc-no-sel.yamlecho 'apiVersion: v1kind: Endpointsmetadata: name: my-servicesubsets: - addresses: - ip: 216.58.207.131 ports: - port: 443' >> ep-no-sel.yamlk apply -f svc-no-sel.yamlk apply -f ep-no-sel.yaml
Where you replace google IP/Port by your database IP/Port.
Then in the given example you can target the service by doing
curl -k https://<node-ip>:<node-port>
Documentation on service without selector here: https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors