2
votes

I am trying to follow this tutorial on configuring nginx-ingress-controller for a Kubernetes cluster I deployed to AWS using kops.

https://daemonza.github.io/2017/02/13/kubernetes-nginx-ingress-controller/

When I run kubectl create -f ./nginx-ingress-controller.yml, the pods are created but error out. From what I can tell, the problem lies with the following portion of nginx-ingress-controller.yml:

volumes:
        - name: tls-dhparam-vol
          secret:
            secretName: tls-dhparam
        - name: nginx-template-volume
          configMap:
            name: nginx-template
            items:
            - key: nginx.tmpl
              path: nginx.tmpl

Error shown on the pods:

MountVolume.SetUp failed for volume "nginx-template-volume" : configmaps "nginx-template" not found

This makes sense, because the tutorial does not have the reader create this configmap before creating the controller. I know that I need to create the configmap using:

kubectl create configmap nginx-template --from-file=nginx.tmpl=nginx.tmpl

I've done this using nginx.tmpl files found from sources like this, but they don't seem to work (always fail with invalid NGINX template errors). Log example:

I1117 16:29:49.344882       1 main.go:94] Using build: https://github.com/bprashanth/contrib.git - git-92b2bac
I1117 16:29:49.402732       1 main.go:123] Validated default/default-http-backend as the default backend
I1117 16:29:49.402901       1 main.go:80] mkdir /etc/nginx-ssl: file exists already exists
I1117 16:29:49.402951       1 ssl.go:127] using file '/etc/nginx-ssl/dhparam/dhparam.pem' for parameter ssl_dhparam
F1117 16:29:49.403962       1 main.go:71] invalid NGINX template: template: nginx.tmpl:1: function "where" not defined

The image version used is quite old, but I've tried newer versions with no luck.

 containers:
        - name: nginx-ingress-controller
          image: gcr.io/google_containers/nginx-ingress-controller:0.8.3

This thread is similar to my issue, but I don't quite understand the proposed solution. Where would I use docker cp to extract a usable template from? Seems like the templates I'm using use a language/syntax incompatible with Docker...?

1

1 Answers

2
votes

To copy the nginx template file from the ingress controller pod to your local machine, you can first grab the name of the pod with kubectl get pods then run kubectl exec [POD_NAME] -it -- cat /etc/nginx/template/nginx.tmpl > nginx.tmpl.

This will leave you with the nginx.tmpl file you can then edit and push back up as a configmap. I would recommend though keeping custom changes to the template to a minimum as it can make it hard for you to update the controller in the future.

Hope this helps!