Skip to main content

Kubernetes MERN Stack 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-mern-voting-app
cd pulumi-examples/aws-ts-k8s-mern-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 Pulumi for AWS
  3. Configure Pulumi for Python
  4. Install Docker

Deploying and running the program#

  1. Create a new stack:

    Terminal window
    pulumi stack init aws-ts-k8s-mern-voting-app
  2. Set the AWS region and the usernames and passwords for a set of accounts the project uses:

    Terminal window
    pulumi config set aws:region us-west-2
    pulumi config set sqlUserName <NAME>
    pulumi config set sqlUserPassword <PASSWORD> --secret
  3. Restore NPM modules via npm install or yarn install.

  4. Run pulumi up -y to deploy changes:

    Terminal window
    Updating (aws-ts-k8s-mern-voting-app):
    Type Name Status Info
    + pulumi:pulumi:Stack voting-app-aws-ts-k8s-mern-voting-app created
    + ├─ eks:index:Cluster eksCluster created
    + ├─ eks:index:ServiceRole eksCluster-eksRole created
    + ├─ aws:iam:Role eksCluster-eksRole-role created
    + ├─ aws:iam:RolePolicyAttachment eksCluster-eksRole-90eb1c99 created
    + └─ aws:iam:RolePolicyAttachment eksCluster-eksRole-4b490823 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:iam:InstanceProfile eksCluster-instanceProfile created
    + ├─ aws:ec2:SecurityGroupRule eksCluster-eksClusterInternetEgressRule created
    + ├─ aws:eks:Cluster eksCluster-eksCluster created
    + ├─ aws:ec2:SecurityGroup eksCluster-nodeSecurityGroup created
    + ├─ pulumi-nodejs:dynamic:Resource eksCluster-vpc-cni created
    + ├─ pulumi:providers:kubernetes eksCluster-eks-k8s created
    + ├─ kubernetes:core:ConfigMap eksCluster-nodeAccess created
    + ├─ aws:ec2:SecurityGroupRule eksCluster-eksClusterIngressRule created
    + ├─ aws:ec2:SecurityGroupRule eksCluster-eksExtApiServerClusterIngressRule created
    + ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeIngressRule created
    + ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeInternetEgressRule created
    + ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeClusterIngressRule created
    + ├─ aws:ec2:LaunchConfiguration eksCluster-nodeLaunchConfiguration created
    + ├─ aws:cloudformation:Stack eksCluster-nodes created
    + └─ pulumi:providers:kubernetes eksCluster-provider 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
    + ├─ 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 : "ab89804d273d8484cb9e64c93975f4ad-1303584037.us-west-2.elb.amazonaws.com"
    kubeConfig: {...}
    Resources:
    + 44 created
    Duration: 18m10s
  5. Verify that the ECS instance exists by connecting to it on port 3000 in a browser window.

Clean up#

To clean up resources, run pulumi destroy and answer the confirmation question at the prompt.

Related

The infrastructure as code platform for any cloud.