Redirect http port to nodePort

10/25/2017

I have a kubernetes 1.5 cluster (with flannel network) and with server port range from 50000 - 55000. What I would like to do is to redirect traffic from VIP:80 to NODE_IP:55000.

  • VIP: 10.66.122.115
  • NODE_IP: 10.66.122.116 (both IP addresses are assigned to same host, but VIP can move if host is down)

iptables rule:

iptables -t nat -I PREROUTING -i eth0 -p tcp --dst 10.66.122.115 \
     --dport 80 -j DNAT --to 10.66.122.116:55000

Yet, it doesn't work. If I run simple http server on some other port and enter corresponding rule iptables then it works, but same rule for kubernetes does not work. Any idea how to solve this?

-- Sasa
iptables
kubernetes

1 Answer

10/25/2017

You can try ingress.. if there is an external traffic terminating on your k8s cluster, your ingress rules will direct it to a service and a port (like node port etc)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo-ingress
spec:
  rules:
  - host: mysite.com
    http:
      paths:
      - backend:
          serviceName: nginx
          servicePort: 80
-- Muzammil
Source: StackOverflow