OpenShift command-line: automate tasks & install the MariaDb application
OpenShift has a great GUI, but if you want to automate tasks on it via Ansible the command-line is the way to move forward. In the fifth episode of our blog series, we will show you how to install MariaDb on OpenShift via this interface.
The OpenShift CLI exposes commands for managing your applications, as well as lower level tools to interact with each component of your system.
First we need to login to the VM.
On your local machine use open ssh
to connect.
prefix
is the prefix you added in the survey while deploying OpenShift OKD.
towerLabKeyPrivate
is the private key created in episode 1.
After login we can start with the oc
command, which has a built-in help system.
This --help
flag works on different levels of the command.
Example: to see the options for the oc project
command:
To get started, you first need to login.
Now, we will create a new project for mariadb.
Make this project the active one.
The next step is to create the application in this project.
It is possible to set variables during the app creation.
Set the MYSQL_USER
, the MYSQL_PASSWORD
and the MYSQL_ROOT_PASSWORD
to developer. Then set the MYSQL_DATABSE
to phpDB.
The last step is to expose the application so it is accessible to the outside world.
This command will create a route to the mariadb application you created with the previous command.
The developer user has standard only access via the internal network and not public.
You can connect to the pod via ssh
.
First search for the pod name, and then connect to the pod with the oc rsh
command.
Now we can check the ip of the pod via ifconfig
(ip command is not available) and connect to mariadb via the mysql
command.
Create a user table and add three rows.
This table can now be used by other pods in the same network.
You can, for example, change the php application to use this database.
In playbook-3yml included in this gitlab repo we used for installing OpenShift OKD, we commented out the role osInstallMariaDb
. If you uncomment this role, it will install MariaDb.
You can also modify the provided php application. Try to make it work together with the database we created.
- Tip 1: check the index2.php file via the terminal screen on your php pod.
- Tip 2: If you can not connect to the database, check the ip from the server in the protected/mysql_connect.php file.
Have fun!
If everything is done correctly you should have the following result on http://phpcountdown-php-devoteam.{{ public IP }}.nip.io/index2.php