Simple Hybrid ConfigurationΒΆ

This example shows how to load a YAML configuration file containing a Deployment resource and modify its values in code before serializing the results back to YAML.

import kuber
from kuber.latest import apps_v1

# Load YAML configuration file into a Deployment object
d: apps_v1.Deployment = kuber.from_yaml_file(file_path="./my-deployment.yaml")

# Add an `app` label.
d.metadata.labels.update(app="foo")

# Create a container port to map port 8080 in
# the container to port 80 on the host.
port = apps_v1.ContainerPort(container_port=8080, host_port=80)

# Modify the container named "app" with resource
# limits/requests and an additional port mapping.
with d.get_container("app") as c:
    c.resources.limits.update(cpu="1.5", memory="1Gi")
    c.resources.requests.update(cpu="1.5", memory="800Mi")
    c.ports.append(port)

# Render the results to YAML
print(d.to_yaml())

Complete code for this example is available at: kuber/examples/config-map/