How to set subdomain to a kubernetes pod?

3/18/2017

Say, the pod has one container which hosts a webserver serving static page on port 80.

When creating the pod, how to set a subdomain x.example.com to a pod? Is a service necessary here?

What role does kube-dns play here?

I don't want to do a use nodePort binding. The pod should be accessible to the public via x.example.com. Is it possible to access it at example.com with query param as CIDR?

-- Jaipradeesh
kubernetes

1 Answer

3/19/2017

Assuming you aren't deploying to a cloud environment, you would use an Ingress Controller Deploy an ingress controller as a standard pod, with a service that uses NodePort or HostPort.

Once you've deployed your ingress controller, you can add an Ingress resource.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - host: x.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: web-app-service
          servicePort: 80

Point DNS to the host your ingress controller pod was scheduled on, and you can access the pod on x.example.com

If you're deploying to GKE or AWS etc, you can use a Load Balancer resource

-- jaxxstorm
Source: StackOverflow