如何使用Traefik从我的Web阿波罗客户端公开应用程序访问Apollo服务器内部Kubernetes服务

时间:2019-05-23 00:07:18

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

我想用apollo-client 使 Nuxt.js连接到 Kubernetes 上的内部Apollo服务器

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

net::ERR_NAME_NOT_RESOLVED 

我的Apollo服务器在端口 6666 上运行,但是我的服务在端口443上运行,并且目标端口为6666

Apollo配置:

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",

1 个答案:

答案 0 :(得分:0)

基于Nuxt.js的Web应用程序需要从外部访问Kubernetes的群集工作负载:Apollo Server。这是因为Nuxjs在客户端(网络浏览器)上运行,并且不知道有关为后端服务(Apollo Server)提供的群集内部DNS名称“ service.namespace.svc.cluster.local”的任何信息-这些DNS名称仅是可解析的在集群内部。

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