redis
Less than 1 minute
redis
prepare
- k8s is ready
- argocd is ready and logged in
installation
- 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
- 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)
- apply to k8s
kubectl -n argocd apply -f redis.yaml
- sync by argocd
argocd app sync argocd/redis
tests
- 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
- apply to k8s
kubectl -n database apply -f redis-tool.yaml
- 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