Skip to main content

Stateless application using a deployment

Example of a Kubernetes Stateless Application Deployment, using Nginx

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set kubernetes-py-nginx
cd pulumi-examples/kubernetes-py-nginx

A version of the Kubernetes Stateless Application Deployment example that uses Pulumi. This example deploys a replicated NGINX server to a Kubernetes cluster, using Python and no YAML.

There is an interactive Tutorial available for this example. If this is your first time using Pulumi for Kubernetes, we recommend starting there.

Prerequisites#

  1. Install Pulumi
  2. Configure Kubernetes
  3. Install Python

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  3. Deploy the stack:

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Status
    + pulumi:pulumi:Stack kubernetes-py-nginx-dev created
    + └─ kubernetes:apps:Deployment nginx-deployment created
    Outputs:
    nginx: "nginx-deployment-ts0qpwi9"
    Resources:
    + 2 created
    Duration: 10s

    This deployment is now running, and you can run commands like kubectl get pods to see the application’s resources.

The stack’s replica count is configurable. By default, it will scale up to two instances, but you can easily change that to five, by running the pulumi config command followed by another pulumi up:

Terminal window
pulumi config set replicas 5
pulumi up

Cleaning up#

Once you’re finished experimenting, you can destroy your stack and remove it to avoid incurring any additional cost:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.