Redis 6.2.7 | with Helm Chart
Deploying a stateless Go app with Redis on Kubernetes | CalliCoder
https://rancher.com/blog/2019/deploying-redis-cluster/
charts/bitnami/redis at master · bitnami/charts
# helm repo add bitnami https://charts.bitnami.com/bitnami
# helm repo update
# helm pull bitnami/redis # redis-16.13.2.tgz, Redis 6.2.7
# helm show values ./redis-16.13.2.tgz > redis-16.13.2.helm-values.yaml
...(1)修改存储类:global.storageClass
...(2)修改运行模式:默认 replication 模式,我们使用 standalone 模式(测试目的);
# helm --namespace infra-database \
install redis bitnami/redis -f redis-16.13.2.helm-values.yaml \
--create-namespace
# helm --namespace infra-database \
upgrade redis bitnami/redis -f redis-16.13.2.helm-values.yaml
// ---------------------------------------------------------------------------- // 当执行成功后,产生如下输出:
...
Redis® can be accessed via port 6379 on the following DNS name from within your cluster:
redis-master.infra-database.svc.cluster.local
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace infra-database redis -o jsonpath="{.data.redis-password}" | base64 -d)
To connect to your Redis® server:
1. Run a Redis® pod that you can use as a client:
kubectl run --namespace infra-database redis-client --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis:6.2.7-debian-11-r11 --command -- sleep infinity
Use the following command to attach to the pod:
kubectl exec --tty -i redis-client \
--namespace infra-database -- bash
2. Connect using the Redis® CLI:
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-master
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace infra-database svc/redis-master 6379:6379 &
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379
通过 Manifest 部署
---
apiVersion: apps/v1 # API version
kind: Deployment
metadata:
name: redis-master # Unique name for the deployment
labels:
app: redis # Labels to be applied to this deployment
spec:
selector:
matchLabels: # This deployment applies to the Pods matching these labels
app: redis
role: master
tier: backend
replicas: 1 # Run a single pod in the deployment
template: # Template for the pods that will be created by this deployment
metadata:
labels: # Labels to be applied to the Pods in this deployment
app: redis
role: master
tier: backend
spec: # Spec for the container which will be run inside the Pod.
containers:
- name: master
image: redis
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
---
apiVersion: v1
kind: Service # Type of Kubernetes resource
metadata:
name: redis-master # Name of the Kubernetes resource
labels: # Labels that will be applied to this resource
app: redis
role: master
tier: backend
spec:
ports:
- port: 6379 # Map incoming connections on port 6379 to the target port 6379 of the Pod
targetPort: 6379
selector: # Map any Pod with the specified labels to this service
app: redis
role: master
tier: backend
kubectl apply -f ./
连接集群
kubectl create deployment redis-cli –image=redis:7.4.0 — sleep infinity
kubectl create deployment redis-cli –image=redis:5 — sleep infinity