Build NGINX Ingress Controller for the legacy F5 WAF for NGINX integration
Applies to: Legacy F5 WAF for NGINX integration, CRD-based (in-pod compilation) and bundle-based (local bundles)
This document explains how to build an F5 NGINX Ingress Controller image with the legacy F5 WAF for NGINX integration from source code. The legacy F5 WAF for NGINX integration was formerly called F5 WAF for NGINX v4. To check which integration you run, see Choose an F5 WAF for NGINX deployment.
If you’d rather not build your own NGINX Ingress Controller image, see the pre-built image options at the end of this guide.
- To use F5 WAF for NGINX with NGINX Ingress Controller, you must have NGINX Plus.
- The legacy F5 WAF for NGINX integration is not supported when
readOnlyRootFilesystemis enabled.
Get your system ready for building and pushing the NGINX Ingress Controller image with F5 WAF for NGINX.
-
Sign in to your private registry. Replace
<MY_DOCKER_REGISTRY>with the path to your own private registry.docker login <MY_DOCKER_REGISTRY> -
Clone the NGINX Ingress Controller repository:
shell git clone https://github.com/nginx/kubernetes-ingress.git --branch v5.8.1 cd kubernetes-ingress
Follow these steps to build the NGINX Ingress Controller image with the legacy F5 WAF for NGINX integration.
-
Place your NGINX Plus license files (nginx-repo.crt and nginx-repo.key) in the project’s root folder. To verify they’re in place, run:
ls nginx-repo.*You should see:
nginx-repo.crt nginx-repo.key -
Build the image. Replace
<MAKEFILE_TARGET>with your chosen build option and<MY_DOCKER_REGISTRY>with your private registry’s path. Refer to the Makefile targets table below for the list of build options.make <MAKEFILE_TARGET> PREFIX=<MY_DOCKER_REGISTRY>/nginx-plus-ingress TARGET=downloadFor example, to build a Debian-based image with NGINX Plus and F5 DoS for NGINX, run:
make debian-image-dos-plus PREFIX=<MY_DOCKER_REGISTRY>/nginx-plus-ingress TARGET=downloadWhat to expect: The image is built and tagged with a version number, which is derived from the
VERSIONvariable in the Makefile. This version number is used for tracking and deployment purposes.
In the event a patch of NGINX Plus is released, make sure to rebuild your image to get the latest version. If your system is caching the Docker layers and not updating the packages, addDOCKER_BUILD_OPTIONS="--pull --no-cache"to the make command.
| Makefile Target | Description | Compatible Systems |
|---|---|---|
| debian-image-nap-plus | Builds a Debian-based image with NGINX Plus and the F5 WAF for NGINX module, for the legacy integration. | Debian |
| debian-image-nap-dos-plus | Builds a Debian-based image with NGINX Plus, F5 WAF for NGINX, and F5 DoS for NGINX, for the legacy integration. | Debian |
| ubi-image-nap-plus | Builds a UBI-based image with NGINX Plus and the F5 WAF for NGINX module, for the legacy integration. | OpenShift |
| ubi-image-nap-dos-plus | Builds a UBI-based image with NGINX Plus, F5 WAF for NGINX, and F5 DoS for NGINX, for the legacy integration. | OpenShift |
Targets that include nap-v5 build images for the current integration, not the legacy one. For those targets, see Build NGINX Ingress Controller for the current F5 WAF for NGINX integration.
For the complete list of Makefile targets and customizable variables, see the Build NGINX Ingress Controller topic.
Once you’ve successfully built the NGINX Ingress Controller image with F5 WAF for NGINX, the next step is to upload it to your private Docker registry. This makes the image available for deployment to your Kubernetes cluster.
To upload the image, run the following command. If you’re using a custom tag, add TAG=your-tag to the end of the command. Replace <MY_DOCKER_REGISTRY> with your private registry’s path.
make push PREFIX=<MY_DOCKER_REGISTRY>/nginx-plus-ingressAdmin access requiredTo complete these steps you need admin access to your cluster. Refer to your Kubernetes platform’s documentation to set up admin access. For Google Kubernetes Engine (GKE), you can refer to their Role-Based Access Control guide.
-
Create a namespace and a service account:
kubectl apply -f deployments/common/ns-and-sa.yaml -
Create a cluster role and binding for the service account:
kubectl apply -f deployments/rbac/rbac.yaml
If you’re planning to use F5 WAF for NGINX or F5 DoS for NGINX, additional roles and bindings are needed.
-
(F5 WAF for NGINX only) Create the App Protect role and binding:
kubectl apply -f deployments/rbac/ap-rbac.yaml -
(F5 DoS for NGINX only) Create the App Protect DoS role and binding:
kubectl apply -f deployments/rbac/apdos-rbac.yaml
In this section, you’ll create resources that most NGINX Ingress Controller installations require:
-
(Optional) Create a secret for the default NGINX server’s TLS certificate and key. Complete this step only if you’re using the default server TLS secret command-line argument. If you’re not, feel free to skip this step.
By default, the server returns a 404 Not Found page for all requests when no ingress rules are set up. Although we provide a self-signed certificate and key for testing purposes, we recommend using your own certificate.
shell make secrets kubectl apply -f examples/shared-examples/default-server-secret/default-server-secret.yaml -
Create a ConfigMap to customize your NGINX settings:
kubectl apply -f deployments/common/nginx-config.yaml -
Create an
IngressClassresource. NGINX Ingress Controller won’t start without anIngressClassresource.kubectl apply -f deployments/common/ingress-class.yamlIf you want to make this NGINX Ingress Controller instance your cluster’s default, uncomment the
ingressclass.kubernetes.io/is-default-classannotation. This action will auto-assignIngressClassto new ingresses that don’t specify aningressClassName.
To make sure your NGINX Ingress Controller pods reach the Ready state, you’ll need to create custom resource definitions (CRDs) for various components.
Alternatively, you can disable this requirement by setting the -enable-custom-resources command-line argument to false.
There are two ways you can install the custom resource definitions:
- Using a URL to apply a single CRD yaml file, which we recommend.
- Applying your local copy of the CRD yaml files, which requires you to clone the repository.
The core custom CRDs are the following:
kubectl apply -f https://raw.githubusercontent.com/nginx/kubernetes-ingress/v5.8.1/deploy/crds.yamlRead the steps outlined in Upgrade from 3.x to 4.x before running the CRD upgrade and perform the steps if applicable.
kubectl apply -f config/crd/bases/k8s.nginx.org_virtualservers.yaml
kubectl apply -f config/crd/bases/k8s.nginx.org_virtualserverroutes.yaml
kubectl apply -f config/crd/bases/k8s.nginx.org_transportservers.yaml
kubectl apply -f config/crd/bases/k8s.nginx.org_policies.yaml
kubectl apply -f config/crd/bases/k8s.nginx.org_globalconfigurations.yamlThese custom resources are for in-pod compilation. If you use only local policy bundles, you can skip this section. Instead, create a Persistent Volume and Persistent Volume Claim in your Kubernetes cluster for the bundle folder.
This single YAML file creates CRDs for the following resources:
APPolicyAPLogConfAPUserSig
kubectl apply -f https://raw.githubusercontent.com/nginx/kubernetes-ingress/v5.8.1/deploy/crds-nap-waf.yamlIf you are installing the CRDs this way, ensure you have first cloned the repository.
These YAML files create CRDs for the following resources:
APPolicyAPLogConfAPUserSig
kubectl apply -f config/crd/bases/appprotect.f5.com_appolicies.yaml
kubectl apply -f config/crd/bases/appprotect.f5.com_aplogconfs.yaml
kubectl apply -f config/crd/bases/appprotect.f5.com_apusersigs.yamlYou have two options for deploying NGINX Ingress Controller:
- Deployment. Choose this method for the flexibility to dynamically change the number of NGINX Ingress Controller replicas.
- DaemonSet. Choose this method if you want NGINX Ingress Controller to run on all nodes or a subset of nodes.
- StatefulSet. Choose this method when you need stable, persistent storage and ordered deployment/scaling for your NGINX Ingress Controller pods.
Before you start, update the command-line arguments for the NGINX Ingress Controller container in the relevant manifest file to meet your specific requirements.
If you use local policy bundles, you need to change the Deployment, DaemonSet, or StatefulSet file to include volumes and volume mounts.
NGINX Ingress Controller requires the volume mount path to be
/etc/nginx/waf/bundles, the bundle folder for the legacy F5 WAF for NGINX integration. The current integration uses/etc/app_protect/bundlesinstead.
Add a volumes section to deployment template spec:
...
volumes:
- name: <VOLUME_NAME>
persistentVolumeClaim:
claimName: <CLAIM_NAME>
...Replace <VOLUME_NAME> with the name of the volume and <CLAIM_NAME> with the name of the PersistentVolumeClaim.
Add volume mounts to the containers section:
...
volumeMounts:
- name: <VOLUME_MOUNT_NAME>
mountPath: /etc/nginx/waf/bundles
...Replace <VOLUME_MOUNT_NAME> with the name of the volume mount.
StatefulSet Volume Configuration: When using StatefulSet deployments, thenginx-cachevolume is automatically provided viavolumeClaimTemplatesfor persistent storage. Configure the bundle volume as a regular volume in thevolumessection. UseemptyDirfor temporary data or PersistentVolumeClaims if you need bundles to persist across pod restarts.
For additional context on managing containers using Kubernetes Deployments, refer to the official Kubernetes Deployments documentation.
When you deploy NGINX Ingress Controller as a Deployment, Kubernetes automatically sets up a single NGINX Ingress Controller pod.
-
For NGINX, run:
kubectl apply -f deployments/deployment/nginx-ingress.yaml -
For NGINX Plus, run:
kubectl apply -f deployments/deployment/nginx-plus-ingress.yamlUpdate the
nginx-plus-ingress.yamlfile to include your chosen image from the F5 Container registry or your custom container image.
For additional context on managing containers using Kubernetes DaemonSets, refer to the official Kubernetes DaemonSets documentation.
When you deploy NGINX Ingress Controller as a DaemonSet, Kubernetes creates an Ingress Controller pod on every node in the cluster.
-
For NGINX, run:
kubectl apply -f deployments/daemon-set/nginx-ingress.yaml -
For NGINX Plus, run:
kubectl apply -f deployments/daemon-set/nginx-plus-ingress.yamlUpdate the
nginx-plus-ingress.yamlfile to include your chosen image from the F5 Container registry or your custom container image.
For additional context on managing containers using Kubernetes StatefulSets, refer to the official Kubernetes StatefulSets documentation.
When you deploy NGINX Ingress Controller as a StatefulSet, Kubernetes creates pods with stable network identities and persistent storage.
-
For NGINX, run:
kubectl apply -f deployments/stateful-set/nginx-ingress.yaml -
For NGINX Plus, run:
kubectl apply -f deployments/stateful-set/nginx-plus-ingress.yamlUpdate the
nginx-plus-ingress.yamlfile to include your chosen image from the F5 Container registry or your custom container image.
StatefulSets include persistent volume claims for nginx cache storage viavolumeClaimTemplates. You may need to configure a StorageClass in your cluster or modify the volumeClaimTemplates section in the manifest to match your storage requirements. Other volumes (like those needed for App Protect modules) are configured in the regularvolumessection, not in volumeClaimTemplates.
To enable the F5 WAF for NGINX Module:
- Add the
--enable-app-protectcommand-line argument to your Deployment, DaemonSet, or StatefulSet file.
Additional WAF modules can be enabled by adding the appropriate command-line arguments:
- To enable F5 DoS for NGINX, add the
--enable-app-protect-doscommand-line argument. - To enable F5 WAF IP Intelligence, add the
--enable-app-protect-ip-intelligencecommand-line argument.
To confirm the NGINX Ingress Controller pods are operational, run:
kubectl get pods --namespace=nginx-ingressFor more information, see Configure the legacy F5 WAF for NGINX integration and the NGINX Ingress Controller with the legacy F5 WAF for NGINX integration example resources on GitHub for VirtualServer resources and for Ingress resources.
If you prefer not to build your own NGINX Ingress Controller image, you can use pre-built images. Here are your options:
- Download the image using your NGINX Ingress Controller subscription certificate and key. View the Download NGINX Ingress Controller from the F5 Registry topic.
- The Add an NGINX Ingress Controller image to your cluster topic describes how to use your subscription JWT token to get the image.