Use a custom nginx.conf file

Related Documentation

You can specify a custom nginx.conf file by creating a ConfigMap or Secret and mounting it inside your container that contains an nginx_kong.lua template.

Use the following fields in values.yaml:

  • deployment.userDefinedVolumes: this field takes an array of objects that get appended as-is to the existing spec.template.spec.volumes array in the Kong Gateway deployment resource.
  • deployment.userDefinedVolumeMounts: this field is appended as-is to the existing spec.template.spec.containers[].volumeMounts and spec.template.spec.initContainers[].volumeMounts arrays.

The volumes to mount are provided under the deployment key in your Helm values.yaml file. The structure of the configuration matches the Kubernetes ConfigMapVolumeSource or SecretVolumeSource structure.

Create a ConfigMap

kubectl create configmap custom-template --from-file=nginx_kong.lua=./nginx_kong.lua -n kong

Mount the ConfigMap

gateway:
  deployment:
    userDefinedVolumes:
      - name: custom-template
        configMap:
          name: custom-template
          items:
            - key: "nginx_kong.lua"
              path: "nginx_kong.lua"
    userDefinedVolumeMounts:
      - name: custom-template
        subPath: "nginx_kong.lua"
        mountPath: "/usr/local/share/lua/5.1/kong/templates/nginx_kong.lua"
        readOnly: true

Validate your configuration

To ensure that your changes are working, you can cat the nginx file inside the container.

kubectl exec -n kong kong-gateway-POD_NAME -c proxy -- cat /usr/local/share/lua/5.1/kong/templates/nginx_kong.lua

The output should show the custom configuration file that you placed inside the ConfigMap.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!