http -> https redirect in Google Kubernetes Engine

Daniel Lee

I'm looking to redirect all traffic from

http://example.com -> https://example.com like how nearly all websites do.

I've looked at this link with no success: Kubernetes HTTPS Ingress in Google Container Engine

And have tried the following annotations in my ingress.yaml file.

nginx.ingress.kubernetes.io/configuration-snippet: |
  if ($http_x_forwarded_proto != 'https') {
    return 301 https://$host$request_uri;
  }
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/ingress.allow-http: "false"

All without any success. To be clear, I can access https://example.com and http://example.com without any errors, I need the http call to redirect to https.

Thanks

Daniel Lee

For what it's worth, I ended up using a reverse proxy in NGINX.

  1. You need to create secrets and sync them into your containers
  2. You need to create a configmap in nginx with your nginx config, as well as a default config that references this additional config file.

Here is my configuration:

worker_processes  1;

events {
    worker_connections  1024;
}


http {

default_type  application/octet-stream;

# Logging Configs
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile        on;
keepalive_timeout  65;

# Puntdoctor Proxy Config
include /path/to/config-file.conf;

# PubSub allows 10MB Files. lets allow 11 to give some space
client_max_body_size 11M;

}

Then, the config.conf

server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}

server {

listen 443;
server_name example.com;

ssl_certificate           /certs/tls.crt;
ssl_certificate_key       /certs/tls.key;

ssl on;
ssl_session_cache  builtin:1000  shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-RC4-SHA:AES128-GCM-SHA256:HIGH:!RC4:!MD5:!aNULL:!EDH:!CAMELLIA;
ssl_prefer_server_ciphers on;

location / {

  proxy_set_header        Host $host;
  proxy_set_header        X-Real-IP $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header        X-Forwarded-Proto $scheme;
  proxy_set_header        X-Forwarded-Host $http_host;

  # Fix the “It appears that your reverse proxy set up is broken" error.
  proxy_pass          http://deployment-name:8080/;
  proxy_read_timeout  90;

  proxy_redirect      http://deployment-name:8080/ https://example.com/;
}
}
  1. Create a deployment:

Here are the .yaml files

---
apiVersion: v1
kind: Service
metadata:
  name: puntdoctor-lb
spec:
   ports:
    - name: https
      port: 443
      targetPort: 443
     - name: http
      port: 80
      targetPort: 80
  selector:
    app: puntdoctor-nginx-deployment
  type: LoadBalancer
  loadBalancerIP: 35.195.214.7
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: puntdoctor-nginx-deployment
spec:
   replicas: 2
  template:
    metadata:
      labels:
        app: puntdoctor-nginx-deployment
    spec:
       containers:
       - name: adcelerate-nginx-proxy
        image: nginx:1.13
         volumeMounts:
        - name: certs
          mountPath: /certs/
        - name: site-config
          mountPath: /etc/site-config/
        - name: default-config
          mountPath: /etc/nginx/
        ports:
        - containerPort: 80
          name: http
        - containerPort: 443
          name: https
      volumes:
      - name: certs
        secret:
          secretName: nginxsecret
      - name: site-config
        configMap:
          name: nginx-config
       - name: default-config
        configMap:
         name: default

Hope this helps someone solve this issue, thanks for the other 2 answers, they both gave me valuable insight.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Google Kubernetes Engine&VPN

分類Dev

Google App EngineでHTTPS://を使用しているときのredirect_uri_mismatch

分類Dev

Google Kubernetes Engine:サービスタイプのHTTPSを有効にする

分類Dev

Loading an HTTPS image url that may redirect to HTTP

分類Dev

How to redirect all HTTPS requests to HTTP requests?

分類Dev

Redirect one Wordpress page from HTTPS to HTTP

分類Dev

How to redirect https file to http file

分類Dev

Redirect http request to https (spray io/scala)

分類Dev

http to https conditional redirect in jboss/wildfly

分類Dev

Redirect URI sent as HTTP and not HTTPS in app running HTTPS

分類Dev

