Allow custom nginx templates
This commit is contained in:
parent
996c769080
commit
b086a686dd
5 changed files with 78 additions and 2 deletions
|
@ -20,7 +20,7 @@ RUN apt-get update && apt-get install -y \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY nginx-ingress-controller /
|
COPY nginx-ingress-controller /
|
||||||
COPY nginx.tmpl /
|
COPY nginx.tmpl /etc/nginx/template/nginx.tmpl
|
||||||
COPY default.conf /etc/nginx/nginx.conf
|
COPY default.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
COPY lua /etc/nginx/lua/
|
COPY lua /etc/nginx/lua/
|
||||||
|
|
|
@ -180,6 +180,15 @@ Using a ConfigMap it is possible to customize the defaults in nginx.
|
||||||
Please check the [tcp services](examples/custom-configuration/README.md) example
|
Please check the [tcp services](examples/custom-configuration/README.md) example
|
||||||
|
|
||||||
|
|
||||||
|
## Custom NGINX template
|
||||||
|
|
||||||
|
The NGINX template is located in the file `/etc/nginx/template/nginx.tmpl`. Mounting a volume is possible to use a custom version.
|
||||||
|
Use the [custom-template](examples/custom-template/README.md) example as a guide
|
||||||
|
|
||||||
|
**Please note the template is tied to the go code. Be sure to no change names in the variable `$cfg`**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### NGINX status page
|
### NGINX status page
|
||||||
|
|
||||||
The ngx_http_stub_status_module module provides access to basic status information. This is the default module active in the url `/nginx_status`.
|
The ngx_http_stub_status_module module provides access to basic status information. This is the default module active in the url `/nginx_status`.
|
||||||
|
|
9
controllers/nginx/examples/custom-template/README.md
Normal file
9
controllers/nginx/examples/custom-template/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
This example shows how is possible to use a custom template
|
||||||
|
|
||||||
|
First create a configmap with a template inside running:
|
||||||
|
```
|
||||||
|
kubectl create configmap nginx-template --from-file=nginx.tmpl=../../nginx.tmpl
|
||||||
|
```
|
||||||
|
|
||||||
|
Next create the rc `kubectl create -f custom-template.yaml`
|
|
@ -0,0 +1,57 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ReplicationController
|
||||||
|
metadata:
|
||||||
|
name: nginx-ingress-controller
|
||||||
|
labels:
|
||||||
|
k8s-app: nginx-ingress-lb
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
k8s-app: nginx-ingress-lb
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
k8s-app: nginx-ingress-lb
|
||||||
|
name: nginx-ingress-lb
|
||||||
|
spec:
|
||||||
|
terminationGracePeriodSeconds: 60
|
||||||
|
containers:
|
||||||
|
- image: aledbf/nginx-third-party:0.15
|
||||||
|
name: nginx-ingress-lb
|
||||||
|
imagePullPolicy: Always
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /healthz
|
||||||
|
port: 10249
|
||||||
|
scheme: HTTP
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
timeoutSeconds: 5
|
||||||
|
# use downward API
|
||||||
|
env:
|
||||||
|
- name: POD_NAME
|
||||||
|
valueFrom:
|
||||||
|
fieldRef:
|
||||||
|
fieldPath: metadata.name
|
||||||
|
- name: POD_NAMESPACE
|
||||||
|
valueFrom:
|
||||||
|
fieldRef:
|
||||||
|
fieldPath: metadata.namespace
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
hostPort: 80
|
||||||
|
- containerPort: 443
|
||||||
|
hostPort: 4430
|
||||||
|
args:
|
||||||
|
- /nginx-ingress-controller
|
||||||
|
- --default-backend-service=default/default-http-backend
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /etc/nginx/template
|
||||||
|
name: nginx-template-volume
|
||||||
|
readOnly: true
|
||||||
|
volumes:
|
||||||
|
- name: nginx-template-volume
|
||||||
|
configMap:
|
||||||
|
name: nginx-template
|
||||||
|
items:
|
||||||
|
- key: nginx.tmpl
|
||||||
|
path: nginx.tmpl
|
|
@ -29,6 +29,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
camelRegexp = regexp.MustCompile("[0-9A-Za-z]+")
|
camelRegexp = regexp.MustCompile("[0-9A-Za-z]+")
|
||||||
|
tmplPath = "/etc/nginx/template/nginx.tmpl"
|
||||||
|
|
||||||
funcMap = template.FuncMap{
|
funcMap = template.FuncMap{
|
||||||
"empty": func(input interface{}) bool {
|
"empty": func(input interface{}) bool {
|
||||||
|
@ -43,7 +44,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ngx *Manager) loadTemplate() {
|
func (ngx *Manager) loadTemplate() {
|
||||||
tmpl, _ := template.New("nginx.tmpl").Funcs(funcMap).ParseFiles("./nginx.tmpl")
|
tmpl, _ := template.New("nginx.tmpl").Funcs(funcMap).ParseFiles(tmplPath)
|
||||||
ngx.template = tmpl
|
ngx.template = tmpl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue