• k8s创建redis集群


    1.首先k8s要有StorangeClass,这里为data

     新建redis-cluster.yaml文件

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: redis-cluster
    data:
      update-node.sh: |
        #!/bin/sh
        REDIS_NODES="/data/nodes.conf"
        sed -i -e "/myself/ s/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/${POD_IP}/" ${REDIS_NODES}
        exec "$@"
      redis.conf: |+
        cluster-enabled yes
        cluster-require-full-coverage no
        cluster-node-timeout 15000
        cluster-config-file /data/nodes.conf
        cluster-migration-barrier 1
        appendonly yes
        protected-mode no
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: redis-cluster
    spec:
      serviceName: redis-cluster
      replicas: 6
      selector:
        matchLabels:
          app: redis-cluster
      template:
        metadata:
          labels:
            app: redis-cluster
        spec:
          containers:
          - name: redis
            image: redis:6.0.6
            ports:
            - containerPort: 6379
              name: client
            - containerPort: 16379
              name: gossip
            command: ["/conf/update-node.sh""redis-server""/conf/redis.conf"]
            env:
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            volumeMounts:
            - name: conf
              mountPath: /conf
              readOnly: false
            - name: data
              mountPath: /data
              readOnly: false
          volumes:
          - name: conf
            configMap:
              name: redis-cluster
              defaultMode: 0755
      volumeClaimTemplates:
      - metadata:
          name: data
        spec:
          accessModes: [ "ReadWriteOnce" ]
          resources:
            requests:
              storage: 5Gi
          storageClassName: data #改成NFS的名称

     执行命令: kubectl apply -f redis-cluster.yaml

    执行命令查看: kubectl get all

     3主3副的pod已经启动成功

    执行初始化集群命令:

    kubectl exec -it redis-cluster-0  -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods  -l  app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 ')
    输入:yes

     这个时候集群创建完成

  • 相关阅读:
    ZipOutputStream SharpZipLib 插件加密无法解密
    Bootstrap可视化页面布局
    Centos7中加载验证码图片报错
    Centos7中安装多版本dotnet core sdk
    NetCore中使用MySql操作数据库时发生异常
    NetCore写属性过滤时遇到的AutoFac注入的问题
    微信小程序采坑记
    PC共享网络,非软件
    hibernate HQL —— ReflectHelper.java:343
    hibernate SQL聚合查询
  • 原文地址:https://www.cnblogs.com/lidezhen/p/13423903.html
Copyright © 2020-2023  润新知