HTTPS load balancer in Google Container Engine

分類Dev

Google Container Engine(Kubernetes)のDaemonSets

分類Dev

Schedule Cluster resizing on Google Kubernetes Engine

分類Dev

Why choosing Google Kubernetes Engine instead of Google AppEngine?

分類Dev

c socket client , http redirect to https and vice versa

分類Dev

Redirect non-www and www http requests to https://www

分類Dev

Google App Engine Go HTTP Post [] byte

分類Dev

Difference between Google Kubernetes Engine and Google Compute Engine in term of server management?

分類Dev

How to force Google App Engine [python] to use SSL (https)?

分類Dev

Why are there 3 nodes in a default Google Kubernetes Engine cluster?

分類Dev

Why are there 3 nodes in a default Google Kubernetes Engine cluster?

分類Dev

How to add resource and limits on Kubernetes Engine on Google Cloud Platform

分類Dev

How to enable Client Certificate in Google Kubernetes Engine Cluster

分類Dev

Kubernetes EngineのhttpベースのサーバーからGoogleCloudでhttpsエンドポイントを作成するにはどうすればよいですか?

分類Dev

Using HTTP Load Balancer with Kubernetes on Google Cloud Platform

分類Dev

Why cannot I redirect my React app on Heroku from http to https?

分類Dev

Traefik (v2.2) Ingress on Kubernetes: HTTP and HTTPS cannot co-exist

分類Dev

Kubernetes:Google Kubernetes Engine(gke)でkube-controller-managerのフラグを追加する方法

分類Dev

Google App EngineでHTTPSリクエストを処理する

Related 関連記事

  1. 1

    Google Kubernetes Engine&VPN

  2. 2

    Google App EngineでHTTPS://を使用しているときのredirect_uri_mismatch

  3. 3

    Google Kubernetes Engine:サービスタイプのHTTPSを有効にする

  4. 4

    Loading an HTTPS image url that may redirect to HTTP

  5. 5

    How to redirect all HTTPS requests to HTTP requests?

  6. 6

    Redirect one Wordpress page from HTTPS to HTTP

  7. 7

    How to redirect https file to http file

  8. 8

    Redirect http request to https (spray io/scala)

  9. 9

    http to https conditional redirect in jboss/wildfly

  10. 10

    Redirect URI sent as HTTP and not HTTPS in app running HTTPS

  11. 11

    HTTPS load balancer in Google Container Engine

  12. 12

    Google Container Engine(Kubernetes)のDaemonSets

  13. 13

    Schedule Cluster resizing on Google Kubernetes Engine

  14. 14

    Why choosing Google Kubernetes Engine instead of Google AppEngine?

  15. 15

    c socket client , http redirect to https and vice versa

  16. 16

    Redirect non-www and www http requests to https://www

  17. 17

    Google App Engine Go HTTP Post [] byte

  18. 18

    Difference between Google Kubernetes Engine and Google Compute Engine in term of server management?

  19. 19

    How to force Google App Engine [python] to use SSL (https)?

  20. 20

    Why are there 3 nodes in a default Google Kubernetes Engine cluster?

  21. 21

    Why are there 3 nodes in a default Google Kubernetes Engine cluster?

  22. 22

    How to add resource and limits on Kubernetes Engine on Google Cloud Platform

  23. 23

    How to enable Client Certificate in Google Kubernetes Engine Cluster

  24. 24

    Kubernetes EngineのhttpベースのサーバーからGoogleCloudでhttpsエンドポイントを作成するにはどうすればよいですか?

  25. 25

    Using HTTP Load Balancer with Kubernetes on Google Cloud Platform

  26. 26

    Why cannot I redirect my React app on Heroku from http to https?

  27. 27

    Traefik (v2.2) Ingress on Kubernetes: HTTP and HTTPS cannot co-exist

  28. 28

    Kubernetes:Google Kubernetes Engine(gke)でkube-controller-managerのフラグを追加する方法

  29. 29

    Google App EngineでHTTPSリクエストを処理する

ホットタグ

アーカイブ