阿里云上实战openshift5-定制并部署DB

1.定制MariaDB镜像,指定镜像的时区为中国

  【注】缺省的MariaDB镜像的时区与中国时区差8小时

1)定制MariaDB镜像

   远程登录master节点,执行:

  mkdir /home/honsen/customize_images/mariadb -p

  cd /home/honsen/customize_images/mariadb

  cp /etc/localtime localtime

   vi Dockerfile

                   FROMcentos/mariadb-101-centos7

                   MAINTAINERApollo.Yang


                   COPY./localtime /etc/localtime


                   #This default user is created in the openshift/base-centos7 image

                   USER1001


                   #Set the default port for applications built using this image

                   EXPOSE3306


                   #Set the default CMD for the image

                   CMD["/bin/run-mysqld"]

         docker build -t honsen/mariadb .

         docker images|grep honsen/

2)上传定制的MariaDB镜像至企业镜像仓库

  docker tag honsen/mariadb <企业镜像仓库地址>:5000/honsen_mariadb

  docker push <企业镜像仓库地址>:5000/honsen_mariadb

3)导入定制的MariaDB镜像,生成OpenShiftImage Stream

  oc import-image <企业镜像仓库地址>:5000/honsen_mariadb -n openshift --confirm


2.定制Redis镜像,指定镜像的时区为中国

  【注】缺省的Redis镜像的时区与中国时区差8小时

1)定制Redis镜像

   远程登录master节点,执行:

  mkdir /home/honsen/customize_images/redis -p

   cd /home/honsen/customize_images/redis

   cp /etc/localtime localtime

   vi Dockerfile

                   FROMcentos/redis-32-centos7

                   MAINTAINERApollo.Yang


                   COPY./localtime /etc/localtime


                   #This default user is created in the openshift/base-centos7 image

                   USER1001


                   #Set the default port for applications built using this image

                   EXPOSE6379


                   #Set the default CMD for the image

                   CMD["run-redis"]

         docker build -t honsen/redis .

         docker images|grep honsen/

2)上传定制的Redis镜像至企业镜像仓库

  docker tag honsen/redis <企业镜像仓库地址>:5000/honsen_redis

  docker push <企业镜像仓库地址>:5000/honsen_redis

3)导入定制的Redis镜像,生成OpenShiftImage Stream

  oc import-image <企业镜像仓库地址>:5000/honsen_redis -n openshift --confirm


3.OpenShift上创建你的project,如:honsen

 honsen用户登录OpenShift Web Console, 创建honsen project


4.honsen project上创建pvc

1)本地电脑创建honsen-pvc-mariadb.yaml

         apiVersion:v1

         kind:PersistentVolumeClaim

         metadata:

                    name: mariadb

         spec:

                    accessModes:

                      - ReadWriteOnce

                    selector:

                      matchLabels:

                             data: mariadb      

                    resources:

                      requests:

                             storage: 10Gi

2)本地电脑创建honsen-pvc-adminmariadb.yaml

         apiVersion:v1

         kind:PersistentVolumeClaim

         metadata:

                    name: adminmariadb

         spec:

                    accessModes:

                      - ReadWriteOnce

                    selector:

                      matchLabels:

                             data: admindb

                   resources:

                      requests:

                             storage: 2Gi

3)本地电脑创建honsen-pvc-redis.yaml

         apiVersion:v1

         kind:PersistentVolumeClaim

         metadata:

                    name: redis

         spec:

                    accessModes:

                      - ReadWriteOnce

                    selector:

                      matchLabels:

                             data: redis       

                    resources:

                      requests:

                             storage: 2Gi

4)本地电脑创建honsen-pvc-user-icon.yaml          

         apiVersion:v1

         kind:PersistentVolumeClaim

         metadata:

                    name: user-icon

         spec:

                    accessModes:

                      - ReadWriteMany

                    selector:

                      matchLabels:

                             file: usericons           

                    resources:

                      requests:

                             storage: 10Gi

5)honsen用户登录OpenShift Web Console, 切换至honsen project, 导入以上yaml,创建PVC

6)远程登录master节点,查看honsen project的pvc

  oc get pvc -n honsen


5.honsen project部署Maria DB

1)部署定制时区后的MariaDB镜像

 honsen用户登录OpenShift Web Console, 切换至honsen project,点击右上角Add to

Project、选择Deploy Image

 Image Stream Tag,选openshift/honsen_mariadb:latest

 Name: mariadb

 Environment Variables:

         MYSQL_USER

         MYSQL_PASSWORD

         MYSQL_DATABASE

         MYSQL_ROOT_PASSWORD 

  点击右下角的Deploybutton

