开发者openshift4使用入门教程 - 11 - 部署redis - 单实例模式

2022-04-21 14:16:28 浏览数 (1)

  • 一 概述
  • 二 准备工作
  • 三 Redis 单实例部署
  • 四 使用Redis
  • 脚注

一 概述

一句话总结本文内容:

如何将以下 Redis 单实例 部署到OpenShift 4.

二 Redis 单实例部署

创建新Redis应用, 多个版本可供选择:

  1. 临时存储Redis 3.2版本oc new-app --name=redis --template=redis-ephemeral:3.2
  2. 临时存储Redis 5.0版本oc new-app --name=redis --image-stream=redis-5-rhel7:latest
  3. 持久化存储Redis 3.2版本oc new-app --name=redis --template=redis-persistent:3.2 --param=VOLUME_CAPACITY=1Gi

示例输出

代码语言:javascript复制
$ oc new-app --template=redis-ephemeral --name=redis
--> Deploying template "openshift/redis-ephemeral" to project demo

    Redis (Ephemeral)
    ---------
    Redis in-memory data structure store, without persistent storage. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/redis-container/blob/master/3.2.

    WARNING: Any data stored will be lost upon pod destruction. Only use this template for testing

    The following service(s) have been created in your project: redis.

            Password: onTXNxV05Nsiea5c
    Connection URL: redis://redis:6379/

    For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/redis-container/blob/master/3.2.

    * With parameters:
        * Memory Limit=512Mi
        * Namespace=openshift
        * Database Service Name=redis
        * Redis Connection Password=onTXNxV05Nsiea5c # generated
        * Version of Redis Image=3.2

--> Creating resources ...
    secret "redis" created
    service "redis" created
    deploymentconfig.apps.openshift.io "redis" created
--> Success
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
    'oc expose svc/redis'
    Run 'oc status' to view your app.


oc new-app --name=redis --image-stream=redis-5-rhel7:latest
--> Found image 3273270 (3 months old) in image stream "openshift/redis-5-rhel7" under tag "latest" for "redis-5-rhel7:latest"

    Redis 5
    -------
    Redis 5 available as container, is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. You can run atomic operations on these types, like appending to a string; incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set. In order to achieve its outstanding performance, Redis works with an in-memory dataset. Depending on your use case, you can persist it either by dumping the dataset to disk every once in a while, or by appending each command to a log.

    Tags: database, redis, redis5, rh-redis5

    * This image will be deployed in deployment config "redis"
    * Port 6379/tcp will be load balanced by service "redis"
    * Other containers can access this service through the hostname "redis"
    * This image declares volumes and will default to use non-persistent, host-local storage.
    You can add persistent volumes later by running 'oc set volume dc/redis --add ...'

--> Creating resources ...
    imagestreamtag.image.openshift.io "redis:latest" created
    deploymentconfig.apps.openshift.io "redis" created
    service "redis" created
--> Success
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
    'oc expose svc/redis'
    Run 'oc status' to view your app.

三 使用Redis

容器内同一租户 的Java应用/微服务等直接通过以下域名 端口来使用: redis:6379 密码在部署时会有提示, 如:* Redis Connection Password=onTXNxV05Nsiea5c # generated, 如果提示没有就仔细在其他地方找找.

脚注

  1. --name=redis 可以按需调整;
  2. --param 可以传入创建部署时候的参数, 比如本次部署传入的是要求存储为1Gi.
  3. redis:6379 这种只能供 容器内同一租户 调用. 容器外 调用需要通过NodePort方式, 且可能需要开通NetworkPolicy防火墙策略.

0 人点赞