Openshift 构建 容器化mysql

1: 准备mysql镜像

  • 查看Image streams
    Openshift 提供了image streams管理镜像,"An image stream can be used to automatically perform an action, such as updating a deployment, when a new image, such as a new version of the base image that is used in that deployment, is created." - OpenShift Documentation
    但是请注意,Image Streams并不是镜像仓库,只是镜像的一种映射,具体的镜像实体还需要自己准备。

    查看Image Streams

[[email protected] ~]# oc get is
NAME              DOCKER REPO   TAGS                           UPDATED
hello-openshift                 latest                         10 weeks ago
httpd                           latest,2.4                     6 hours ago
jenkins                         latest,2,1                     6 hours ago
mariadb                         latest,10.1                    6 hours ago
mongodb                         2.6,2.4,latest + 1 more...     6 hours ago                    
mysql                           latest,5.7,5.6 + 1 more...     6 hours ago
nodejs                          4,0.10,latest + 1 more...      6 hours ago
perl                            5.20,5.16,latest + 1 more...   6 hours ago
php                             5.5,latest,7.0 + 1 more...     6 hours ago
postgresql                      latest,9.5,9.4 + 1 more...     6 hours ago
python                          latest,3.5,3.4 + 2 more...     6 hours ago
redis                           latest,3.2                     6 hours ago
ruby                            latest,2.3,2.2 + 1 more...     6 hours ago
wildfly                         10.1,10.0,9.0 + 2 more...      6 hours ago
[[email protected] ~]#

2: 查看image: 发现并没有mysql 的镜像,下面来下载一下:

[[email protected] ~]# oc describe is mysql
Name:            mysql
Namespace:        shp
Created:        6 hours ago
Labels:            <none>
Annotations:        openshift.io/display-name=MySQL
            openshift.io/image.dockerRepositoryCheck=2019-12-24T02:45:15Z
Docker Pull Spec:    <none>
Unique Images:        3
Tags:            4

5.7 (latest)
  tagged from centos/mysql-57-centos7:latest

下载image 到本地: docker pull centos/mysql-57-centos7:latest

3: 从openshift web console界面部署mysql

  1. 新建一个deployment,并加入到project: shp中:

Openshift 构建 容器化mysql

注意:上面创建mysql 的deployment 的时候,图中的"Enviroment Variable" 是要添加user_name,user_password,user_database 的参数的,否则,pod会创建失败的。

4创建好以后,尝试连接:

[[email protected] ~]# oc rsh mysql01-2-nayf1
sh-4.2$ mysql -usheng -psheng
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql>

实验成功!