使用helm部署 redis 单机版

发布时间:2024年01月21日

1、配置helm redis repo

helm repo add bitnami https://charts.bitnami.com/bitnami

2 安装下载helm redis

下面是默认安装,不过前往别直接拿着下面安装命令就安装,官方默认安装的默认参数配置往往和我们实际场景不一样,需要配置一些参数

helm install my-redis bitnami/redis --version 18.7.0

2.1 下载helm redis

helm pull bitnami/redis --version 18.7.0

2.2?查看storageclass

如果环境中没有storageclass,就需自己安装存储支持或者采用云厂商的storageclass,内网环境推荐openebs,测试nfs就行了。

我的默认storageclass是openebs-hostpath,我的k8s环境上安装的openebs来做存储支持。当然如果有其他支持storageclass的也可以,比如nfs、云厂商sc,这里不做过多解释。

[root@k8s-master01 redis]# kubectl get storageclass
NAME                         PROVISIONER        RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
openebs-device               openebs.io/local   Delete          WaitForFirstConsumer   false                  20d
openebs-hostpath (default)   openebs.io/local   Delete          WaitForFirstConsumer   false                  20d

2.3?通过指定my-values.yaml安装

不过在这里因为是安装单机版,并且需要配置一些参数,所以需要通过--values配置一些参数

global:
  storageClass: "openebs-hostpath"
  redis:
    password: "redis123"

architecture: standalone

commonConfiguration: |-
  appendonly yes
  save "300 10"

master:
  resources:
    limits: 
      cpu: 2
      memory: 4Gi
    requests: 
      cpu: 500m
      memory: 2Gi
  
  nodeSelector: {}
  tolerations: []

  persistence:
    size: 10Gi

  service:
    type: NodePort
    nodePorts:
      redis: "30202"
  • storageClass可以不用配置,因为我的默认storageClass已经配置。
  • password 配置密码
  • architecture 配置单机部署
  • commonConfiguration 配置redis的存储策略
  • master 主redis相关配置

安装前测试:

helm -n newland install redis -f my-values.yaml ./redis --dry-run

安装:

helm -n newland install redis -f my-values.yaml ./redis

?2.4 直接修改values.yaml

我用的比较多的是直接修改values.yaml,修改的参数和上面的一样,找到对应的位置修改

安装测试:

[root@k8s-master01 redis]# helm install redis  -n newland ../redis --dry-run

安装:

[root@k8s-master01 redis]# helm install redis  -n newland ../redis

2.5 查看安装情况

helm查看安装:

[root@k8s-master01 redis]# helm list
NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION
[root@k8s-master01 redis]# helm list -n newland
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
elasticsearch   newland         3               2024-01-01 11:26:33.538207701 +0800 CST deployed        elasticsearch-7.7.1     7.7.1      
kibana          newland         3               2024-01-01 11:45:37.329407575 +0800 CST deployed        kibana-7.7.1            7.7.1      
redis           newland         1               2024-01-21 14:36:37.627113594 +0800 CST deployed        redis-18.7.0            7.2.4 

查看k8s安装情况:

[root@k8s-master01 redis]# kubectl get pod -n newland
NAME                             READY   STATUS    RESTARTS   AGE
elasticsearch-master-0           1/1     Running   0          20d
kibana-kibana-59f98df5c9-fn6n8   1/1     Running   0          20d
redis-master-0                   1/1     Running   0          3m8s
[root@k8s-master01 redis]# kubectl get service -n newland
NAME                            TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                         AGE
elasticsearch-master            NodePort    10.0.0.93    <none>        9200:32478/TCP,9300:30815/TCP   20d
elasticsearch-master-headless   ClusterIP   None         <none>        9200/TCP,9300/TCP               20d
kibana-kibana                   NodePort    10.0.0.246   <none>        5601:30062/TCP                  20d
redis-headless                  ClusterIP   None         <none>        6379/TCP                        3m52s
redis-master                    NodePort    10.0.0.123   <none>        6379:30379/TCP                  3m52s
[root@k8s-master01 redis]# kubectl get pv,pvc -n newland
NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                                             STORAGECLASS       REASON   AGE
persistentvolume/pvc-2909b96d-6de8-4dd1-9684-d084fde78bac   30Gi       RWO            Delete           Bound    newland/elasticsearch-master-elasticsearch-master-0               openebs-hostpath            20d
persistentvolume/pvc-746fb993-a14e-4d41-a9a5-ea188e66da68   8Gi        RWO            Delete           Bound    newland/redis-data-redis-master-0                                 openebs-hostpath            4m25s
persistentvolume/pvc-a9524463-9bdf-4ce6-9b2b-cbb3277235ae   20Gi       RWO            Delete           Bound    kubesphere-monitoring-system/prometheus-k8s-db-prometheus-k8s-0   openebs-hostpath            20d

NAME                                                                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
persistentvolumeclaim/elasticsearch-master-elasticsearch-master-0   Bound    pvc-2909b96d-6de8-4dd1-9684-d084fde78bac   30Gi       RWO            openebs-hostpath   20d
persistentvolumeclaim/redis-data-redis-master-0                     Bound    pvc-746fb993-a14e-4d41-a9a5-ea188e66da68   8Gi        RWO            openebs-hostpath   4m29s

2.6 测试redis安装情况

[root@k8s-master01 redis]# kubectl exec -n newland redis-master-0 -it -- /bin/sh
$ redis-cli -a 密码
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> get a
(nil)

通过测试可以看出安装成功了,我们本地需要连接redis直接使用nodeport端口30379,如果是k8s内直接使用service:6379就行了

文章来源:https://blog.csdn.net/liu289747235/article/details/135728997
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。