Nginx Ingress Integrator

  • Canonical IS DevOps
Channel Revision Published Runs on
latest/stable 131 10 Dec 2024
Ubuntu 20.04
latest/stable 130 10 Dec 2024
Ubuntu 20.04
latest/stable 101 28 May 2024
Ubuntu 20.04
latest/edge 133 18 Dec 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 132 18 Dec 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 109 22 Jul 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 44 16 Nov 2022
Ubuntu 22.04 Ubuntu 20.04
v2/edge 84 09 Jan 2024
Ubuntu 20.04
juju deploy nginx-ingress-integrator
Show information

Platform:

Ubuntu
22.04 20.04

charms.nginx_ingress_integrator.v0.nginx_route

Library for the nginx-route relation.

This library contains the require and provide functions for handling the nginx-route interface.

Import require_nginx_route in your charm, with four required keyword arguments:

  • charm: (the charm itself)
  • service_hostname
  • service_name
  • service_port

Other optional arguments include:

  • additional_hostnames
  • backend_protocol
  • limit_rps
  • limit_whitelist
  • max_body_size
  • owasp_modsecurity_crs
  • owasp_modsecurity_custom_rules
  • path_routes
  • retry_errors
  • rewrite_target
  • rewrite_enabled
  • service_namespace
  • session_cookie_max_age
  • tls_secret_name

See the config section for descriptions of each, along with the required type.

As an example, add the following to src/charm.py:

from charms.nginx_ingress_integrator.v0.nginx_route import NginxRouteRequirer

# In your charm's `__init__` method (assuming your app is listening on port 8080).
require_nginx_route(
    charm=self,
    service_hostname=self.app.name,
    service_name=self.app.name,
    service_port=8080
)

And then add the following to metadata.yaml:

requires:
  nginx-route:
    interface: nginx-route

You must require nginx route as part of the __init__ method rather than, for instance, a config-changed event handler, for the relation changed event to be properly handled.

In the example above we're setting service_hostname (which translates to the external hostname for the application when related to nginx-ingress-integrator) to self.app.name here. This ensures by default the charm will be available on the name of the deployed juju application, but can be overridden in a production deployment by setting service-hostname on the nginx-ingress-integrator charm. For example:

juju deploy nginx-ingress-integrator
juju deploy my-charm
juju relate nginx-ingress-integrator my-charm:nginx-route
# The service is now reachable on the ingress IP(s) of your k8s cluster at
# 'http://my-charm'.
juju config nginx-ingress-integrator service-hostname='my-charm.example.com'
# The service is now reachable on the ingress IP(s) of your k8s cluster at
# 'http://my-charm.example.com'.

class NginxRouteRequirer

This class defines the functionality for the 'requires' side of the 'nginx-route' relation.

Description

Hook events observed: - relation-changed

Methods

NginxRouteRequirer. __init__( self , charm , config , nginx_route_relation_name: str )

Init function for the NginxRouteRequires class.

Arguments

charm

The charm that requires the nginx-route relation.

config

Contains all the configuration options for nginx-route.

nginx_route_relation_name

Specifies the relation name of the relation handled by this requirer class. The relation must have the nginx-route interface.

def require_nginx_route()

Set up nginx-route relation handlers on the requirer side.

Arguments

charm

The charm that requires the nginx-route relation.

service_hostname

configure Nginx ingress integrator service-hostname option via relation.

service_name

configure Nginx ingress integrator service-name option via relation.

service_port

configure Nginx ingress integrator service-port option via relation.

additional_hostnames

configure Nginx ingress integrator additional-hostnames option via relation, optional.

backend_protocol

configure Nginx ingress integrator backend-protocol option via relation, optional.

enable_access_log

configure Nginx ingress nginx.ingress.kubernetes.io/enable-access-log option.

limit_rps

configure Nginx ingress integrator limit-rps option via relation, optional.

limit_whitelist

configure Nginx ingress integrator limit-whitelist option via relation, optional.

max_body_size

configure Nginx ingress integrator max-body-size option via relation, optional.

owasp_modsecurity_crs

configure Nginx ingress integrator owasp-modsecurity-crs option via relation, optional.

owasp_modsecurity_custom_rules

configure Nginx ingress integrator owasp-modsecurity-custom-rules option via relation, optional.

path_routes

configure Nginx ingress integrator path-routes option via relation, optional.

retry_errors

configure Nginx ingress integrator retry-errors option via relation, optional.

rewrite_target

configure Nginx ingress integrator rewrite-target option via relation, optional.

rewrite_enabled

configure Nginx ingress integrator rewrite-enabled option via relation, optional.

service_namespace

configure Nginx ingress integrator service-namespace option via relation, optional.

session_cookie_max_age

configure Nginx ingress integrator session-cookie-max-age option via relation, optional.

tls_secret_name

configure Nginx ingress integrator tls-secret-name option via relation, optional.

nginx_route_relation_name

Specifies the relation name of the relation handled by this requirer class. The relation must have the nginx-route interface.

Returns

the NginxRouteRequirer.

Description

This function must be invoked in the charm class constructor.

def provide_nginx_route(
    charm,
    on_nginx_route_available,
    on_nginx_route_broken,
    nginx_route_relation_name: str
)

Set up nginx-route relation handlers on the provider side.

Arguments

charm

The charm that requires the nginx-route relation.

on_nginx_route_available

Callback function for the nginx-route-available event.

on_nginx_route_broken

Callback function for the nginx-route-broken event.

nginx_route_relation_name

Specifies the relation name of the relation handled by this provider class. The relation must have the nginx-route interface.

Description

This function must be invoked in the charm class constructor.