I have set up a working Kubernetes cluster using Rancher which defines two networks:

  • for pod ip addresses
  • for service endpoints

I want to use my existing Caddy reverse proxy to access those service endpoints, so I defined a route ( is one of my kubernetes nodes):

sudo route add -net netmask gw

My routing table on the Caddy web server:

arturh@web:~$ sudo route
[sudo] password for arturh:
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         DD-WRT.local         UG    0      0        0 eth0   U     0      0        0 eth0       rancherkube1.lo     UG    0      0        0 eth0     U     0      0        0 docker0

Using this setup I can access and use without any issues (it is the main kubernetes api endpoint):

arturh@web:~$ nmap -p 443 | grep 443
443/tcp open  https
arturh@web:~$ curl -k

But accessing any other IP address in the network fails and I cannot figure out why:

arturh@web:~$ kubectl get svc | grep prometheus-server
prometheus-prometheus-server        <none>         80/TCP              1d
arturh@web:~$ curl
curl: (7) Failed to connect to port 80: No route to host
arturh@web:~$ traceroute
traceroute to (, 30 hops max, 60 byte packets
 1  rancherkube1.local (  0.348 ms  0.341 ms  0.332 ms
 2  rancherkube1.local (  3060.710 ms !H  3060.722 ms !H  3060.716 ms !H

I can access everything from the kubernetes node itself:

[rancher@rancherkube1 ~]$ wget -qO-
<!DOCTYPE html>
<html lang="en">...

which works because of iptable NAT rules:

[rancher@rancherkube1 ~]$ sudo iptables -t nat -L -n  | grep 10.43
KUBE-SVC-NGLRF5PTGH2R7LSO  tcp  --          /* default/prometheus-prometheus-server:http cluster IP */ tcp dpt:80
KUBE-SVC-NPX46M4PTMTKRN6Y  tcp  --              /* default/kubernetes:https cluster IP */ tcp dpt:443

I'm confused because the entries for which works looks identical the the others which do not... I figure I need to add an iptables rule to allow access to the subnet, but I'm not familiar with iptables.

I'm quite new to the whole kubernetes business, is this the correct way to go about accessing your service endpoints? If so can someone please help me with the correct iptables command?

| improve this question | | | | |

you can access things from a host that's running a kubernetes workload because it has the iptables rules and possible route table rules to route traffic.

If you want to access the kubernetes services from outside your cluster then you want to use a ingress controller with a ingress service.


| improve this answer | | | | |
  • okay, thanks that makes sense in that the other things i got working with kubernetes are either served by my ingress controller or are NodePorts which are available on the node IP directly, but I thought that there must be a way to access service endpoints directly when you want to for example expose MySQL ports which are not http to other hosts – arturh Sep 27 '17 at 21:51
  • You can use like haproxy as a ingress controller and it'll the ingress service controller you could say i want this node port 33060 opened and it'll open them on all hosts.. Then if you are on a non-cloud provider you'd have like a hardware LB to map a new VIP 3306->33060 and then point all your services at that VIP. On AWS for example the service controller would create a ELB – Mike Sep 27 '17 at 21:55
  • ya good luck.. kubernetes is really a great platform once you wrap your head around the concepts and learn a new way of doing ops – Mike Sep 27 '17 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.