Exposing a deployment with a public IP address
A simple Deployment running nginx, exposed to the Internet with a Service
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-exposed-deploymentcd pulumi-examples/kubernetes-ts-exposed-deploymentDeploys nginx to a Kubernetes cluster, and publicly exposes it to the Internet with an IP address,
using a Kubernetes Service.
In the gif below we see the experience of deploying this example with pulumi up. Notice that
Pulumi has an inherent notion of “done-ness” — Pulumi waits for the IP address to be allocated to
the Service. Because this example uses the Pulumi concept of stack exports to report this IP
address, in this example we are also able to use curl to reach the nginx server.

Prerequisites#
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
This example will attempt to expose the
nginxdeployment to the Internet with aServiceof typeLoadBalancer. Since minikube does not supportLoadBalancer, the application already knows to use typeClusterIPinstead; all you need to do is tell it whether you’re deploying to minikube:Terminal window pulumi config set isMinikube <value> -
Install dependencies:
Terminal window npm install -
Deploy the stack:
Terminal window pulumi upUpdating stack 'exposed-deployment-dev'Performing changes:Type Name Status Info+ pulumi:pulumi:Stack exposed-deployment-exposed-deployment-dev created 1 warning+ ├─ kubernetes:apps:Deployment nginx created+ └─ kubernetes:core:Service nginx created 2 info messages---outputs:---frontendIp: "35.226.79.225"info: 3 changes performed:+ 3 resources createdUpdate duration: 46.555593397s -
We can see here in the
---outputs:---section thatnginxwas allocated a public IP, in this case35.226.79.225. It is exported with a stack output variable,frontendIp. Usecurlandgrepto retrieve the<title>of the site the proxy points at:Note: minikube does not support type
LoadBalancer; if you are deploying to minikube, make sure to runkubectl port-forward svc/frontend 8080:80to forward the cluster port to the local machine and access the service vialocalhost:8080.Terminal window curl -sL $(pulumi stack output frontendIp) | grep "<title>"<title>Welcome to nginx!</title>
Next steps#
Now that nginx is deployed and exposed to the Internet with an IP, try playing around with the
example!
If we change the nginx image to nginx:1.16-alpine, we can run pulumi preview --diff and see
this change reported to us:

Notice also that if you provide an image that does not exist, Pulumi will report errors as it sees them. You should see something similar in principle to this:

Cleaning up#
Once you’re finished experimenting, you can destroy your stack and remove it to avoid incurring any additional cost:
pulumi destroypulumi stack rm