One domain points to another kubernetes ingress host domain using CNAME

12/6/2019

I have setup as below:

One kubernetes cluster with nginx ingress for deployment A. Ingress to deployment has configuration for host example.com. I want abc.com to point to example.comusing CNAME but its always throwing SSL error.

-- ajay.kumar.awscloud
kubernetes
nginx

1 Answer

12/6/2019

If I understand you correctly you need to use Rewrite annotations.

See the example below:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)

In this ingress definition, any characters captured by (.*) will be assigned to the placeholder $2, which is then used as a parameter in the rewrite-target annotation. For example, the ingress definition above will result in the following rewrites:

- rewrite.bar.com/something rewrites to rewrite.bar.com/

- rewrite.bar.com/something/ rewrites to rewrite.bar.com/

- rewrite.bar.com/something/new rewrites to rewrite.bar.com/new

Please let me know if that helped.

EDIT: More options:

  • create additional Ingresses

  • use HTTP (80) and generate SSL certificates

-- OhHiMark
Source: StackOverflow