How to get Kubernetes Ingress to terminate SSL and proxy to service?

3/28/2018

I have a centos7 deployment with kubernetes on bare metal. Everything works great. However, i would like to get an Ingress working. so in brief what i want to do is to terminate the SSL from within the Ingress and have plain http between the ingress and my service. this is what i did:

1) i hack weave to allow hostNetwork

2) i have an ingress controller set up as per:

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nginx-ingress-controller
  namespace: ingress-nginx
  labels:
    k8s-app: nginx-ingress-lb
    kubernetes.io/cluster-service: "true"
spec:
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
        name: nginx-ingress-lb
    spec:
      hostNetwork: true
      terminationGracePeriodSeconds: 60
      serviceAccountName: nginx-ingress-serviceaccount
      nodeSelector:
        role: edge-router
      containers:
      - image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.12.0
        name: nginx-ingress-lb
        imagePullPolicy: Always
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          timeoutSeconds: 1
        # use downward API
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        ports:
          - containerPort: 80
            hostPort: 80
          - containerPort: 443
            hostPort: 443
        args:
          - /nginx-ingress-controller
          - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
          - --enable-ssl-passthrough
          # - --default-ssl-certificate=$(POD_NAMESPACE)/tls-certificate
        volumeMounts:
          - name: tls-dhparam-vol
            mountPath: /etc/nginx-ssl/dhparam
      volumes:
        - name: tls-dhparam-vol
          secret:
            secretName: tls-dhparam

Note the DaemonSet and the nodeSelector. Also the hostNetwork = true so that my kubernetes nodes will open up 80 and 443 to listen for routing).

So i attempt to go to http://foo.bar.com and unsurprisingly, nothing. i just get the default backend - 404 page. i need the ingress rule....

3) so i create a Ingress rule like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hub
  annotations:
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.org/ssl-services: "hub"
spec:
  tls:
  - hosts:
    - foo.bar.com
    secretName: tls-dhparam
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /
        backend:
          serviceName: hub
          servicePort: 8000

So it works great!... for http... when i go to my node at http://foo.bar.com i can access my service (hub) and can log on. however, as one has to log on it only makes sense to enforce https....

so my problem is that when i switch my browser over to https://foo.bar.com, i end up with a the default backend - 404 page.

looking at the cert presented in the above, i see that it is one created by kubernetes:

Kubernetes Ingress Controller Fake Certificate
Self-signed root certificate

checking my secrets:

$ kubectl -n ingress-nginx get secrets
NAME                                       TYPE                                  DATA      AGE
default-token-kkd2j                        kubernetes.io/service-account-token   3         12m
nginx-ingress-serviceaccount-token-7f2sq   kubernetes.io/service-account-token   3         12m
tls-dhparam                                Opaque                                1         8m

what am i doing wrong?

-- yee379
https
kubernetes
kubernetes-ingress

2 Answers

3/29/2018

In your example, it looks like your Ingress doesn't explicitly declare metadata.namespace. If it is ending up in the default namespace while the tls-dhparam Secret is in the ingress-nginx namespace that would be the problem. The tls secrets for Ingresses should be in the same namespace as the Ingress.

-- coreypobrien
Source: StackOverflow

3/30/2018

issue was that i using a pem file didn't seem to work (and there's no noticeable errors associated with it). switch over to a tls cert/key via

kubectl create secret tls tls-certificate --key my.key --cert my.cer

worked.

-- yee379
Source: StackOverflow