Skip to content

Instantly share code, notes, and snippets.

@jcderr
Last active January 15, 2019 16:50
Show Gist options
  • Save jcderr/1a31908ae71b2bef292c505831705ba7 to your computer and use it in GitHub Desktop.
Save jcderr/1a31908ae71b2bef292c505831705ba7 to your computer and use it in GitHub Desktop.
Kubernetes Nginx Gateway with Upstreams from ConfigMap
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;";
}
}
kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-config
data:
nginx-upstreams: |
upstream api {
server api;
}
upstream auth {
server auth;
}
upstream admin {
server admin;
}
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
@Arconapalus
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment