Openshift 3.11部署容器化mysql

OKD 3.11 提供了mysql数据库的catalog,以下为使用okd311从web console拉起mysql的步骤。

创建storage class

如果OKD集群刚装好,还没有设置storage class,需要先创建storage class,并将创建可用的storage class设置为默认。

  • 创建storage class
    本文使用glusterFS,首先需要编写storage class的描述文件如下:
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
  name: gluster-dyn
provisioner: kubernetes.io/glusterfs
parameters:
# since k8s 1.5, endpoint is not necessary for dynamic provisioning
#  endpoint: "heketi-ep"
  resturl: "http://x.x.x.x:8080"
  restuser: "admin"
  restuserkey: "storage secret"
  secretName: "heketi-secret"
  secretNameSpace: "default"
  volumetype: "replicate:2"

---
apiVersion: v1
kind: Secret
metadata:
  name: heketi-secret
  namespace: default
data:
  # base64 encoded password. E.g.: echo -n "mypassword" | base64
  key: a0xkODM0ZGFkRXNmd2N2
type: kubernetes.io/glusterfs

使用命令创建storage class。

oc create -f storage-class.yaml

检查是否成功创建

[root@host-10-1-236-72 data]# oc get storageclass
NAME                    PROVISIONER               AGE
gluster-dyn           kubernetes.io/glusterfs     5d
  • 将创建好的storage class设为默认值
    因为在部署mysql过程中,会自动绑定默认的storage class创建pvc,因此首先需要将创建好的storage class设为默认值。
    方法如下:
oc patch storageclass gluster-dyn -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

如果执行成功,检查storage class,会在name后标注default。

[root@host-10-1-236-72 data]# oc get storageclass
NAME                    PROVISIONER               AGE
gluster-dyn (default)   kubernetes.io/glusterfs   5d
准备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并不是镜像仓库,只是镜像的一种映射,具体的镜像实体还需要自己准备。
    OpenShift的默认的IS都在project openshift中
    查看Image Streams
[root@host-10-1-236-72 data]# oc get is -n openshift
NAME               DOCKER REPO                                                   TAGS                          UPDATED
dotnet             docker-registry.default.svc:5000/openshift/dotnet             2.0
dotnet-runtime     docker-registry.default.svc:5000/openshift/dotnet-runtime     2.0,2.1
httpd              docker-registry.default.svc:5000/openshift/httpd              2.4
jenkins            docker-registry.default.svc:5000/openshift/jenkins            2,1
mariadb            docker-registry.default.svc:5000/openshift/mariadb            10.1,10.2
mongodb            docker-registry.default.svc:5000/openshift/mongodb            2.4,2.6,3.2 + 2 more...
mysql              docker-registry.default.svc:5000/openshift/mysql              5.7,latest,5.5 + 1 more...    6 days ago
nginx              docker-registry.default.svc:5000/openshift/nginx              1.10,1.12,1.8
nodejs             docker-registry.default.svc:5000/openshift/nodejs             8-RHOAR,0.10,10 + 3 more...
perl               docker-registry.default.svc:5000/openshift/perl               5.16,5.20,5.24 + 1 more...
php                docker-registry.default.svc:5000/openshift/php                5.5,5.6,7.0 + 1 more...
postgresql         docker-registry.default.svc:5000/openshift/postgresql         9.2,9.4,9.5 + 2 more...
python             docker-registry.default.svc:5000/openshift/python             3.4,3.5,3.6 + 2 more...
redis              docker-registry.default.svc:5000/openshift/redis              3.2
ruby               docker-registry.default.svc:5000/openshift/ruby               2.0,2.2,2.3 + 2 more...
wildfly            docker-registry.default.svc:5000/openshift/wildfly            10.1,11.0,12.0 + 4 more...

使用describe查看mysql

oc describe is mysql

mysql使用的镜像为centos/mysql-57-centos7,下载镜像,并上传至私有仓库后,修改mysql的is.
修改IS tag命令如下:

oc tag 10.1.236.77:5000/centos/mysql-57-centos7:latest mysql:5.7
从openshift web console界面部署mysql
  1. 新建一个project,并进入到project中
  2. 在Catalog下 Database中选择mysql,进入到部署wizard。


    image.png
  3. 点击下一步,输入必须的参数后,点击create。创建成功后,在下方会显示mysql的基本信息如下


    image.png
验证mysql
  1. 从web console查看Deployment的状态为active, pod的状态为Running.
  2. 登录mysql pods, 命令行连接mysql。
[root@host-10-1-236-72 data]# oc rsh mysql-1-8h297
sh-4.2$ mysql -ugeng -p123456
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 86772
Server version: 5.7.21 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| sampledb           |
+--------------------+
2 rows in set (0.02 sec)

你可能感兴趣的:(Openshift 3.11部署容器化mysql)