2017年1月21日星期六

OpenShift_034:部署 mywebsql docker image 访问 mysql 数据库

环境:OCP 3.4

本实验全部材料来自我的同事陈耿,在此表示感谢!

mywebsql docker image 可以作为数据库客户端访问多种类型的数据库。

1. 下载 mywebsql docker image(在 MAC 机器上操作)
docker pull quantumobject/docker-mywebsql
docker save -o mywebsql.tar.gz quantumobject/docker-mywebsql
scp mywebsql.tar.gz root@192.168.56.112:/opt/ose/images/

2. 加载 mywebsql docker image (在 Registry 机器上操作)
docker load -i mywebsql.tar.gz
docker tag quantumobject/docker-mywebsql:latest registry.example.com:5000/quantumobject/docker-mywebsql:latest
docker push registry.example.com:5000/quantumobject/docker-mywebsql

3. 创建 mywebsql 应用(在 Master 机器上操作)
允许 root 用户访问容器
oc login -u system:admin
oadm policy add-scc-to-user anyuid -z default
oc edit scc anyuid

创建 mywebsql 应用
oc new-app registry.example.com:5000/quantumobject/docker-mywebsql:latest --name=mywebsql --insecure-registry=true
输出如下:
--> Found Docker image b24dd9f (10 weeks old) from registry.example.com:5000 for "registry.example.com:5000/quantumobject/docker-mywebsql:latest"

    * An image stream will be created as "mywebsql:latest" that will track this image
    * This image will be deployed in deployment config "mywebsql"
    * Port 80/tcp will be load balanced by service "mywebsql"
      * Other containers can access this service through the hostname "mywebsql"
    * WARNING: Image "registry.example.com:5000/quantumobject/docker-mywebsql:latest" runs as the 'root' user which may not be permitted by your cluster administrator

--> Creating resources ...
    imagestream "mywebsql" created
    deploymentconfig "mywebsql" created
    service "mywebsql" created
--> Success
    Run 'oc status' to view your app.

可以看到 mywebsql 应用生成了 is、dc、service,但是没有生成 bc,因为从 image 构建应用不需要生成 bc。

接下来手动 Deploy 并创建 route。

4. 测试
访问 http://mywebsql-applications.apps.example.com,连接数据库了。

5. 如果有错,执行以下步骤清理,然后重做(在 Master 机器上操作)
运行 oc delete all -l app=mywebsql,删除 mywebsql 应用所有资源对象。
运行 oc delete is/mywebsql dc/mywebsql routes/mywebsql svc/mywebsql 删除全部对象。


没有评论: