OpenShift实战(四):OpenShift持久化存储Redis

时间:2021-09-23 03:00:55

1、模板定义

  修改OpenShift自带模板

[root@master1 pv]# oc edit template redis-persistent

  添加如下:

  OpenShift实战(四):OpenShift持久化存储Redis

  OpenShift实战(四):OpenShift持久化存储Redis

2、创建PV

  编辑redis pv json文件

[root@master1 pv]# cat data_redis.json 
{
  "apiVersion": "v1",
  "kind": "PersistentVolume",
  "metadata": {
    "name": "redis"
  },
  "spec": {
    "capacity": {
      "storage": "2Gi"
    },
    "accessModes": [ "ReadWriteOnce" ],
    "nfs": {
      "path": "/export/pv/data_redis",
      "server": "192.168.10.110"
    },
    "persistentVolumeReclaimPolicy": "Retain"
  }
}

  创建对应目录

[root@master1 pv]# mkdir /export/pv/data_redis
[root@master1 pv]# chown -R nfsnobody:nfsnobody !$
[root@master1 pv]# vim /etc/exports
[root@master1 pv]# cat !$
cat /etc/exports
/export/pv/docker_registry/  *(rw,sync,all_squash)
/export/pv/data_redis/  *(rw,sync,all_squash)
[root@master1 pv]# exportfs -r
[root@master1 pv]# systemctl reload nfs-server

  创建pv以及手动label

[root@master1 pv]# oc create -f data_redis.json 
persistentvolume "redis" created
 [root@master1 pv]# oc label pv redis disktype=data_redis
persistentvolume "redis" labeled
[root@master1 pv]# oc get pv --show-labels
NAME         CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM                           STORAGECLASS   REASON    AGE       LABELS
redis        2Gi        RWO           Retain          Available                                                            1m        disktype=data_redis
registrypv   100Gi      RWO           Retain          Bound       default/docker-registry-claim                            14h       disktype=registry

3、创建Redis pod

  登录控制台-选择要部署的project-点击Add to Project - Browse Catalog

  OpenShift实战(四):OpenShift持久化存储Redis

  OpenShift实战(四):OpenShift持久化存储Redis

  选择所使用的pv的label

  OpenShift实战(四):OpenShift持久化存储Redis

  点击create即可

  OpenShift实战(四):OpenShift持久化存储Redis

4、查看pod

  OpenShift实战(四):OpenShift持久化存储Redis