Skip to main content

redis

ben.wangzLess than 1 minute

redis

prepare

  1. k8s is ready
  2. argocd is ready and logged in

installation

  1. prepare redis.yaml
    • apiVersion: argoproj.io/v1alpha1
      kind: Application
      metadata:
        name: redis
      spec:
        syncPolicy:
          syncOptions:
          - CreateNamespace=true
        project: default
        source:
          repoURL: https://charts.bitnami.com/bitnami
          chart: redis
          targetRevision: 18.16.0
          helm:
            releaseName: redis
            values: |
              architecture: replication
              auth:
                enabled: true
                sentinel: true
                existingSecret: redis-credentials
              master:
                count: 1
                disableCommands:
                  - FLUSHDB
                  - FLUSHALL
                persistence:
                  enabled: false
              replica:
                replicaCount: 3
                disableCommands:
                  - FLUSHDB
                  - FLUSHALL
                persistence:
                  enabled: false
              image:
                registry: docker.io
                pullPolicy: IfNotPresent
              sentinel:
                enabled: false
                persistence:
                  enabled: false
                image:
                  registry: docker.io
                  pullPolicy: IfNotPresent
              metrics:
                enabled: false
                image:
                  registry: docker.io
                  pullPolicy: IfNotPresent
              volumePermissions:
                enabled: false
                image:
                  registry: docker.io
                  pullPolicy: IfNotPresent
              sysctl:
                enabled: false
                image:
                  registry: docker.io
                  pullPolicy: IfNotPresent
        destination:
          server: https://kubernetes.default.svc
          namespace: database
      
      
  2. prepare credentials secret
    • kubectl get namespaces database > /dev/null 2>&1 || kubectl create namespace database
      kubectl -n database create secret generic redis-credentials \
          --from-literal=redis-password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 16)
      
  3. apply to k8s
    • kubectl -n argocd apply -f redis.yaml
      
  4. sync by argocd
    • argocd app sync argocd/redis
      

tests

  1. prepare redis-tool.yaml
    • apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: redis-tool
        labels:
          app.kubernetes.io/name: redis-tool
      spec:
        replicas: 1
        selector:
          matchLabels:
            app.kubernetes.io/name: redis-tool
        template:
          metadata:
            labels:
              app.kubernetes.io/name: redis-tool
          spec:
            containers:
            - name: redis-tool
              image: docker.io/bitnami/redis:7.2.4-debian-12-r8
              imagePullPolicy: IfNotPresent
              env:
              - name: REDISCLI_AUTH
                valueFrom:
                  secretKeyRef:
                    key: redis-password
                    name: redis-credentials
              - name: TZ
                value: Asia/Shanghai
              command:
              - tail
              - -f
              - /etc/hosts
      
      
  2. apply to k8s
    • kubectl -n database apply -f redis-tool.yaml
      
  3. tests
    • kubectl -n database exec -it deployment/redis-tool -- \
          redis-cli -c -h redis-master.database ping
      
    • kubectl -n database exec -it deployment/redis-tool -- \
          redis-cli -c -h redis-master.database set mykey somevalue
      
    • kubectl -n database exec -it deployment/redis-tool -- \
          redis-cli -c -h redis-master.database get mykey
      
    • kubectl -n database exec -it deployment/redis-tool -- \
          redis-cli -c -h redis-master.database del mykey
      
    • kubectl -n database exec -it deployment/redis-tool -- \
          redis-cli -c -h redis-master.database get mykey