Redhat Openshift 4 - Not able to make mysql connection from php pod to mysql pod - openshift

I am user of Openshift online and OKD. I am facing similar issue in both places. Please have a look.
I have created a project.
I have launched php in Developer's Catalog option. With other details, I entered my project's git url, project is cloned successfully. Now it needs to connect to mysql database only.
In Pods, I deployed mysql image from 'Deploy Image' option. It is launched successfully.
When I make mysql connection from php pod to mysql pod, it does not connect, connection time out.
How should I make connection?
Note :
I do not have datastore option to launch mysql from developer's catalog in openshift online, that's why I am launching mysql image from deploy image.

As you mentioned you are using Openshift Online and OKD and you are facing the issue at both places.
You can not create mysql from development store because currently, the OpenShift Online catalog does not provide MySQL template via the web interface directly, but you can deploy the MySQL template using the oc CLI instead. The database deployment is simplified when using templates.
Once logged in with the oc CLI, running
oc new-app -L
will list all of the templates that we were used to seeing in the web console, including the mysql-persistent. Then, you can specify all the template parameters via the oc CLI, e.g.:
oc new-app mysql-persistent -p MYSQL_USER=<desired_DB_username> -p MYSQL_PASSWORD=<mysql_password> -p MYSQL_DATABASE=<desired_database_name>
If you'd like to see all the supported template parameters, you can use
oc process <template_name> --parameters -n openshift
or, for a more detailed output,
oc describe template <template_name> -n openshift
Once the app is launched successfully, you can find this app's hostname in services and connect to it from your php pod after defining host name in php configuration file.

Related

Openshift new-app from image creates service with incorrect ports

I am using openshift oc new-app to create a app from a image.
However oc new-app is creating the associated openshift service incorrectly with only one tcp port, not the two ports than the application uses.
Is there any simple way to force openshift new-app to correctly create the service with the two correct ports when building from a image rather than incorrectly with only one port ?
Alternatively is there a command line way to add the extra port to the service created that can be scripted (I know about oc edit) ..
(Disclaimer.. I am new to openshift and have lots to learn)

How to use CDK/minishift OpenShift cluster with kubectl

I have installed CDK on my Windows 10 laptop.
I am following documentation on using IBM Blockchain Platform with RedHat OpenShift.
One of the first steps is issuing kubectl commands.
I see CDK comes with the OpenShift CLI (oc) installed but not with kubectl. Do I need to install kubectl separatelly ? If so, how do I configure kubectl to know about my OpenShift cluster running in CDK/minishift?
To answer your specific question, any time you see a "kubectl" command you can replace it with "oc".
You can also download kubectl directly from upstream, and it will use the same (by default, or use $KUBECONFIG to override) ~/.kube/config file.
However, you should know that CDK is based on OpenShift 3.11.z and is approaching end-of-life. I would suggest you take a look at CRC, which is based on 4.x. Start here for more information -- https://console.redhat.com/openshift/create/local

Running two docker containers on one Azure App service plan

I have two containers that need to run on the same machine.
The first container is the server and the second one is the agent.
Server image tag name: local-wptserver
Server image tag name: local-wptagent
I can get it to work locally so I am trying to deploy it to the cloud (Azure) for the team's consumption.
This is how I am running it locally::
docker run -d -p 4000:80 local-wptserver
docker run -d -p 4001:80 --network="host" -e "SERVER_URL=http://localhost:4000/work/" -e "LOCATION=EastUS_wptdriver" local-wptagent
This basically sets up the server and the agent to talk to each other so once I start making API calls to the server it schedules the job with the agent and returns me the results.
However since my images are now in Azure Container registry, how do I get the container to instantiate with those extra parameters (--network="host" -e "SERVER_URL=http://localhost:4000/work/" -e "LOCATION=EastUS_wptdriver") when it gets deployed to a web app?
Is this something I can add in the docker file, prior to creating the image? If yes, how?
Note: I am using the same Azure app service plan to ensure that the two web apps (built form two different repositories in the Azure container registry: server and agent) are on the same machine.
When you want to deploy multiple containers in the Azure Web App, then you need to use the docker-compose file to deploy the multiple containers. You can follow the steps in the example.
And then, the --network does not support in the docker-compose in Azure Web App, you can see all supported compose options here. But don't worry, the containers can communicate with each other through the ports.
According to the message that you push the images to Azure Container Registry. Then you should use the ACR as the docker registry. So you need to set the environment variables for your ACR and the details here. And there are also many details you cloud know in the link I provided.

No environment variables in OpenShift

I have created a new OpenShift account for a new application I'm developing.
I have added a MongoDB cartridge for the database, and a Tomcat cartridge for the Java web application.
I now need to connect to the database from my Java web app, but I miss two authentication details:
$OPENSHIFT_MONGODB_DB_HOST
$OPENSHIFT_MONGODB_DB_PORT
As far as I know, I have to type rhc env list -a the_name_of_my_app in the console, but my application seems to have no environment variables set.
What can I do?
Apparently, the default enironment variables are visible only via ssh.
In order to see them, you have to type rhc ssh <appid-as-seen-on-openshift-console> followeb by env.
you can see environment variables by doing ssh to openshift. Also you can use openshift port forwarding feature to setup a connection locally to your database.
Openshift blog link for port forwarding

Openshift unable to connect to the server

I am having issues with setting up Open shift and getting the following error after connecting to my server domain:
Command:
User$ rhc setup --server=app-domain.rhcloud.com
Result:
The server has rejected your connection attempt with an older SSL protocol.
Pass --ssl-version=sslv3 on the command line to connect to this server.
I am not sure what this is telling me to do. I tried using the instruction literally and it does not recognize the command.
Any ideas?
You should not pass rhc setup the --server flag unless you are running your own OpenShift Origin or OpenShift Enterprise broker. For OpenShift Online, just run the rhc setup command with no other options and it will setup fine. If that command messed up your express.conf file (which it should not have) you just need to delete your ~/.openshift/express.conf file then run rhc setup again without any flags. Basically you tried to point rhc to your gear as an OpenShift Online broker, which will not work.
I ended up answering this on another forum post:
The only way that this worked for me was to actually create a SSH key locally with ssh-keygen -p without rhc setup and "not" giving it a password. I then went back to OpenShift clicked add a key and pasted the contents of my rsa file.
There is obviously some kind of bug with authentication on Openshift or the installation is not right.
It would be good to find out what is going on and why does it work if I do it, this way.