Exposing a deployment with a public IP address
A minimal Go Pulumi program
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-go-exposed-deploymentcd pulumi-examples/kubernetes-go-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 exposed-deployment-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 to tell it whether you’re deploying to minikube:Terminal window pulumi config set isMinikube <value> -
Install dependencies:
Terminal window go mod download -
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 messagesDiagnostics:kubernetes:core:Service: nginxinfo: ✅ Service 'nginx-rn6uipeg' successfully created endpoint objectsinfo: ✅ Service has been allocated an IP---outputs:---frontendIp: "35.226.79.225"info: 3 changes performed:+ 3 resources createdUpdate duration: 46.555593397s -
The
nginxservice was allocated a public IP, in this case35.226.79.225, exported as the stack outputfrontendIp. Usecurlandgrepto retrieve the<title>of the site:Terminal window curl -sL $(pulumi stack output frontendIp) | grep "<title>"<title>Welcome to nginx!</title>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.
Cleaning up#
Once you’re finished experimenting, you can destroy your stack and remove it to avoid incurring any additional cost:
pulumi destroypulumi stack rmNext 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:
