diff --git a/controllers/nginx/Dockerfile b/controllers/nginx/Dockerfile index cb285d9b3..28e44a7d9 100644 --- a/controllers/nginx/Dockerfile +++ b/controllers/nginx/Dockerfile @@ -20,7 +20,7 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* COPY nginx-ingress-controller / -COPY nginx.tmpl / +COPY nginx.tmpl /etc/nginx/template/nginx.tmpl COPY default.conf /etc/nginx/nginx.conf COPY lua /etc/nginx/lua/ diff --git a/controllers/nginx/README.md b/controllers/nginx/README.md index f2ed1e63d..c82d71c81 100644 --- a/controllers/nginx/README.md +++ b/controllers/nginx/README.md @@ -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 +## 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 The ngx_http_stub_status_module module provides access to basic status information. This is the default module active in the url `/nginx_status`. diff --git a/controllers/nginx/examples/custom-template/README.md b/controllers/nginx/examples/custom-template/README.md new file mode 100644 index 000000000..6d6375d0b --- /dev/null +++ b/controllers/nginx/examples/custom-template/README.md @@ -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` diff --git a/controllers/nginx/examples/custom-template/custom-template.yaml b/controllers/nginx/examples/custom-template/custom-template.yaml new file mode 100644 index 000000000..ac7991033 --- /dev/null +++ b/controllers/nginx/examples/custom-template/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 diff --git a/controllers/nginx/nginx/template.go b/controllers/nginx/nginx/template.go index fc67cfd1c..8a5b1626f 100644 --- a/controllers/nginx/nginx/template.go +++ b/controllers/nginx/nginx/template.go @@ -29,6 +29,7 @@ import ( var ( camelRegexp = regexp.MustCompile("[0-9A-Za-z]+") + tmplPath = "/etc/nginx/template/nginx.tmpl" funcMap = template.FuncMap{ "empty": func(input interface{}) bool { @@ -43,7 +44,7 @@ var ( ) 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 }