2)设置部署策略(数据库部署策略设为Recreate)

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选mariadb, 右上点击Actions、选Edit:

 Strategy Type: Recreate       

3)对接PVC

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选mariadb, 右上点击Actions、选Edit YAML:

  将:

     volumes:

       - emptyDir: {}

         name: mariadb-1

  改为:

     volumes:

       - persistentVolumeClaim:

           claimName: mariadb

         name: mariadb-1 

4)查看db

 OpenShift Web Console,点击左边菜单Applications、选Pods,

  列表中选mariadb,Terminal:

         sh-4.2$mysql -uroot 

         MariaDB[(none)]> show databases;

         MariaDB[(none)]> use honsenflagdb;

         MariaDB[honsenflagdb]> select now() from dual;

         MariaDB[honsenflagdb]> show tables;

5)设置健康检测

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选mariadb, 右上点击Actions、选Edit HealthCheck:

  AddReadiness Probe:

           *Type: Container Command

           *Command: /bin/sh -i -cMYSQL_PWD="$MYSQL_PASSWORD" mysql -h 127.0.0.1 -u $MYSQL_USER -D$MYSQL_DATABASE -e 'SELECT 1'

  AddLiveness Probe:

           *Type: TCP Socket

           *Port: 3306



6.honsen project部署Admin MariaDB

1)部署定制时区后的MariaDB镜像

 honsen用户登录OpenShift Web Console, 切换至honsen project,点击右上角Add to

Project、选择Deploy Image

 Image Stream Tag,选openshift/honsen_mariadb:latest

 Name: adminmariadb

 Environment Variables:

         MYSQL_USER

         MYSQL_PASSWORD

         MYSQL_DATABASE

         MYSQL_ROOT_PASSWORD 

  点击右下角的Deploybutton

2)设置部署策略(数据库部署策略设为Recreate)

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选adminmariadb,右上点击Actions、选Edit:

 Strategy Type: Recreate 

3)对接PVC

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选adminmariadb,右上点击Actions、选Edit YAML:

  将:

     volumes:

       - emptyDir: {}

         name: adminmariadb-1

  改为:

     volumes:

       - persistentVolumeClaim:

           claimName: adminmariadb

         name: adminmariadb-1

4)查看db

 OpenShift Web Console,点击左边菜单Applications、选Pods,

  列表中选adminmariadb,Terminal:

         sh-4.2$mysql -uroot 

         MariaDB[(none)]> show databases;

         MariaDB[(none)]> use admindb;

         MariaDB[admindb]> select now() from dual;

         MariaDB[admindb]> show tables;

5)设置健康检测

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选adminmariadb,右上点击Actions、选Edit Health Check:

  AddReadiness Probe:

           *Type: Container Command

           *Command: /bin/sh -i -cMYSQL_PWD="$MYSQL_PASSWORD" mysql -h 127.0.0.1 -u $MYSQL_USER -D$MYSQL_DATABASE -e 'SELECT 1'

  AddLiveness Probe:

           *Type: TCP Socket

           *Port: 3306


7.honsen project部署Redis

1)部署定制时区后的Redis镜像

 honsen用户登录OpenShift Web Console, 切换至honsen project,点击右上角Add to

Project、选择Deploy Image

 Image Stream Tag,选openshift/honsen_redis:latest

 Name: redis

 Environment Variables:

         REDIS_PASSWORD

  点击右下角的Deploybutton

2)对接PVC

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选redis, 右上点击Actions、选Edit YAML:

  将:

     volumes:

       - emptyDir: {}

         name: redis-1

  改为:

     volumes:

       - persistentVolumeClaim:

           claimName: redis

         name: redis-1 

3)查看db

 OpenShift Web Console,点击左边菜单Applications、选Pods,

  列表中选redis,Terminal:

         sh-4.2$redis-cli -a $REDIS_PASSWORD

         127.0.0.1:6379>keys *

4)设置部署策略(数据库部署策略设为Recreate)

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选redis, 右上点击Actions、选Edit:

 Strategy Type: Recreate     

5)设置健康检测

 OpenShift Web Console,点击左边菜单Applications、选Deployment,

  列表中选redis, 右上点击Actions、选Edit HealthCheck:

  AddReadiness Probe:

           *Type: Container Command

           *Command: /bin/sh -i -c test"$(redis-cli -h 127.0.0.1 -a $REDIS_PASSWORD ping)" =="PONG"

  AddLiveness Probe:

           *Type: TCP Socket

           *Port: 6379

你可能感兴趣的:(阿里云上实战openshift5-定制并部署DB)