Skip to content

sample-app: the frontend can't talk to database #1607

Closed

Description

@xjvs

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:

  1. 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",
  1. 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
  1. 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)...
  1. 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

  1. mrunalp commented on Apr 6, 2015

    @mrunalp
    Member

    Could you take out this rule "-A FORWARD -j REJECT --reject-with icmp-host-prohibited" ?

  2. xjvs commented on Apr 6, 2015

    @xjvs
    Author

    Before take out the rule of "-A FORWARD -j REJECT --reject-with icmp-host-prohibited":

    from host:

    [root@os ~]# iptables -nvL
    Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
     pkts bytes target     prot opt in     out     source               destination         
      26M 9735M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    18817 1129K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:10250
    88660 5320K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpts:8443:8444
        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:7001
    77886 4673K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:4001
        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:443
        5   300 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80
        0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
      490 29400 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
       14   840 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
     328K   20M REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
     pkts bytes target     prot opt in     out     source               destination         
    48155   81M DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0           
    48153   81M ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    27470 1436K ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0           
        2   168 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0           
        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain OUTPUT (policy ACCEPT 26M packets, 9684M bytes)
     pkts bytes target     prot opt in     out     source               destination         
    
    Chain DOCKER (1 references)
     pkts bytes target     prot opt in     out     source               destination  
    

    from the container which boot up from the image used by frontend:

    [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# 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 ---
    11 packets transmitted, 0 received, 100% packet loss, time 10002ms
    
    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# mysql -h172.30.17.244 -P5434 -uuserLD6 -puYGpO5qC
    ERROR 2003 (HY000): Can't connect to MySQL server on '172.30.17.244' (113)
    

    From host:

    [root@os ~]# iptables -nvL
    Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
     pkts bytes target     prot opt in     out     source               destination         
      26M 9737M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    18820 1129K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:10250
    88672 5320K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpts:8443:8444
        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:7001
    77900 4674K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:4001
        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:443
        5   300 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80
        0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
      490 29400 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
       14   840 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
     328K   20M REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
     pkts bytes target     prot opt in     out     source               destination         
    48155   81M DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0           
    48153   81M ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    27481 1437K ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0           
        2   168 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0           
        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain OUTPUT (policy ACCEPT 26M packets, 9686M bytes)
     pkts bytes target     prot opt in     out     source               destination         
    
    Chain DOCKER (1 references)
     pkts bytes target     prot opt in     out     source               destination         
    

    and seeing this on host while pinging:

    [root@os sample-app]# tcpdump -nn -i any icmp
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
    00:20:09.074950 IP 172.30.17.244 > 172.17.0.46: ICMP host 172.30.17.244 unreachable - admin prohibited, length 68
    00:20:10.181031 IP 172.30.17.244 > 172.17.0.46: ICMP host 172.30.17.244 unreachable - admin prohibited, length 68
    00:20:10.181035 IP 172.30.17.244 > 172.17.0.46: ICMP host 172.30.17.244 unreachable - admin prohibited, length 68
    <snip>
    

    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:

    # -A INPUT -j REJECT --reject-with icmp-host-prohibited
    #-A FORWARD -j REJECT --reject-with icmp-host-prohibited
    

    and then

    $ systemctl restart iptables
    $ systemctl restart docker
    

    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):

    [root@os ~]# tcpdump -nn -i any icmp
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
    01:49:17.551561 IP 172.17.0.5 > 172.30.17.244: ICMP echo request, id 23, seq 1, length 64
    01:49:17.551580 IP 192.168.10.5 > 172.30.17.244: ICMP echo request, id 23, seq 1, length 64
    01:49:18.550995 IP 172.17.0.5 > 172.30.17.244: ICMP echo request, id 23, seq 2, length 64
    01:49:18.550995 IP 172.17.0.5 > 172.30.17.244: ICMP echo request, id 23, seq 2, length 64
    01:49:18.551012 IP 192.168.10.5 > 172.30.17.244: ICMP echo request, id 23, seq 2, length 64
    01:49:19.551019 IP 172.17.0.5 > 172.30.17.244: ICMP echo request, id 23, seq 3, length 64
    <snip>
    
  3. xjvs commented on Apr 7, 2015

    @xjvs
    Author

    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.

    • the issue exists when there is icmp-host-prohibited reject rule in INPUT chain
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    #-A FORWARD -j REJECT --reject-with icmp-host-prohibited
    
    • the issue doesn't exist when there is no icmp-host-prohibited reject rule in INPUT chain, even with that reject rule in FORWARD chain
    #-A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    
  4. mrunalp commented on Apr 7, 2015

    @mrunalp
    Member

    @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.

  5. smarterclayton commented on Apr 8, 2015

    @smarterclayton
    Contributor

    Where is the best place to document this, or record it so it doesn't catch anyone else?

  6. mrunalp commented on May 29, 2015

    @mrunalp
    Member

    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.

  7. mrunalp commented on Jun 1, 2015

    @mrunalp
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions