How to access an Apollo Server Internal Kubernetes Service from my Web apollo-client exposed application with Traefik

5/23/2019

I want to make my Nuxt.js with apollo-client to connect to my internal Apollo-Server on Kubernetes.

My nuxtjs with apollo-client app is exposed via Traefik Ingress and when i set my apollo-client URL to the <service>.<namespace> to point to my internal apollo-client i get the following error message on Chrome Console:

net::ERR_NAME_NOT_RESOLVED 

My Apollo Server is running on port 6666 but my Service runs on port 443 and targets port 6666

Apollo Config:

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
})

My API variable:

  API: "https://service.namespace.svc.cluster.local:443/gql",
-- Joe Lopez Cuenca
apollo
apollo-client
apollo-server
kubernetes
traefik

1 Answer

6/11/2019

Your Nuxt.js based web application needs to have access from outside to your Kubernetes' cluster workload: Apollo Server. This is because Nuxjs runs on client side (web browser), and it does not know anything about cluster internal DNS name "service.namespace.svc.cluster.local" given to backend service (Apollo Server) - these DNS names are resolvable only inside the cluster.

You need to expose your Appolo Server on NodePort or LoadBalancer type service, as explained in official doc here. Yet another option is to expose your "Apollo Server Internal Kubernetes Service" via Ingress too with TLS/HTTPS.

-- Nepomucen
Source: StackOverflow