如何让hasura websocket在本地Kubernetes集群上工作?

如何让hasura websocket在本地Kubernetes集群上工作?,kubernetes,websocket,nuxt.js,apollo,hasura,Kubernetes,Websocket,Nuxt.js,Apollo,Hasura,我在Windows下设置了一个本地K8s群集,如下所示: 安装桌面docker 在docker for desktop中,启用kubernetes 安装nginx入口控制器 kubectl应用-fhttps://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.29.0/deploy/static/mandatory.yaml kubectl应用-fhttps://raw.githubusercontent.com/kubern

我在Windows下设置了一个本地K8s群集,如下所示:

  • 安装桌面docker
  • 在docker for desktop中,启用kubernetes
  • 安装nginx入口控制器
  • kubectl应用-fhttps://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.29.0/deploy/static/mandatory.yaml
    kubectl应用-fhttps://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.29.0/deploy/static/provider/cloud-generic.yaml
    
  • 将以下域添加到主机(
    C:\Windows\System32\drivers\etc\hosts
  • 我在这里没有做什么特别的事情,我把一切都保持在默认设置

    然后,我使用以下YAML将hasura部署到集群中(为了简洁起见,我不展示postgres部署):

    ---
    #来源:api/templates/secrets.yaml
    版本:v1
    种类:秘密
    元数据:
    名称:api
    标签:
    app.kubernetes.io/name:api
    helm.sh/chart:api-0.0.0
    app.kubernetes.io/instance:api
    app.kubernetes.io/version:“0.0”
    app.kubernetes.io/managed-by:Helm
    类型:不透明
    数据:
    管理员机密:“c2VjcmV0”
    ---
    #来源:api/templates/service.yaml
    版本:v1
    种类:服务
    元数据:
    名称:api
    标签:
    app.kubernetes.io/name:api
    helm.sh/chart:api-0.0.0
    app.kubernetes.io/instance:api
    app.kubernetes.io/version:“0.0”
    app.kubernetes.io/managed-by:Helm
    规格:
    类型:集群
    端口:
    -端口:8080
    目标港:8080
    #TODO:我们不能使用字符串端口,因为devspace在其UI中不支持它
    #targetPort:http
    协议:TCP
    名称:http
    选择器:
    app.kubernetes.io/name:api
    app.kubernetes.io/instance:api
    ---
    #来源:api/templates/deployment.yaml
    apiVersion:apps/v1
    种类:部署
    元数据:
    名称:api
    标签:
    app.kubernetes.io/name:api
    helm.sh/chart:api-0.0.0
    app.kubernetes.io/instance:api
    app.kubernetes.io/version:“0.0”
    app.kubernetes.io/managed-by:Helm
    规格:
    副本:1份
    选择器:
    火柴标签:
    app.kubernetes.io/name:api
    app.kubernetes.io/instance:api
    模板:
    元数据:
    标签:
    app.kubernetes.io/name:api
    app.kubernetes.io/instance:api
    规格:
    serviceAccountName:api
    securityContext:
    {}
    初始化容器:
    #应用程序必须等待数据库联机“依赖”解决方案
    -名称:等待数据库
    图:darthcabs/微型工具:1
    args:
    -/bin/bash
    --c
    - >
    set-x;
    而[[“$(nc-zv'postgres'5432&>/dev/null;echo$?)”!=0]];做
    回声''
    睡眠15;
    完成
    容器:
    -名称:api
    securityContext:
    {}
    图片:shopozor/graphql引擎:EM5Aya
    政策:
    环境:
    -姓名:POSTGRES_用户
    价值来源:
    secretKeyRef:
    名称:共享postgresql
    关键字:postgresql用户名
    -名称:POSTGRES_数据库
    价值:shopozor
    -姓名:POSTGRES_密码
    价值来源:
    secretKeyRef:
    名称:共享postgresql
    密钥:postgresql密码
    -姓名:POSTGRES_主机
    价值:博士后
    -名称:POSTGRES_PORT
    值:“5432”
    -名称:HASURA_GRAPHQL_服务器_端口
    值:“8080”
    -名称:HASURA_GRAPHQL_启用_控制台
    价值:“真实”
    -名称:HASURA_GRAPHQL_启用的日志类型
    值:启动、http日志、webhook日志、websocket日志、查询日志
    -名称:HASURA_GRAPHQL_启用_遥测
    值:“false”
    -名称:HASURA_GRAPHQL_CORS_域名
    值:“*”
    -名称:HASURA_GRAPHQL_DISABLE_CORS
    值:“false”
    -名称:HASURA_GRAPHQL_未经授权的角色
    价值:隐姓埋名
    -姓名:HASURA_GRAPHQL_ADMIN_SECRET
    价值来源:
    secretKeyRef:
    名称:api
    密钥:管理机密
    -姓名:HASURA_GRAPHQL_JWT_机密
    值:“{\”type\”:“HS256\”,“key\”:“my access token signing key secret\”,“audience\”:[“58640fbe-9a6c-11ea-bb37-0242ac130002\”,“6e707590-9a6c-11ea-bb37-0242ac130002\”,“Claimes\u namespace\:”https://hasura.io/jwt/claims\“,\”索赔\格式\“:\”json\“,\”发行人\“:\”shopozor.com\“}”
    -名称:HASURA_GRAPHQL_数据库_URL
    值:postgres://$(postgres\u用户):$(postgres\u密码)@$(postgres\u主机):$(postgres\u端口)//$(postgres\u数据库)
    -名称:函数名称空间
    值:dev
    端口:
    -名称:http
    集装箱港口:8080
    协议:TCP
    livenessProbe:
    httpGet:
    路径:/healthz
    端口:http
    readinessProbe:
    httpGet:
    路径:/healthz
    端口:http
    资源:
    {}
    ---
    #来源:api/templates/ingress.yaml
    apiVersion:networking.k8s.io/v1beta1
    种类:入口
    元数据:
    名称:api
    标签:
    app.kubernetes.io/name:api
    helm.sh/chart:api-0.0.0
    app.kubernetes.io/instance:api
    app.kubernetes.io/version:“0.0”
    app.kubernetes.io/managed-by:Helm
    注释:
    kubernetes.io/ingres.class:nginx
    规格:
    规则:
    -主持人:“api.shopozor”
    http:
    路径:
    -路径:/
    后端:
    服务名称:api
    服务端口:8080
    
    现在,我有一个nuxt前端,它试图利用hasura的websocket。我用标准方式配置了阿波罗

    //---
    //nuxt.config.js
    [...]
    //提供阿波罗舱的选择
    阿波罗:{
    Cookie属性:{
    有效期:7
    },
    includeNodeModules:true,
    authenticationType:“基本”,
    客户端配置:{
    默认值:“~/apollo/clientConfig.js”
    }
    },
    [...]
    //---
    //apollo/clientConfig.js
    从'apollo cache inmemory'导入{InMemoryCache}
    导出默认函数(上下文){
    返回
    
    127.0.0.1  localhost api.shopozor
    
     ERROR  Network error: Unexpected token < in JSON at position 0                                                                                                                                         23:17:06
    
      at new ApolloError (D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:92:26)
      at D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:1588:34
      at D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:2008:15
      at Set.forEach (<anonymous>)
      at D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:2006:26
      at Map.forEach (<anonymous>)
      at QueryManager.broadcastQueries (D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:2004:20)
      at D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:1483:29
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
    
    Global error handler                                                                                                                                                                                    23:17:06
    
     ERROR  Network error: Unexpected token < in JSON at position 0                                                                                                                                         23:17:06
    
      at new ApolloError (D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:92:26)
      at D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:1486:27
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
    
    client.js?06a0:49 ApolloError: Network error: Unexpected token < in JSON at position 0
        at new ApolloError (D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:92:26)
        at D:\workspace\shopozor\services\node_modules\apollo-client\bundle.umd.js:1486:27
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (internal/process/task_queues.js:97:5) {
      graphQLErrors: [],
      networkError: SyntaxError [ServerParseError]: Unexpected token < in JSON at position 0
          at JSON.parse (<anonymous>)
          at D:\workspace\shopozor\services\node_modules\apollo-link-http-common\lib\index.js:35:25
          at runMicrotasks (<anonymous>)
          at processTicksAndRejections (internal/process/task_queues.js:97:5) {
        name: 'ServerParseError',
        response: Body {
          url: 'http://api.shopozor/v1/graphql/',
          status: 404,
          statusText: 'Not Found',
          headers: [Headers],
          ok: false,
          body: [PassThrough],
          bodyUsed: true,
          size: 0,
          timeout: 0,
          _raw: [Array],
          _abort: false,
          _bytes: 153
        },
        statusCode: 404,
        bodyText: '<html>\r\n' +
          '<head><title>404 Not Found</title></head>\r\n' +
          '<body>\r\n' +
          '<center><h1>404 Not Found</h1></center>\r\n' +
          '<hr><center>nginx/1.17.8</center>\r\n' +
          '</body>\r\n' +
          '</html>\r\n'
      },
      message: 'Network error: Unexpected token < in JSON at position 0',
      extraInfo: undefined
    }
    
    index.js?a6d6:111 OPTIONS http://api.shopozor/v1/graphql/ net::ERR_ABORTED 404 (Not Found)
    
    Access to fetch at 'http://api.shopozor/v1/graphql/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
    
    WebSocket connection to 'ws://api.shopozor/v1/graphql/' failed: Error during WebSocket handshake: Unexpected response code: 404
    
    2020-07-28T07:42:28.903877263Z {"type":"websocket-log","timestamp":"2020-07-28T07:42:28.894+0000","level":"info","detail":{"event":{"type":"accepted"},"connection_info":{"websocket_id":"94243bde-41c4-42c8-8d8f-355c47a3492e","token_expiry":null,"msg":null},"user_vars":null}}