From WebUI to CLI: OCP Templates

Last time I showed how to recreate a WebUI-generated MariaDB deployment from the command line. But how should you really generate it in the first place? Let’s walk through:

Looking at the deployment config, we can see it was created from a template:

oc get deploymentconfigs mariadb -o yaml | grep template
     template.alpha.openshift.io/wait-for-ready: "true"
     template: mariadb-persistent-template
     template.openshift.io/template-instance-owner: d3954775-1540-11ea-8310-0a580a800022
   template:

We can view the template from the CLI. Note that it is a global resource, and not in the “keystone” project. So to see it, we need to look in all namespaces:

$ oc get templates -A | grep maria
 openshift   mariadb-ephemeral                               MariaDB database service, without persistent storage. For more information ab…   8 (3 generated)   3
 openshift   mariadb-persistent                              MariaDB database service, with persistent storage. For more information about…   9 (3 generated)   4

We care about the persistent version.

$ oc get templates -n openshift mariadb-persistent<br> NAME                 DESCRIPTION                                                                        PARAMETERS        OBJECTS<br> mariadb-persistent   MariaDB database service, with persistent storage. For more information about…   9 (3 generated)   4

We can use this template with the oc new-app command. First, clean up the old project, to remove all resources:

$ oc delete project keystone
project.project.openshift.io "keystone" deleted

And recreate it

oc new-project keystone

Now recreate it:

$ oc new-app mariadb
--> Found image 3bcfc5c (7 weeks old) in image stream "openshift/mariadb" under tag "10.2" for "mariadb"
 
    MariaDB 10.2 
    ------------ 
    MariaDB is a multi-user, multi-threaded SQL database server. The container image provides a containerized packaging of the MariaDB mysqld daemon and client application. The mysqld server daemon accepts connections from clients and provides access to content from MariaDB databases on behalf of the clients.
 
    Tags: database, mysql, mariadb, mariadb102, rh-mariadb102
 
    * This image will be deployed in deployment config "mariadb"
    * Port 3306/tcp will be load balanced by service "mariadb"
      * Other containers can access this service through the hostname "mariadb"
 
--> Creating resources ...
    imagestreamtag.image.openshift.io "mariadb:10.2" created
    deploymentconfig.apps.openshift.io "mariadb" created
    service "mariadb" created
--> Success
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
     'oc expose svc/mariadb' 
    Run 'oc status' to view your app.

Now, this time it did not let me customize any of the fields. But inside the template, we see can follow a link to instructions. Delete the proejct again, wait until it is done, and recreate:

oc new-app mariadb --name mariadb-keystone --env MYSQL_DATABASE=keystone --env MYSQL_USER=keystone --env MYSQL_PASSWORD=keystone

Note that the name is not mariadb-keystone, and not just mariadb. This changes the pod name. Also, for some reason the label is app, not name, now. Hence:

export MARIAIP=`oc get pod -l app=mariadb-keystone -o json | jq  -r  '. | .items[0] | .status |  .podIP '`
kubectl run -it --rm --image=mariadb:latest --restart=Never mariadb-client -- mysql  keystone -h $MARIAIP --user keystone -pkeystone

And we have a database.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.