# Deploy a Python app

Use the `python-app` package for a Python backend that needs a Deployment,
Service, environment ConfigMap, and HTTP health probes. This guide starts with
one backend process. Frontends, workers, migrations, ingress, and data services
can be added through the same package when the application needs them.

This guide assumes the application image is already available from a container
registry and listens on a known port.

## Add the application instance

Add an instance to the application namespace and configure its backend image,
process, port, and health endpoint:

<Snippet {...pythonApplicationInstance} />

The example uses Python's built-in HTTP server so the complete configuration
stays small. Replace `backend.command` and `backend.args` with your image's
normal startup command, or omit them when the image already declares its
entrypoint.

Set `backend.port` to the container's listening port. Kix uses it for the
container port and the internal Service. The liveness and readiness probes use
the same port, while `backend.probes.path` selects the endpoint they request.

Values under `env` are written to the application's environment ConfigMap.
Use `secretEnv` for values that must be stored in a Kubernetes Secret, or
`backend.secrets` for names of externally managed Secrets.

## Check the generated resources

Evaluate the cluster before deploying it:

<Command {...check} />

Inspect the application resources that the package generates:

<Command {...workload} />

The Deployment runs the configured image and process, both probes request `/`,
and the Service forwards port 8080 to the backend. The ConfigMap contains the
ordinary environment values from the instance configuration.

## Deploy and connect

Deploy the cluster and wait for the backend to become ready:

<Command
  commands={[
  "kix deploy how-to-package-python",
  "kix status how-to-package-python",
]}
  cwd="kix-examples/"
/>

For a local check, forward the Service port and make a request from another
terminal:

<Command commands={["kix pf how-to-package-python web 8080:8080"]} cwd="kix-examples/" />

While the forward is running, open another terminal:

<Command commands={["curl http://127.0.0.1:8080/"]} />

Stop the port-forward with `Ctrl-C`.

If the deploy waits on readiness, verify that `backend.probes.path` returns a
successful HTTP response without authentication and that `backend.port`
matches the process's listening port.