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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file charmlibs_nginx_k8s-0.0.1.post0.tar.gz.
File metadata
- Download URL: charmlibs_nginx_k8s-0.0.1.post0.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0da7e64025c45fe984f2c0cf54e4c1cf7183e5121ee3038c29d3c6512d6b45a
|
|
| MD5 |
f7b48472cabce19b38cfcb3eb26d2f49
|
|
| BLAKE2b-256 |
4107e5a5a3b73e3f29c405dd93d292c34dd6740611a01c669eb397d73d2ec4ca
|
Provenance
The following attestation bundles were made for charmlibs_nginx_k8s-0.0.1.post0.tar.gz:
Publisher:
publish.yaml on canonical/charmlibs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
charmlibs_nginx_k8s-0.0.1.post0.tar.gz -
Subject digest:
f0da7e64025c45fe984f2c0cf54e4c1cf7183e5121ee3038c29d3c6512d6b45a - Sigstore transparency entry: 618532821
- Sigstore integration time:
-
Permalink:
canonical/charmlibs@82140406529337bca76e30fc924e214ca74cb0ab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@82140406529337bca76e30fc924e214ca74cb0ab -
Trigger Event:
push
-
Statement type:
File details
Details for the file charmlibs_nginx_k8s-0.0.1.post0-py3-none-any.whl.
File metadata
- Download URL: charmlibs_nginx_k8s-0.0.1.post0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fae69f2691abbc20aaddf826ad0c42733296f698ca7cf1063bfba605566fc574
|
|
| MD5 |
dd32545d94d201b2d2e875c9d897a3ab
|
|
| BLAKE2b-256 |
5b6de0be380d8bf0b456140a1b3ab7c763200dc209f89e61b6d33af7f99dbc90
|
Provenance
The following attestation bundles were made for charmlibs_nginx_k8s-0.0.1.post0-py3-none-any.whl:
Publisher:
publish.yaml on canonical/charmlibs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
charmlibs_nginx_k8s-0.0.1.post0-py3-none-any.whl -
Subject digest:
fae69f2691abbc20aaddf826ad0c42733296f698ca7cf1063bfba605566fc574 - Sigstore transparency entry: 618532825
- Sigstore integration time:
-
Permalink:
canonical/charmlibs@82140406529337bca76e30fc924e214ca74cb0ab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@82140406529337bca76e30fc924e214ca74cb0ab -
Trigger Event:
push
-
Statement type: