redis-cluster
Less than 1 minute
redis-cluster
prepare
- k8s is ready
- argocd is ready and logged in
installation
- prepare
redis-cluster.yaml
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: redis-cluster spec: syncPolicy: syncOptions: - CreateNamespace=true project: default source: repoURL: https://charts.bitnami.com/bitnami chart: redis-cluster targetRevision: 9.6.1 helm: releaseName: redis-cluster values: | architecture: replication usePassword: true existingSecret: redis-cluster-credentials existingSecretPasswordKey: redis-password cluster: init: true nodes: 6 replica: 1 update: addNodes: false currentNumberOfNodes: 6 currentNumberOfReplicas: 1 image: registry: docker.io pullPolicy: IfNotPresent metrics: enabled: false image: registry: docker.io pullPolicy: IfNotPresent volumePermissions: enabled: false image: registry: docker.io pullPolicy: IfNotPresent sysctlImage: enabled: false registry: docker.io pullPolicy: IfNotPresent persistence: enabled: false destination: server: https://kubernetes.default.svc namespace: database
- prepare credentials secret
kubectl get namespaces database > /dev/null 2>&1 || kubectl create namespace database kubectl -n database create secret generic redis-cluster-credentials \ --from-literal=redis-password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 16)
- apply to k8s
kubectl -n argocd apply -f redis-cluster.yaml
- sync by argocd
argocd app sync argocd/redis-cluster
tests
- prepare
redis-cluster-tool.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: redis-cluster-tool labels: app.kubernetes.io/name: redis-cluster-tool spec: replicas: 1 selector: matchLabels: app.kubernetes.io/name: redis-cluster-tool template: metadata: labels: app.kubernetes.io/name: redis-cluster-tool spec: containers: - name: redis-cluster-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-cluster-credentials - name: TZ value: Asia/Shanghai command: - tail - -f - /etc/hosts
- apply to k8s
kubectl -n database apply -f redis-cluster-tool.yaml
- tests
kubectl -n database exec -it deployment/redis-cluster-tool -- \ redis-cli -h redis-cluster.database ping
kubectl -n database exec -it deployment/redis-cluster-tool -- \ redis-cli -c -h redis-cluster.database set mykey somevalue
kubectl -n database exec -it deployment/redis-cluster-tool -- \ redis-cli -c -h redis-cluster.database get mykey
kubectl -n database exec -it deployment/redis-cluster-tool -- \ redis-cli -c -h redis-cluster.database del mykey
kubectl -n database exec -it deployment/redis-cluster-tool -- \ redis-cli -c -h redis-cluster.database get mykey