k8s&dapr模式运行
Dapr uninstall --all dapr init -k
新增docker支持
添加backend的k8s配置文件dapr-backend.yaml
kind: Deployment apiVersion: apps/v1 metadata: name: dapr-deploy-backend labels: service: backend spec: replicas: 2 selector: matchLabels: service: backend template: metadata: labels: service: backend annotations: dapr.io/enabled: "true" dapr.io/app-id: "backend" #这里要注意app-id要与front调用的名称要一致 dapr.io/app-port: "8080" #dapr.io/config: "dapr-config" spec: containers: - name: daprbackend image: daprbackend imagePullPolicy: Never ports: - name: http containerPort: 8080 protocol: TCP --- apiVersion: v1 kind: Service metadata: name: daprbackend labels: service: backend spec: type: NodePort ports: - port: 80 targetPort: 8080 nodePort: 30003 protocol: TCP name: http - port: 50001 targetPort: 50001 nodePort: 30042 protocol: TCP name: dapr-grpc selector: service: backend
添加backend的k8s配置文件dapr-backend.yaml
kind: Deployment apiVersion: apps/v1 metadata: name: dapr-deploy-front labels: service: front spec: replicas: 1 selector: matchLabels: service: front template: metadata: labels: service: front annotations: dapr.io/enabled: "true" dapr.io/app-id: "front" dapr.io/app-port: "8080" #dapr.io/config: "dapr-config" spec: containers: - name: daprfrontend image: daprfrontend imagePullPolicy: Never ports: - name: http containerPort: 8080 protocol: TCP --- apiVersion: v1 kind: Service metadata: name: daprfrontend labels: service: front spec: type: NodePort ports: - port: 80 targetPort: 8080 nodePort: 30002 protocol: TCP name: http - port: 50001 targetPort: 50001 nodePort: 30041 protocol: TCP name: dapr-grpc selector: service: front
启动批处理文件start-all.bat
docker build -t daprbackend -f backend/Dockerfile . docker build -t daprfrontend -f front/Dockerfile . Dapr uninstall --all dapr init -k kubectl apply -f k8s/dapr-backend.yaml kubectl apply -f k8s/dapr-front.yaml pause
停止批处理文件stop-all.bat
kubectl delete -f ./k8s/dapr-front.yaml kubectl delete -f ./k8s/dapr-backend.yaml Dapr uninstall --all pause
运行成功验证
访问http://localhost:30002/swagger/index.html
显示如下说明已经成功
项目源码下载
常用命令
dapr uninstall Dapr uninstall --all dapr init dapr init -k dapr run --app-id myapp --dapr-http-port 3500 --dapr-grpc-port 50001 -- dotnet run #运行.net项目 dapr run --app-id backend --app-port 5001 dotnet run dapr invoke --app-id backend --method WeatherForecast #调用接口 dapr invoke --app-id backend --method WeatherForecast --verb GET CSS 复制 全屏