How do I route traffic to an external SFTP server via a port in kubernetes nginx?

10/12/2020

The end goal: be able to sftp into the server using domain.com:42150 using routing through Kubernetes.

The reason: This behavior is currently handled by an HAProxy config that we are moving away from, but we still need to support this behavior in our Kubernetes set up.

I came across this and could not figure out how to make it work.

I have the IP of the sftp server and the port.

So, basicaly if a request comes in at domain.com:42150 then it should connect to external-ip:22

I have created a config-map like the one in the linked article:

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: nginx-ingress
data:
  42150: "nginx-ingress/external-sftp:80"

Which, by my understanding should route requests to port 42150 to this service:

apiVersion: v1
kind: Service
metadata:
  name: external-sftp
  namespace: nginx-ingress
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 22
      protocol: TCP

And although it's not listed in that article, I know from connecting to other outside services, I need to create an endpoint to use.

apiVersion: v1
kind: Endpoints
metadata:
  name: external-sftp
  namespace: nginx-ingress
subsets:
  - addresses:
      - ip: 12.345.67.89
    ports:
      - port: 22
        protocol: TCP

Obviously this isn't working. I never ask questions here. Usually my answers are easy to find, but this one I cannot find an answer for. I'm just stuck.

Is there something I'm missing? I'm thinking this way of doing it is not possible. Is there a better way to go about doing this?

-- Grumble
kubernetes
nginx
service

0 Answers