Skip to main content

Nginx sidecar container abstractions for k8s charms.

Project description

nginx-k8s

nginx-k8s provides abstractions for Juju Charms to run a sidecar Nginx container and a corresponding Prometheus exporter. The supported Nginx configuration is not meant to fully cover all Nginx features, but a minimal subset sufficient to cover our immediate use cases.

To install, add charmlibs-nginx-k8s to your requirements. Then in your Python code, import as:

from charmlibs import nginx_k8s

Check out the reference docs on the charmlibs docsite.

Getting started

To get started, you can add two sidecar containers to your charm's charmcraft.yaml and in charm.py, instantiate the Nginx and NginxPrometheusExporter classes in your initializer and call their .reconcile() methods whenever you wish to synchronize the configuration files.

import ops

from charmlibs import nginx_k8s


class MyCharm(ops.CharmBase):
    def __init__(self, framework: ops.Framework):
        super().__init__(framework)
        self._nginx = nginx_k8s.Nginx(
            self.unit.get_container("nginx"),  # container name as defined in charmcraft.yaml
            nginx_config=nginx_k8s.NginxConfig(
                server_name="foo",
                upstream_configs=[
                    nginx_k8s.NginxUpstream(name="foo", port=4040, group="backend"),
                    nginx_k8s.NginxUpstream(name="bar", port=4041, group="frontend"),
                ],
                server_ports_to_locations={8080: [
                    nginx_k8s.NginxLocationConfig(
                        path="/", 
                        backend="foo", 
                        backend_url="/api/v1", 
                        headers={"a": "b"},
                        modifier="=",
                        is_grpc=True, 
                        upstream_tls=True
                    ),
                ]}
            )
        )
        self._nginx_pexp = nginx_k8s.NginxPrometheusExporter(
            self.unit.get_container('nginx-pexp-container')
        )

        self.framework.observe(self.on.nginx_container_pebble_ready, self._on_reconcile)
        self.framework.observe(self.on.nginx_pexp_container_pebble_ready, self._on_reconcile)

    def _on_reconcile(self, _):
        self._nginx.reconcile(
            upstreams_to_addresses={
                "foo": {"http://example.com"},
                "bar": {"http://example.io"},
            }
        )
        self._nginx_pexp.reconcile()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

charmlibs_nginx_k8s-0.1.1.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

charmlibs_nginx_k8s-0.1.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file charmlibs_nginx_k8s-0.1.1.tar.gz.

File metadata

  • Download URL: charmlibs_nginx_k8s-0.1.1.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for charmlibs_nginx_k8s-0.1.1.tar.gz
Algorithm Hash digest
SHA256 97e489f1043915dae36bfc88065d3e8b3b206f50305ebf2931a8ae9638cba2c8
MD5 f24c45cb40ab59a4e996e96c2bb5e1be
BLAKE2b-256 27f2e1c6e8a6e5ccda2ee2b735dc2c7879cffbd707c13fbe65d936eb7ac21010

See more details on using hashes here.

Provenance

The following attestation bundles were made for charmlibs_nginx_k8s-0.1.1.tar.gz:

Publisher: publish.yaml on canonical/charmlibs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file charmlibs_nginx_k8s-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for charmlibs_nginx_k8s-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5513adfad98ea6d91bfe72b5ee5c5701f9c4515eb3e8af3ced4ce77f60668a4c
MD5 02b0b97bc9eeb3bb6764e9bb43fcd234
BLAKE2b-256 c2b8fd1d0fcb6eacda7ceabc5c24c8019fbc0ec1f8d048aaf0d9858f47040699

See more details on using hashes here.

Provenance

The following attestation bundles were made for charmlibs_nginx_k8s-0.1.1-py3-none-any.whl:

Publisher: publish.yaml on canonical/charmlibs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page