DanielM
DanielM

Reputation: 6666

Kubernetes Service pointing to External Resource

We have an existing website, lets say example.com, which is a CNAME for where.my.server.really.is.com.

We're now developing new services using Kubernetes. Our first service /login is ready to be deployed. Using a mock HTML server I've been able to deploy two pods with seperate services that map to example.com and example.com/login.

What I would like to do is get rid of my mock HTML server, and provide a service inside of the cluster, that points to our full website outside of the server. Then I can change the DNS for example.com to point to our kubernetes cluster and people will still get the main site from where.my.server.really.is.com.

We are using Traefik for ingress, and these are the changes I've made to the config for the website:

---
kind: Service
apiVersion: v1
metadata:
  name: wordpress
spec:
  type: ExternalName
  externalName: where.my.server.really.is.com

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: wordpress
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  backend:
    serviceName: wordpress
    servicePort: 80
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: wordpress
          servicePort: 80

Unfortunately, when I visit example.com, rather than getting where.my.server.really.is.com, I get a 503 with the body "Service Unavailable". example.com/login works as expected

What have I missed?

Upvotes: 2

Views: 2032

Answers (1)

Jose Armesto
Jose Armesto

Reputation: 13739

Following traefik documentation on using ExternalName

When specifying an ExternalName, Træfik will forward requests to the given host accordingly and use HTTPS when the Service port matches 443.

This still requires setting up a proper port mapping on the Service from the Ingress port to the (external) Service port.

I believe you are missing the ports configuration of the Service. Something like

apiVersion: v1
kind: Service
metadata:
  name: wordpress
spec:
  ports:
  - name: http
    port: 80
  type: ExternalName
  externalName: where.my.server.really.is.com

You can see a full example in the docs.

Upvotes: 1

Related Questions