Help Center/ Cloud Container Engine/ Best Practices/ DevOps/ Automatic Application Deployment Using Pulumi
Updated on 2026-09-08 GMT+08:00

Automatic Application Deployment Using Pulumi

Pulumi is an infrastructure as code (IaC) automation tool built on Terraform. It allows you to build, deploy, and manage cloud infrastructure throughout its lifecycle using popular programming languages such as Python, TypeScript, C#, and Go.

This section describes how to use Pulumi to deploy an application and shows the process using a specific example.

Preparations

  • Create a CCE cluster and ensure that an EIP has been bound to a node for downloading images and external access.
  • Prepare an ECS, bind an EIP to it, and configure kubectl to connect to the cluster. For details, see Connecting to a Cluster Using kubectl.

Installing Pulumi

  1. Log in to the ECS.
  2. Run the command below to install Pulumi. You can also visit the Pulumi official website and follow the instructions to manually install Pulumi.

    curl -fsSL https://get.pulumi.com | sh

  3. Run the following command to check whether Pulumi is successfully installed:

    pulumi version

  4. Go to the Pulumi official website and register a Pulumi account.
  5. Create a Pulumi access token.

    Log in to the Pulumi console, click the user avatar, and choose Settings. Click Access Tokens and then Create token.

  6. Set the Pulumi access token environment variable.

    export PULUMI_ACCESS_TOKEN=pul-xxxx

Using Pulumi to Deploy an Application

  1. Initialize a Pulumi project. The following uses Python as an example.

    mkdir pulumi-demo && cd pulumi-demo
    pulumi new kubernetes-python

    Enter the following information as prompted:

    • project name: project name (for example, pulumi-cce-demo)
    • description: project description
    • stack name: environment stack (The default value is dev, which is used to distinguish the development, test, and production environments.)

    After the initialization is complete, the following core file is automatically generated:

    pulumi-demo/
    ├── Pulumi.yaml       # Project metadata
    ├── Pulumi.dev.yaml   # Development environment configuration
    ├── __main__.py       # Main infrastructure code
    └── venv/             # Python virtual environment

  2. Compile the test code __main__.py to deploy an Nginx application.

    """A Kubernetes Python Pulumi program"""
    import pulumi
    from pulumi_kubernetes.apps.v1 import Deployment
    app_labels = { "app": "nginx" }
    deployment = Deployment(
        "nginx",
        spec={
            "selector": { "match_labels": app_labels },
            "replicas": 1,
            "template": {
                "metadata": { "labels": app_labels },
                "spec": { "containers": [{ "name": "nginx", "image": "nginx" }] }
            },
        })
    pulumi.export("name", deployment.metadata["name"])

  3. In the terminal, run the following command to deploy your infrastructure:

    pulumi up

    The resources to be created are displayed in the command output. Enter yes to confirm.

  4. Check whether the deployment is successful.

    kubectl get pod

    If the following information is displayed, the deployment is successful.