Rancher部署Redis单节点

9 篇文章 2 订阅
3 篇文章 0 订阅

上一篇介绍了如何Rancher部署Nacos,这里继续介绍通过Rancher部署Redis单节点

2 部署redis

2.1 准备ConfigMap

通过ConfigMap管理redis.conf文件

[root@uat-master standalone]# cat redis.conf 
appendonly yes
cluster-enabled no
#cluster-config-file /var/lib/redis/nodes.conf
#cluster-node-timeout 5000
dir /var/lib/redis
port 6379
[root@uat-master standalone]# 
[root@uat-master standalone]# kubectl create configmap redis-alone-conf -n middleware --from-file=redis.conf
[root@uat-master standalone]# kubectl get cm -n middleware |grep redis-alone-
redis-alone-conf   1      76m
[root@uat-master standalone]# 

Rancher上查看
在这里插入图片描述
在这里插入图片描述

2.1 准备pvc

yaml文件

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    cattle.io/creator: norman
  name: redis-alone-data
  namespace: middleware
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 512Mi
  storageClassName: managed-nfs-storage
  volumeMode: Filesystem

创建、查看PVC

[root@uat-master standalone]# kubectl create -f  pvc.yaml
[root@uat-master standalone]# kubectl get pvc -n middleware |grep redis-alone-data
redis-alone-data    Bound    pvc-99f64e8c-f196-4f68-9094-29eaba68cf33   512Mi      RWO            managed-nfs-storage   63m
[root@uat-master standalone]# 

2.2 部署redis

yaml文件

[root@uat-master standalone]# cat redis-alone-deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: middleware
spec:
  #serviceName: redis
  replicas: 1
  selector:
    matchLabels:
      app: redis
      appCluster: redis-alone
  template:
    metadata:
      labels:
        app: redis
        appCluster: redis-alone
    spec:
      terminationGracePeriodSeconds: 20
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - redis
              topologyKey: kubernetes.io/hostname
      containers:
      - name: redis
        image: redis:6.0.10
        imagePullPolicy: IfNotPresent
        command:
          - "redis-server"
        args:
          - "/etc/redis/redis.conf"
          - "--protected-mode"
          - "no"
        resources:
          requests:
            cpu: "200m"
            memory: "250Mi"
        ports:
        - containerPort: 6379
          name: redis
          protocol: TCP
        volumeMounts:
        - name: conf
          mountPath: /etc/redis
        - name: data
          mountPath: /var/lib/redis
          subPath: data
      volumes:
      - name: conf
        configMap:
          name: redis-alone-conf
          items:
          - key: redis.conf
            path: redis.conf
      - name: data
        persistentVolumeClaim:
          claimName: redis-alone-data
[root@uat-master standalone]# 

创建redis Deployment

[root@uat-master standalone]# kubectl create -f redis-alone-deployment.yaml
······
[root@uat-master standalone]# kubectl get pods -n middleware |grep redis
redis-5b6ddfcd68-x22tq                    1/1     Running   0          70m
[root@uat-master standalone]# 

2.3 部署service

为便于远程访问,这里以NodePort方式部署service

[root@uat-master standalone]# cat redis-alone-service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: redis-alone-access
  namespace: middleware
  labels:
    app: redis
spec:
  selector:
    app: redis
    appCluster: redis-alone
  ports:
  - name: redis-access
    protocol: TCP
    port: 6379
    targetPort: 6379
  type: NodePort
[root@uat-master standalone]# 

创建、查看service

[root@uat-master standalone]# kubectl apply -f redis-alone-service.yaml 
service/redis-alone-access unchanged
[root@uat-master standalone]# kubectl get svc -n middleware |grep redis-alone-access
redis-alone-access   NodePort    10.43.113.220   <none>        6379:31600/TCP                  69m
[root@uat-master standalone]# 

3 远程访问redis

先要确保k8s集群主机31600端口能够远程访问
这里使用Another Redis DeskTop Manager 工具,github地址:https://github.com/qishibo/AnotherRedisDesktopManager

配置连接:
在这里插入图片描述

连接成功
在这里插入图片描述

测试成功
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值