14

Dapr学习(2)之Rancher2.63(k8s&k3s)环境安装Dapr - xjk27400861

 3 years ago
source link: https://www.cnblogs.com/kunwn/p/16271944.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

前言:前面写过一篇关于dapr入门安装的文章,self-host模式,使用docker安装的本地调试环境,并进行了测试;本篇介绍k8s方式安装dapr,此文主要基于的环境是k3s,通过rancher2.6.3版管理工具进行快捷安装,并进行相关demo测试

1.k8s安装dapr介绍

参考官网:https://docs.dapr.io/zh-hans/operations/hosting/kubernetes/kubernetes-deploy/

官网推荐使用helm方式安装&高可用安装;这里不在赘述

image

2.Rancher2.6.3安装Dapr

  • Rancher 添加商店helm源:添加 Dapr 源;https://dapr.github.io/helm-charts/ 最新的安装源,添加到商店

    image
  • 进入应用商店,搜索dapr

    image
  • 安装最新版本,1.7.2版

    image
  • 由于我们安装了1.6.1版本,我们选择升级版本

    image
  • 安装成功后,我们可以在Rancher管理界面看到几个dapr组件

    image

3.配置 状态存储 和 发布/订阅 消息代理,查看官网:https://docs.dapr.io/zh-hans/reference/components-reference/supported-state-stores/ 可以看到状态存储等支持的数据库类型;

  • 我们这里使用官网推荐的redis作为状态存储

    image
  • 使用Rancher创建一个单实例的redis容器;Dapr使用redis存储,要求redis版本>5;镜像:index.docker.io/library/redis:6.2.6

    image

    image
    设置密码命令:redis-server --requirepass 123456
    环境变量也可以设置成空密码访问:ALLOW_EMPTY_PASSWORD=yes

4.Dapr快速入门demo之hello-kubernetes

  • 去github官网下载demo-1.7版本代码:https://github.com/dapr/quickstarts/tree/release-1.7/tutorials/hello-kubernetes

    image
  • 创建一个daprdemo的命名空间,部署nodejs服务
      命令:sudo kubectl apply -f node.yaml -n daprdemo
      查看部署状态:sudo kubectl rollout status deploy/nodeapp -n daprdemo
    
    image
  • 修改node.yaml文件,因为80端口已被占用,会导致部署问题,把80端口改为3000端口,与nodeapp释放端口一致

    image
  • nodeapp服务部署完毕后,可以通过rancher查看或者编辑对外访问端口,然后可通过k8s任一节点ip+端口访问nodeapp服务

    image
  • 我们也可以通过命令指定对外访问的端口,这样我就可以通过30018端口访问nodeapp:

      kubectl port-forward service/nodeapp 30018:3000
    
  • 我们通过浏览器,可以访问nodeapp服务,返回dapr的端口信息

    image
  • 我们在daprdemo的命名空间下,创建一个state组件,供nodeapp服务使用;要保证state组件与nodeapp服务同属于同一命名空间下,否则nodeapp服务是无法访问到state组件的

    image
  • 输入命令,构建state组件

      sudo kubectl apply -f redis-state.yaml -n daprdemo
    
    image
  • 使用apifox工具,请求nodeapp服务,新建一个订单

    image
  • image

5.Rancher2.6.3 Dapr dashboard访问

  • 找到Dapr dashbord服务信息

    image
  • 点击进入dashbord界面

    image

6.部署python服务app

  • 输入命令部署app,并查看部署状态

      kubectl apply -f python.yaml -n daprdemo
      kubectl rollout status deploy/pythonapp -n daprdemo
    

    image
  • 查看nodeapp的日志

      kubectl logs --selector=app=node -c node --tail=-1 -n daprdemo
    

    image
  • 获取订单号

    image

7.清理所有应用(进入到yaml文件所在目录)

kubectl delete -f . -n daprdemo

8.Rancher查看Dapr组件信息

  • 在Rancher管理界面的“更多资源”节点下,dapr.io节点下查看

    image

9.组件的作用域参考官网:https://www.bookstack.cn/read/dapr-1.6.0-zh/38630b93719234c7.md


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK