Repository navigation
Closed
Description
I'm following the guide (https://github.com/openshift/origin/blob/master/examples/sample-app/README.md) to build the sample app, after the front-end and database containers are started, the frontend can not talk to the database, here is the steps I took to check:
- Confirm the database is up and running:
[root@os sample-app]# osc get services
NAME LABELS SELECTOR IP PORT
database template=application-template-stibuild name=database 172.30.17.244 5434
frontend template=application-template-stibuild name=frontend 172.30.17.215 5432
[root@os sample-app]# docker ps | grep k8s_ruby-helloworld-database
971d7a875458 openshift/mysql-55-centos7:latest "run-mysqld.sh mysql 35 minutes ago Up 35 minutes k8s_ruby-helloworld-database.d7274162_database-1-6txmw_test_1a53c10e-dc69-11e4-bf48-525400e80350_2ab12d43
[root@os sample-app]# docker inspect 971d7a875458 | grep MYSQL_
"MYSQL_USER=userLD6",
"MYSQL_PASSWORD=uYGpO5qC",
"MYSQL_DATABASE=root",
"MYSQL_VERSION=5.5",
- Connect to database from host, it has no problem:
[root@os sample-app]# mysql -h172.30.17.244 -P5434 -uuserLD6 -puYGpO5qC
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> Bye
- Check frontend:
[root@os sample-app]# docker ps | grep 'k8s_ruby-helloworld.*frontend'
7873e7ad77e4 172.30.17.100:5000/test/origin-ruby-sample:76af1f2ec7bebeba79ae4ffd3d2e4336069a8f567b9ca19a55cd83bc2142ea31 "/usr/local/sti/run" 20 minutes ago Up 20 minutes k8s_ruby-helloworld.c7727750_frontend-4-s9f9l_test_3a90fbe3-dc78-11e4-9cd2-525400e80350_118b117f
[root@os sample-app]# docker logs 7873e7ad77e4 | tail
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
Connecting to production database ([email protected]:5434)...
- Start a container from the image which frontend is boot from to have a double check.
[root@os sample-app]# docker run -it -u root 172.30.17.100:5000/test/origin-ruby-sample:76af1f2ec7bebeba79ae4ffd3d2e4336069a8f567b9ca19a55cd83bc2142ea31 /bin/bash
bash-4.2# yum install -y mysql
<snip>
bash-4.2# mysql -h172.30.17.244 -P5434 -uuserLD6 -puYGpO5qC
ERROR 2003 (HY000): Can't connect to MySQL server on '172.30.17.244' (113)
bash-4.2# ping 172.30.17.244
PING 172.30.17.244 (172.30.17.244) 56(84) bytes of data.
^C
--- 172.30.17.244 ping statistics ---
7 packets transmitted, 0 received, 100% packet loss, time 6000ms
Additional Info (from host):
[root@os ~]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
Active: inactive (dead)
[root@os ~]# systemctl status iptables
iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled)
Active: active (exited) since Sat 2015-04-04 20:23:33 CST; 2 days ago
Main PID: 453 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/iptables.service
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
[root@os ~]# getenforce
Permissive
[root@os ~]# lsof -i :5434
[root@os ~]# lsof -i :5432
[root@os ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:10250
ACCEPT tcp -- anywhere anywhere state NEW tcp dpts:pcsync-https:pcsync-http
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:afs3-callback
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:newoak
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (1 references)
target prot opt source destination
[root@os sample-app]# iptables-save
# Generated by iptables-save v1.4.21 on Tue Apr 7 01:12:34 2015
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [28:1680]
:POSTROUTING ACCEPT [28:1680]
:DOCKER - [0:0]
:KUBE-PORTALS-CONTAINER - [0:0]
:KUBE-PORTALS-HOST - [0:0]
-A PREROUTING -j KUBE-PORTALS-CONTAINER
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT -j KUBE-PORTALS-HOST
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A KUBE-PORTALS-CONTAINER -d 172.30.17.100/32 -p tcp -m comment --comment "default/docker-registry" -m tcp --dport 5000 -j REDIRECT --to-ports 36507
-A KUBE-PORTALS-CONTAINER -d 172.30.17.2/32 -p tcp -m comment --comment "default/kubernetes" -m tcp --dport 443 -j REDIRECT --to-ports 49506
-A KUBE-PORTALS-CONTAINER -d 172.30.17.1/32 -p tcp -m comment --comment "default/kubernetes-ro" -m tcp --dport 80 -j REDIRECT --to-ports 35777
-A KUBE-PORTALS-CONTAINER -d 172.30.17.244/32 -p tcp -m comment --comment "test/database" -m tcp --dport 5434 -j REDIRECT --to-ports 58333
-A KUBE-PORTALS-CONTAINER -d 172.30.17.215/32 -p tcp -m comment --comment "test/frontend" -m tcp --dport 5432 -j REDIRECT --to-ports 46951
-A KUBE-PORTALS-HOST -d 172.30.17.100/32 -p tcp -m comment --comment "default/docker-registry" -m tcp --dport 5000 -j DNAT --to-destination 192.168.10.5:36507
-A KUBE-PORTALS-HOST -d 172.30.17.2/32 -p tcp -m comment --comment "default/kubernetes" -m tcp --dport 443 -j DNAT --to-destination 192.168.10.5:49506
-A KUBE-PORTALS-HOST -d 172.30.17.1/32 -p tcp -m comment --comment "default/kubernetes-ro" -m tcp --dport 80 -j DNAT --to-destination 192.168.10.5:35777
-A KUBE-PORTALS-HOST -d 172.30.17.244/32 -p tcp -m comment --comment "test/database" -m tcp --dport 5434 -j DNAT --to-destination 192.168.10.5:58333
-A KUBE-PORTALS-HOST -d 172.30.17.215/32 -p tcp -m comment --comment "test/frontend" -m tcp --dport 5432 -j DNAT --to-destination 192.168.10.5:46951
COMMIT
# Completed on Tue Apr 7 01:12:34 2015
# Generated by iptables-save v1.4.21 on Tue Apr 7 01:12:34 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [25600449:9622654100]
:DOCKER - [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10250 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8443:8444 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Tue Apr 7 01:12:34 2015
Activity
mrunalp commentedon Apr 6, 2015
Could you take out this rule "-A FORWARD -j REJECT --reject-with icmp-host-prohibited" ?
xjvs commentedon Apr 6, 2015
Before take out the rule of "-A FORWARD -j REJECT --reject-with icmp-host-prohibited":
from host:
from the container which boot up from the image used by frontend:
From host:
and seeing this on host while pinging:
After take out the rule of "-A FORWARD -j REJECT --reject-with icmp-host-prohibited":
comment out the following 2 line in host's /etc/sysconfig/iptables:
and then
And then check connecting to the database service, there is no luck, still can't connect to it.
tcpdump output (while pinging from container to the database service ip) changes to (172.17.0.5 is host ip):
xjvs commentedon Apr 6, 2015
BTW: Here is the steps I took to setup the env (in a F21 vm): http://fpaste.org/207646/
xjvs commentedon Apr 7, 2015
I've checked this again today, rebuild the sample app from the very beginning (just comment out the icmp-host-prohibited reject rule and restart iptables & docker & openshift with the old openshift.local.* doesn't work).
Confirmed the most important point is removing icmp-host-prohibited reject rule from INPUT chain, have that rule in FORWARD chain is ok.
mrunalp commentedon Apr 7, 2015
@xjvs Thanks! Yes, the INPUT rule to icmp rule can't be there. I somehow misread your iptables rules yesterday and thought that there was an ACCEPT rule for icmp before the REJECT and hence it was harmless.
smarterclayton commentedon Apr 8, 2015
Where is the best place to document this, or record it so it doesn't catch anyone else?
soltysh commentedon Apr 8, 2015
Maybe here https://github.com/openshift/origin/blob/master/docs/debugging-openshift.md ?
mrunalp commentedon May 29, 2015
We have a few more rules in node setup script now to decrease the likelihood of this happening. I will add things to watch out for in the docs if any.
mrunalp commentedon Jun 1, 2015
I think we can close this issue. We have iptables rules in the setup that should prevent this from happening. If anything else comes up, we can modify the setup script to add those rules as well.
Squashed 'cmd/service-catalog/go/src/github.com/kubernetes-incubator/…