Last active
January 15, 2019 16:50
-
-
Save jcderr/1a31908ae71b2bef292c505831705ba7 to your computer and use it in GitHub Desktop.
Kubernetes Nginx Gateway with Upstreams from ConfigMap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include /etc/nginx/conf.d/upstreams/*.conf; | |
server { | |
listen 8080; | |
resolver 10.99.254.254; | |
server_name ~^(?<svc>[a-zA-Z0-9]+)(?<env>[\-a-zA-Z0-9]*)\..*\.com$; | |
location / { | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_next_upstream error; | |
# 2) Any request that did not originally come in to the ELB | |
# over HTTPS gets redirected. | |
if ($http_x_forwarded_proto != "https") { | |
rewrite ^(.*)$ https://$host$1 permanent; | |
} | |
proxy_pass http://$svc; | |
# Add HTTP Strict Transport Security for good measure. | |
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kind: ConfigMap | |
apiVersion: v1 | |
metadata: | |
name: nginx-config | |
data: | |
nginx-upstreams: | | |
upstream api { | |
server api; | |
} | |
upstream auth { | |
server auth; | |
} | |
upstream admin { | |
server admin; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: nginx-gateway | |
labels: | |
name: nginx-gateway | |
role: frontend | |
application: nginx | |
spec: | |
replicas: 2 | |
strategy: | |
rollingUpdate: | |
maxSurge: 2 | |
maxUnavailable: 1 | |
type: RollingUpdate | |
template: | |
metadata: | |
labels: | |
name: nginx-gateway | |
role: frontend | |
application: nginx | |
spec: | |
containers: | |
- name: nginx-gateway | |
image: __some_account__/nginx-gateway:latest | |
ports: | |
- containerPort: 80 | |
volumeMounts: | |
- mountPath: /etc/nginx/conf.d/upstreams | |
name: nginx-upstreams | |
volumes: | |
- name: nginx-upstreams | |
configMap: | |
name: nginx-config | |
items: | |
- key: nginx-upstreams | |
path: upstreams.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I'm looking to add nginx gateway for my api's for GKE cluster that I've already develop. By assumption, I deploy this files as is?
Is there resource of information that details how to do this? Thanks