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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set kubernetes-ts-nginxcd pulumi-examples/kubernetes-ts-nginxA version of the Kubernetes Stateless Application Deployment example that uses Pulumi. This example deploys a replicated Nginx server to a Kubernetes cluster, using TypeScript 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.
Pre-Requisites#
Running the App#
After cloning this repo, cd into this directory and install dependencies:
npm installAfterwards, create a new stack, a logical deployment target that we’ll deploy into:
pulumi stack initEnter a stack name: k8s-nginx-devNow to perform the deployment, simply run pulumi up. It will first show you a preview of what will take place.
After confirming, the deployment will take place in approximately 20 seconds:
pulumi upUpdating stack 'k8s-nginx-dev'Performing changes:
Type Name Status Info + pulumi:pulumi:Stack k8s-nginx-k8s-nginx-dev created + └─ kubernetes:apps:Deployment nginx created
info: 2 changes performed: + 2 resources createdUpdate duration: 18.291517072sThis 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 three instances, but we can easily change
that to five, by running the pulumi config command followed by another pulumi up:
pulumi config set replicas 5pulumi upUpdating stack 'k8s-nginx-dev'Performing changes:
Type Name Status Info * pulumi:pulumi:Stack k8s-nginx-k8s-nginx-dev done ~ └─ kubernetes:apps:Deployment nginx updated changes: ~ spec
info: 1 change performed: ~ 1 resource updated 1 resource unchangedUpdate duration: 4.324849549sAfter we’re done, we can tear down all resources, including removing our stack, with a couple commands:
pulumi destroy --yespulumi stack rm --yes