1

I deployed Wildfly application and MySQL persistent on Openshift web console and tried to connect MySQL persistent with jdbc driver of Eclipse outside. However I can not find the public IP address at all on web console.

How can I find public IP address of MySQL persistent or how to configure the specific IP address into MySQL persistent? I attach an image of both services on Openshift.

[enter image description here

UPDATED

On Eclipse IDE, I opened the log part of MySQL pod. And I found the IP addresses of MySQL service:

"readinessProbe" : {
                "exec" : {"command" : [
                    "/bin/sh",
                    "-i",
                    "-c",
                    "MYSQL_PWD=\"$MYSQL_PASSWORD\" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE -e 'SELECT 1'"
                ]},
                "initialDelaySeconds" : 5,
                "timeoutSeconds" : 1,
                "periodSeconds" : 10,
                "successThreshold" : 1,
                "failureThreshold" : 3
            },

....

"phase" : "Running",
        "conditions" : [
            {
                "type" : "Initialized",
                "status" : "True",
                "lastTransitionTime" : "2017-04-02T06:35:00Z"
            },
            {
                "type" : "Ready",
                "status" : "True",
                "lastTransitionTime" : "2017-04-03T16:47:27Z"
            },
            {
                "type" : "PodScheduled",
                "status" : "True",
                "lastTransitionTime" : "2017-04-02T06:35:00Z"
            }
        ],
        "hostIP" : "172.31.14.159",
        "podIP" : "10.1.72.72",
        "startTime" : "2017-04-02T06:35:00Z",
        "containerStatuses" : [{
            "name" : "mysql",
            "state" : {"running" : {"startedAt" : "2017-04-03T16:47:07Z"}},
            "lastState" : {"terminated" : {
                "exitCode" : 255,
                "reason" : "Error",
                    "startedAt" : "2017-04-02T06:36:28Z",
....

I tried to connect MySQL pod with the hostIP, 172.31.14.159 or podIP, 10.1.72.72. But connection failed. And then I found the following MySQL generation commands in the log contents:

"exec" : {"command" : [
                        "/bin/sh",
                        "-i",
                        "-c",
                        "MYSQL_PWD=\"$MYSQL_PASSWORD\" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE -e 'SELECT 1'"
                    ]},

So, I tried to connect the mysql database service with the ip 127.0.0.1. And the connection was SUCCESSFUL.

enter image description here

Now I am confused what this 127.0.0.1 address is, my local PC or MySQL pod of Openshift container. How can I generate MySQL persistent with the HostIP, not with 127.0.0.1? I am afraid I missed the some procedure.

halfer
  • 19,824
  • 17
  • 99
  • 186
Joseph Hwang
  • 1,337
  • 3
  • 38
  • 67
  • The 127.0.0.1 is your local machine. The ``oc port-forward`` only tunnels a single connection back to your local machine for the single MySQL database port. To have a permanent exposed IP corresponding to the MySQL pod is more complicated and would from memory require admin access to the OpenShift cluster. – Graham Dumpleton Apr 07 '17 at 20:45
  • Yes! my issue is not opening port, but getting the external ip address with which I can access mysql pot from eclipse ide or web console, outside the openshift. Would you inform me the reference site or documents? I had similar try on openshift v2 and made success. However openshift v3 is too much complicated. – Joseph Hwang Apr 07 '17 at 23:35
  • The answer below explains it as does the documentation link they already provided. Unfortunately they got ports around wrong way in their example. See ``oc port-forward --help``. Should have been ``oc port-forward 5000:3306``. Then connect from your UI to ``127.0.0.1:5000``. – Graham Dumpleton Apr 08 '17 at 03:42
  • With your advice, I can connect to openshift mysql pod from my eclipse ide. However problem is my connection address is 127.0.0.1:5000. I try to configure mysql character set to utf8. but the commands do not work. I think the configuration commands (ex: SET character_set_database = 'utf8';) can not be applied to database inside mysql pod. Pls, inform me how to connect the actual mysql pod ip address, not 127.0.0.1. Best regards! – Joseph Hwang Apr 10 '17 at 11:31
  • I solved it. The answer was simple. "jdbc:mysql://127.0.0.1:5000/database?useUnicode=yes&characterEncoding=UTF-8" I really appreciate your help Thanks! – Joseph Hwang Apr 11 '17 at 06:50

1 Answers1

1

Your mysql pod havn't a public ip address, but you can use port forwarding.

With Eclipse:

How-To: https://blog.openshift.com/getting-started-eclipse-jboss-tools-openshift-online-3/

Download: http://marketplace.eclipse.org/content/jboss-tools-luna

With Openshift CLI:

$ oc port-forward <pod> [<local_port>:]<remote_port> [...[<local_port_n>:]<remote_port_n>]

such as

$ oc port-forward <pod> 3306:5000

Now you can connect the URL jdbc:mysql://127.0.0.1:5000/database. The mysql pod listen to on your local port 5000.

https://docs.openshift.com/container-platform/3.3/dev_guide/port_forwarding.html

jklee
  • 2,198
  • 2
  • 15
  • 25
  • Thank you for your reply. Pls, check the UPDATED part of my question above. – Joseph Hwang Apr 04 '17 at 10:39
  • You have a db running? Stop them. Follow the blog https://blog.openshift.com/getting-started-eclipse-jboss-tools-openshift-online-3/ and you can access the mysql pod. – jklee Apr 04 '17 at 11:32
  • I think my problem seems to be related with firewall of mysql pot container. The ping does not work with host ip and pot ip. My generated OS is Red Hat Enterprise Linux Server, version=7.3. If I am right, pls inform how to configure the firewall of my pod container, Red Hat linux? – Joseph Hwang Apr 07 '17 at 04:25
  • You installed Openshift CLI Tool OC? I have added a more detailed description. – jklee Apr 07 '17 at 06:36