【问题标题】:How to access an Apollo Server Internal Kubernetes Service from my Web apollo-client exposed application with Traefik如何使用 Traefik 从我的 Web apollo-client 暴露的应用程序访问 Apollo 服务器内部 Kubernetes 服务
【发布时间】:2019-10-09 12:17:41
【问题描述】:

我想让我的 Nuxt.js with apollo-client 连接到我在 Kubernetes 上的内部 Apollo-Server

我的带有 apollo-client 应用程序的 nuxtjs 通过 Traefik Ingress 公开,当我将我的 apollo-client URL 设置为 <service>.<namespace> 以指向我的内部 apollo-client 时,我收到以下错误消息在 Chrome 控制台上:

net::ERR_NAME_NOT_RESOLVED 

我的 Apollo 服务器在端口 6666 上运行,但我的 服务在端口 443 上运行并针对端口 6666

阿波罗配置:

import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'

// Replace this with your project's endpoint
const GRAPHCMS_API = process.env.API

export default () => ({
  link: new HttpLink({ uri: GRAPHCMS_API }),
  cache: new InMemoryCache(),
  defaultHttpLink: false
})

我的 API 变量:

  API: "https://service.namespace.svc.cluster.local:443/gql",

【问题讨论】:

  • 嗨,你能粘贴你的入口 yaml 吗?

标签: kubernetes apollo traefik apollo-client apollo-server


【解决方案1】:

基于 Nuxt.js 的 Web 应用程序需要能够从外部访问 Kubernetes 的集群工作负载:Apollo Server。这是因为 Nuxjs 在客户端(Web 浏览器)上运行,并且它对提供给后端服务(Apollo 服务器)的集群内部 DNS 名称“service.namespace.svc.cluster.local”一无所知 - 这些 DNS 名称只能解析集群内部。

您需要在 NodePort 或 LoadBalancer 类型的服务上公开您的 Appolo 服务器,如官方文档 here 中所述。另一种选择是通过 Ingress 使用 TLS/HTTPS 公开您的“Apollo 服务器内部 Kubernetes 服务”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-21
    • 2020-12-17
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 2020-10-21
    相关资源
    最近更新 更多