Kubernetes SSL AWS ELB setup config map for HTTP to HTTPS Flask

10/16/2018

I see the other posts in regards to this but I got an error while attempting to put the ConfigMap in the ingress. In order to get HTTP -> HTTPS.

---
apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
    service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "3600"
    service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: <ARN>
    service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443"
  labels:
    app: nginx-ingress
    chart: nginx-ingress-0.16.1
    component: controller
    release: prod-hola
  name: nginx-ingress-hola
  namespace: nginx-ingress
spec:
  externalTrafficPolicy: Cluster
  ports:
  - name: https
    port: 443
    protocol: TCP
    targetPort: 80
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8000
  selector:
    app: nginx-ingress
    component: controller
    release: prod-hola
  sessionAffinity: None
  type: LoadBalancer
---
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: nginx-ingress-config
    name: nginx-ingress-config
  namespace: nginx-ingress
data:
  ssl-redirect: "false"
  hsts: "true"
  server-tokens: "false"
  http-snippet: |
    server {
      listen 8000 proxy_protocol;
      server_tokens off;
      return 301 https://$host$request_uri;
    }
---

It gives me a resource name may not be empty. So do I have this ConfigMap in the correct place to get HTTP to https for flask (which I have on 8000) to work?

-- user2462320
amazon-web-services
flask
https
kubernetes

1 Answer

10/20/2018

Looks like you are missing the actual name for the ConfigMap, due to an indentation hiccup:

Instead of this:

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: nginx-ingress-config
    name: nginx-ingress-config
  namespace: nginx-ingress
data:
  ssl-redirect: "false"
  hsts: "true"
  server-tokens: "false"
  http-snippet: |
    server {
      listen 8000 proxy_protocol;
      server_tokens off;
      return 301 https://$host$request_uri;
    }

It should be this:

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: nginx-ingress-config
  name: nginx-ingress-config
  namespace: nginx-ingress
data:
  ssl-redirect: "false"
  hsts: "true"
  server-tokens: "false"
  http-snippet: |
    server {
      listen 8000 proxy_protocol;
      server_tokens off;
      return 301 https://$host$request_uri;
    }
-- Rico
Source: StackOverflow