Skip to content

Commit dc11ae9

Browse files
Merge pull request #13840 from rajatchopra/nginx
Automatic merge from submit-queue nginx router based on template template based nginx router implementation /cc @jawnsy
2 parents d1fcf38 + f0bc6b4 commit dc11ae9

File tree

6 files changed

+264
-0
lines changed

6 files changed

+264
-0
lines changed

hack/build-local-images.py

+9
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@
9696
},
9797
"files": {}
9898
},
99+
"nginx-router": {
100+
"directory": "router/nginx",
101+
"binaries": {
102+
"openshift": "/usr/bin/openshift"
103+
},
104+
"files": {
105+
".": "/var/lib/nginx"
106+
}
107+
},
99108
"haproxy-router": {
100109
"directory": "router/haproxy",
101110
"binaries": {

images/router/nginx/.cccp.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
job-id: origin-nginx-router

images/router/nginx/Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# This is the NGINX router for OpenShift Origin.
3+
#
4+
# The standard name for this image is openshift/origin-nginx-router
5+
#
6+
FROM openshift/origin
7+
8+
RUN INSTALL_PKGS="nginx" && \
9+
yum install -y "epel-release" && \
10+
yum install -y $INSTALL_PKGS && \
11+
rpm -V $INSTALL_PKGS && \
12+
yum clean all && \
13+
mkdir -p /var/lib/nginx/router/{certs,cacerts} && \
14+
mkdir -p /var/lib/nginx/{conf,run,bin,log,logs} && \
15+
touch /var/lib/nginx/conf/{{os_http_be,os_edge_http_be,os_tcp_be,os_sni_passthrough,os_reencrypt,os_route_http_expose,os_route_http_redirect,cert_config,os_wildcard_domain}.map,nginx.config} && \
16+
setcap 'cap_net_bind_service=ep' /usr/sbin/nginx && \
17+
chown -R :0 /var/lib/nginx && \
18+
chown -R :0 /var/log/nginx && \
19+
chmod -R 777 /var/log/nginx && \
20+
chmod -R 777 /var/lib/nginx
21+
22+
COPY . /var/lib/nginx/
23+
24+
LABEL io.k8s.display-name="OpenShift Origin NGINX Router" \
25+
io.k8s.description="This is a component of OpenShift Origin and contains an NGINX instance that automatically exposes services within the cluster through routes, and offers TLS termination, reencryption, or SNI-passthrough on ports 80 and 443."
26+
USER 1001
27+
EXPOSE 80 443
28+
WORKDIR /var/lib/nginx/conf
29+
ENV TEMPLATE_FILE=/var/lib/nginx/conf/nginx-config.template \
30+
RELOAD_SCRIPT=/var/lib/nginx/reload-nginx
31+
ENTRYPOINT ["/usr/bin/openshift-router"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
HTTP/1.0 503 Service Unavailable
2+
Pragma: no-cache
3+
Cache-Control: private, max-age=0, no-cache, no-store
4+
Connection: close
5+
Content-Type: text/html
6+
7+
<html>
8+
<head>
9+
<meta name="viewport" content="width=device-width, initial-scale=1">
10+
11+
<style type="text/css">
12+
/*!
13+
* Bootstrap v3.3.5 (http://getbootstrap.com)
14+
* Copyright 2011-2015 Twitter, Inc.
15+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
16+
*/
17+
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
18+
html {
19+
font-family: sans-serif;
20+
-ms-text-size-adjust: 100%;
21+
-webkit-text-size-adjust: 100%;
22+
}
23+
body {
24+
margin: 0;
25+
}
26+
h1 {
27+
font-size: 1.7em;
28+
font-weight: 400;
29+
line-height: 1.3;
30+
margin: 0.68em 0;
31+
}
32+
* {
33+
-webkit-box-sizing: border-box;
34+
-moz-box-sizing: border-box;
35+
box-sizing: border-box;
36+
}
37+
*:before,
38+
*:after {
39+
-webkit-box-sizing: border-box;
40+
-moz-box-sizing: border-box;
41+
box-sizing: border-box;
42+
}
43+
html {
44+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
45+
}
46+
body {
47+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
48+
line-height: 1.66666667;
49+
font-size: 13px;
50+
color: #333333;
51+
background-color: #ffffff;
52+
margin: 2em 1em;
53+
}
54+
p {
55+
margin: 0 0 10px;
56+
font-size: 13px;
57+
}
58+
.alert.alert-info {
59+
padding: 15px;
60+
margin-bottom: 20px;
61+
border: 1px solid transparent;
62+
background-color: #f5f5f5;
63+
border-color: #8b8d8f;
64+
color: #363636;
65+
margin-top: 30px;
66+
}
67+
.alert p {
68+
padding-left: 35px;
69+
}
70+
a {
71+
color: #0088ce;
72+
}
73+
74+
ul {
75+
position: relative;
76+
padding-left: 51px;
77+
}
78+
p.info {
79+
position: relative;
80+
font-size: 15px;
81+
margin-bottom: 10px;
82+
}
83+
p.info:before, p.info:after {
84+
content: "";
85+
position: absolute;
86+
top: 9%;
87+
left: 0;
88+
}
89+
p.info:before {
90+
content: "i";
91+
left: 3px;
92+
width: 20px;
93+
height: 20px;
94+
font-family: serif;
95+
font-size: 15px;
96+
font-weight: bold;
97+
line-height: 21px;
98+
text-align: center;
99+
color: #fff;
100+
background: #4d5258;
101+
border-radius: 16px;
102+
}
103+
104+
@media (min-width: 768px) {
105+
body {
106+
margin: 4em 3em;
107+
}
108+
h1 {
109+
font-size: 2.15em;}
110+
}
111+
112+
</style>
113+
</head>
114+
<body>
115+
<div>
116+
<h1>Application is not available</h1>
117+
<p>The application is currently not serving requests at this endpoint. It may not have been started or is still starting.</p>
118+
119+
<div class="alert alert-info">
120+
<p class="info">
121+
Possible reasons you are seeing this page:
122+
</p>
123+
<ul>
124+
<li>
125+
<strong>The host doesn't exist.</strong>
126+
Make sure the hostname was typed correctly and that a route matching this hostname exists.
127+
</li>
128+
<li>
129+
<strong>The host exists, but doesn't have a matching path.</strong>
130+
Check if the URL path was typed correctly and that the route was created using the desired path.
131+
</li>
132+
<li>
133+
<strong>Route and path matches, but all pods are down.</strong>
134+
Make sure that the resources exposed by this route (pods, services, deployment configs, etc) have at least one pod running.
135+
</li>
136+
</ul>
137+
</div>
138+
</div>
139+
</body>
140+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{{/*
2+
nginx.config: contains the main config with helper backends that are used to terminate
3+
encryption before finally sending to a host_be which is the backend that is the final
4+
backend for a route and contains all the endpoints for the service
5+
*/}}
6+
{{- define "/var/lib/nginx/conf/nginx.config" -}}
7+
{{- $workingDir := .WorkingDir }}
8+
#user www www; ## Default: nobody
9+
worker_processes 5; ## Default: 1
10+
error_log /var/lib/nginx/logs/error.log;
11+
pid /var/lib/nginx/logs/nginx.pid;
12+
worker_rlimit_nofile 8192;
13+
14+
events {
15+
worker_connections 4096; ## Default: 1024
16+
}
17+
18+
http {
19+
#include conf/mime.types;
20+
#include /etc/nginx/proxy.conf;
21+
#include /etc/nginx/fastcgi.conf;
22+
index index.html index.htm index.php;
23+
24+
default_type application/octet-stream;
25+
log_format main '$remote_addr - $remote_user [$time_local] $status '
26+
'"$request" $body_bytes_sent "$http_referer" '
27+
'"$http_user_agent" "$http_x_forwarded_for"';
28+
access_log /var/lib/nginx/logs/access.log main;
29+
sendfile on;
30+
tcp_nopush on;
31+
server_names_hash_bucket_size 128; # this seems to be required for some vhosts
32+
33+
34+
35+
{{- range $cfgIdx, $cfg := .State }}
36+
37+
upstream be_{{$cfg.Namespace}}_{{$cfg.Name}} {
38+
{{- range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
39+
{{- with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
40+
{{- range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
41+
server {{$endpoint.IP}}:{{$endpoint.Port}};
42+
{{ end -}}
43+
{{ end -}}
44+
{{ end -}}
45+
}
46+
47+
server { # simple load balancing
48+
{{- if (eq $cfg.TLSTermination "") }}
49+
listen 80;
50+
{{- else }}
51+
listen 443 ssl;
52+
{{ end -}}
53+
54+
server_name {{$cfg.Host}};
55+
{{- if and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "edge") (eq $cfg.TLSTermination "reencrypt")) -}}
56+
{{ $cert := index $cfg.Certificates $cfg.Host -}}
57+
{{ if ne $cert.Contents "" }}
58+
ssl_certificate {{$workingDir}}/certs/{{$cfgIdx}}.pem;
59+
ssl_certificate_key {{$workingDir}}/certs/{{$cfgIdx}}.pem;
60+
{{ end -}}
61+
{{ end -}}
62+
access_log /var/lib/nginx/logs/be_{{$cfgIdx}}.log main;
63+
64+
location / {
65+
proxy_pass http://be_{{$cfg.Namespace}}_{{$cfg.Name}};
66+
}
67+
}
68+
{{ end -}}{{/* end all routes */}}
69+
}
70+
{{ end -}}{{/* end config file */}}

images/router/nginx/reload-nginx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -o nounset
4+
5+
config_file=/var/lib/nginx/conf/nginx.config
6+
if [ -f /var/lib/nginx/logs/nginx.pid ]; then
7+
/usr/sbin/nginx -c ${config_file} -s reload
8+
reload_status=$?
9+
else
10+
/usr/sbin/nginx -c ${config_file}
11+
reload_status=$?
12+
fi
13+
exit $reload_status

0 commit comments

Comments
 (0)