概述
dapr支持self-hosted和Kubernetes两种模式,官方教程是默认以self-hosted进行演示的,我们总结Kubernetes下的dapr使用。
过程
安装
# 1. 安装cli
wget https://raw.githubusercontent.com/dapr/cli/master/install/install.sh
./install.sh
wget https://github.com/dapr/cli/releases/download/v1.9.1/dapr_linux_amd64.tar.gz
tar zxvf dapr_linux_amd64.tar.gz
cp dapr /usr/local/bin/
# 2. cli安装Kubernetes
dapr init -k --enable-mtls=false
k get pods -n dapr-system
start
git clone https://github.com/dapr/quickstarts.git
cd quickstarts/tutorials/hello-kubernetes
helm install redis bitnami/redis
cd tutorials/hello-kubernetes
NAME: redis
LAST DEPLOYED: Wed Jan 4 14:13:41 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 17.4.1
APP VERSION: 7.0.7
** Please be patient while the chart is being deployed **
Redis® can be accessed on the following DNS names from within your cluster:
redis-master.default.svc.cluster.local for read/write operations (port 6379)
redis-replicas.default.svc.cluster.local for read-only operations (port 6379)
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace default 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 default redis-client --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis:7.0.7-debian-11-r7 --command -- sleep infinity
Use the following command to attach to the pod:
kubectl exec --tty -i redis-client \
--namespace default -- bash
2. Connect using the Redis® CLI:
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-master
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-replicas
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace default svc/redis-master 6379:6379 &
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379