Skip to main content

Kubernetes voting app

Voting app that uses containers

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 aws-ts-k8s-voting-app
cd pulumi-examples/aws-ts-k8s-voting-app

A simple voting app that uses Kubernetes.

The example shows how easy it is to deploy a containerized application to Amazon EKS. Pulumi does the following:

  • Builds the Docker images
  • Provisions AWS Container Registry (ECR) instance
  • Pushes the images to the ECR instance
  • Provisions AWS EKS cluster
  • Uses the images to create Kubernetes deployments

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js
  4. Install Docker

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Set the AWS region and the usernames and passwords for the admin and application database users:

    Terminal window
    pulumi config set aws:region us-west-2
    pulumi config set sql-admin-name <NAME>
    pulumi config set sql-admin-password <PASSWORD> --secret
    pulumi config set sql-user-name <NAME>
    pulumi config set sql-user-password <PASSWORD> --secret
  3. Install dependencies:

    Terminal window
    npm install
  4. Deploy the stack:

    Terminal window
    pulumi up
    Updating (aws-ts-k8s-voting-app):
    Type Name Status
    + pulumi:pulumi:Stack voting-app-aws-ts-k8s-voting-app created
    + ├─ awsx:ecr:Repository server-side-service created
    + │ ├─ aws:ecr:Repository server-side-service created
    + │ └─ aws:ecr:LifecyclePolicy server-side-service created
    + ├─ awsx:ecr:Repository client-side-service created
    + │ ├─ aws:ecr:Repository client-side-service created
    + │ └─ aws:ecr:LifecyclePolicy client-side-service created
    + ├─ eks:index:Cluster eksCluster created
    + │ ├─ eks:index:ServiceRole eksCluster-eksRole created
    + │ │ ├─ aws:iam:Role eksCluster-eksRole-role created
    + │ │ ├─ aws:iam:RolePolicyAttachment eksCluster-eksRole-4b490823 created
    + │ │ └─ aws:iam:RolePolicyAttachment eksCluster-eksRole-90eb1c99 created
    + │ ├─ eks:index:ServiceRole eksCluster-instanceRole created
    + │ │ ├─ aws:iam:Role eksCluster-instanceRole-role created
    + │ │ ├─ aws:iam:RolePolicyAttachment eksCluster-instanceRole-e1b295bd created
    + │ │ ├─ aws:iam:RolePolicyAttachment eksCluster-instanceRole-3eb088f2 created
    + │ │ └─ aws:iam:RolePolicyAttachment eksCluster-instanceRole-03516f97 created
    + │ ├─ pulumi-nodejs:dynamic:Resource eksCluster-cfnStackName created
    + │ ├─ aws:ec2:SecurityGroup eksCluster-eksClusterSecurityGroup created
    + │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksClusterInternetEgressRule created
    + │ ├─ aws:eks:Cluster eksCluster-eksCluster created
    + │ ├─ aws:iam:InstanceProfile eksCluster-instanceProfile created
    + │ ├─ aws:ec2:SecurityGroup eksCluster-nodeSecurityGroup created
    + │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeClusterIngressRule created
    + │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeIngressRule created
    + │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeInternetEgressRule created
    + │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksClusterIngressRule created
    + │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksExtApiServerClusterIngressRule created
    + │ ├─ aws:ec2:LaunchConfiguration eksCluster-nodeLaunchConfiguration created
    + │ ├─ pulumi:providers:kubernetes eksCluster-eks-k8s created
    + │ ├─ pulumi-nodejs:dynamic:Resource eksCluster-vpc-cni created
    + │ ├─ kubernetes:core:ConfigMap eksCluster-nodeAccess created
    + │ ├─ aws:cloudformation:Stack eksCluster-nodes created
    + │ └─ pulumi:providers:kubernetes eksCluster-provider created
    + ├─ awsx:ecr:Repository database-side-service created
    + │ ├─ aws:ecr:Repository database-side-service created
    + │ └─ aws:ecr:LifecyclePolicy database-side-service created
    + ├─ aws:ebs:Volume storage-volume created
    + ├─ kubernetes:apps:Deployment database-side-service created
    + ├─ kubernetes:core:Service database-side-listener created
    + ├─ kubernetes:apps:Deployment server-side-service created
    + ├─ kubernetes:core:Service server-side-listener created
    + ├─ kubernetes:apps:Deployment client-side-service created
    + └─ kubernetes:core:Service client-side-listener created
    Outputs:
    URL : "ab368f798ca564be295df514dfbc7a0e-519435073.us-west-2.elb.amazonaws.com"
    kubeConfig: {...}
    Resources:
    + 44 created
    Duration: 15m45s
  5. Verify that the ECS instance exists by connecting to it on port 3000 in a browser window.

Cleaning up#

Once you’re finished, destroy the resources and remove the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.