redis集群6.2.6

redis集群6.2.6,第1张

tee redis-all.yaml<<-'EOF'
apiVersion: v1
kind: Service
metadata:
  name: redis
  namespace: test01
  labels:
    app: redis
spec:
  ports:
  - port: 6379
    targetPort: 6379
    name: redis-port
  clusterIP: None
  selector:
    app: redis
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
  namespace: test01
spec:
  selector:
    matchLabels:
      app: redis
  serviceName: "redis-service"
  replicas: 6
  template:
    metadata:
      labels:
        app: redis
    spec:
      terminationGracePeriodSeconds: 20
      containers:
      - name: redis
        image: redis:6.2.6-alpine
        command:
          - "redis-server"
        args:
          - "/etc/redis/redis.conf"         #redis-server后面跟的参数,换行代表空格
          - "--protected-mode"              #允许外网访问
          - "no"
        # command: redis-server /etc/redis/redis.conf --protected-mode no
        resources:
          requests:
            cpu: "100m"
            memory: "100Mi"
        ports:
            - name: redis
              containerPort: 6379
              protocol: "TCP"
        volumeMounts:
          - name: "redis-conf"
            mountPath: "/etc/redis"
          - name: "redis-data"
            mountPath: "/var/lib/redis"
      volumes:
      - name: "redis-conf"
        configMap:
          name: "redis-conf"
          items:
            - key: "redis.conf"
              path: "redis.conf"
  volumeClaimTemplates:
  - metadata:
      name: "redis-data"
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: openebs-hostpath
      resources:
        requests:
          storage: 1Gi

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-conf
  namespace: test01
data:
  redis.conf: |
    appendonly yes
    cluster-enabled yes
    cluster-config-file /var/lib/redis/nodes.conf
    cluster-node-timeout 5000
    dir /var/lib/redis
    port 6379
EOF

手动创建集群

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

自动创建集群

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install staging bitnami/redis-cluster \
  --set usePassword=false \
  --set replica.replicaCount=6 \
  --set persistence.size=1Gi \
  --set metrics.enabled=true \
  --set persistence.storageClass=openebs-hostpath

#开启 metrics会开启边车

官网

https://github.com/bitnami/charts/tree/master/bitnami/redis-cluster
tee ui-redis.yaml<<-'EOF'
apiVersion: v1
kind: Service
metadata:
  name: redisinsight-service
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8001
    nodePort: 31888
  selector:
    app: redisinsight
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redisinsight
  labels:
    app: redisinsight
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redisinsight
  template:
    metadata:
      labels:
        app: redisinsight
    spec:
      containers:
      - name: redisinsight
        image: redislabs/redisinsight:1.7.0
        ports:
        - containerPort: 8001
        volumeMounts:
        - name: db
          mountPath: /db
      volumes:
      - name: db
        emptyDir: {}
EOF


redis一主2从
  • bitnami/redis 比较特殊MASTER的存储需要提前创建pvc
# kubectl get pvc
NAME                              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
redis     Bound    pvc-498df4ed-0d9f-46ac-81a9-e1a589158bef   1Gi        RWO            nfs-so             46m
helm install dbs bitnami/redis \
  --set replica.persistence.enabled=true \
  --set master.persistence.existingClaim=redis \
  --set auth.password="12345wqe" \
  --set replica.replicaCount=2 \
  --set replica.persistence.size=1G \
  --set replica.persistence.storageClass=openebs-hostpath

#从可以享受storageClass的动态存储
获取密码
kubectl get secret --namespace default dbs-redis -o jsonpath="{.data.redis-password}" | base64 --decode
[root@master128 mnt]# kubectl get pods | grep dbs
dbs-redis-master-0              1/1     Running   0          41m
dbs-redis-replicas-0            1/1     Running   0          41m
dbs-redis-replicas-1            1/1     Running   0          40m
模板方式
helm pull bitnami/redis --untar
helm template redis/  --name-template db-redis  > redis-test.yaml
kubectl apply -f redis-test.yaml

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/725573.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存