Configure domain names with static IP addresses Stay organized with collections Save and categorize content based on your preferences.
This tutorial demonstrates how to use Google Kubernetes Engine (GKE) to expose yourweb application to the internet on astatic external IP addressand configure a domain name to point to your application.
This tutorial assumes you own a registered domain name, such asexample.com.
Objectives
This tutorial demonstrates the following steps:
Costs
In this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage, use thepricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, seeClean up.
Before you begin
Take the following steps to enable the Kubernetes Engine API:- Visit the Kubernetes Engine page in the Google Cloud console.
- Create or select a project.
- Wait for the API and related services to be enabled. This can take several minutes.
Verify that billing is enabled for your Google Cloud project.
Install the following command-line tools used in this tutorial:
gcloudis used to create and delete Kubernetes Engine clusters.gcloudis included in thegcloudCLI.kubectlis used to manage Kubernetes, the cluster orchestration system used by Kubernetes Engine. You can installkubectlusinggcloud:gcloud components install kubectl
Clone the sample code from GitHub:
gitclonehttps://github.com/GoogleCloudPlatform/kubernetes-engine-samplescdkubernetes-engine-samples/quickstarts/hello-app/manifestsSet defaults for thegcloud command-line tool
To save time typing yourproject IDandCompute Engine zone options in thegcloudcommand-line tool, you can set the defaults:gcloud config set projectproject-idgcloud config set compute/zonecompute-zone
Create a cluster
Create a cluster:
gcloudcontainerclusterscreate-autodomain-testDeploy your web application
The following manifest describes a Deployment that runs a sample webapplication container image:
apiVersion:apps/v1kind:Deploymentmetadata:name:helloweblabels:app:hellospec:selector:matchLabels:app:hellotier:webtemplate:metadata:labels:app:hellotier:webspec:containers:-name:hello-appimage:us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0ports:-containerPort:8080resources:requests:cpu:200mCreate the Deployment:
kubectlapply-fhelloweb-deployment.yamlExpose your application
You can expose your application on GKE using either of thefollowing methods:
Use a Service, which creates anexternal passthrough Network Load Balancerthat works with regional IP addresses.
Use an Ingress, which creates anApplication Load Balancerand supports global IP addresses.
To learn more about the advantages and disadvantages of each method,seeSetting up an external Application Load Balancer with Ingress.
Use a Service
To ensure that your application has a static external IP address, you mustreserve a static IP address.
Note: Static IP addresses have no cost when they are used by a loadbalancer. If you reserve a static IP address and don't use it, you arecharged perunused IP address pricing.If you choose to expose your application using aService,you must create a regional IP address. Global IP addresses only work withIngress resource type, as explained in the next section.
To use a Service, create a static IP address namedhelloweb-ip in theregionus-central1:
gcloud
gcloudcomputeaddressescreatehelloweb-ip--regionus-central1Find the static IP address that you created:
gcloudcomputeaddressesdescribehelloweb-ip--regionus-central1The output is similar to the following:
...address: 203.0.113.32...Config Connector
Note: This step requiresConfig Connector. Follow theinstallation instructions to install Config Connector on your cluster.
apiVersion:compute.cnrm.cloud.google.com/v1beta1kind:ComputeAddressmetadata:name:helloweb-ipspec:location:us-central1Save the manifest ascompute-address-regional.yaml.
Apply the manifest to your cluster:
kubectlapply-fcompute-address-regional.yamlFind the static IP address that you created:
kubectlgetcomputeaddresshelloweb-ip-ojsonpath='{.spec.address}'The following manifest describes aService of type LoadBalancer, whichcreates an external passthrough Network Load Balancer to expose Pods with an external IP address.
apiVersion:v1kind:Servicemetadata:name:helloweblabels:app:helloannotations:networking.gke.io/load-balancer-ip-addresses:"helloweb-ip"spec:selector:app:hellotier:webports:-port:80targetPort:8080type:LoadBalancerCreate the Service:
kubectlapply-fhelloweb-service-static-ip.yamlView the reserved IP address associated with the load balancer:
kubectlgetserviceThe output is similar to the following:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEhelloweb 10.31.254.176 203.0.113.32 80:30690/TCP 54sUse an Ingress
If you choose to expose your application using anIngress,you mustreserve a global static IP address.Use the annotationkubernetes.io/ingress.global-static-ip-name to specify a global IP address.
To expose your application to clients and services in a region, use a regional static internal IP address while deploying an internal ingress resource for GKE along with therequired annotations.
To learn how to use Ingress to expose your applications to theinternet, seeSetting up an external Application Load Balancer with Ingress.
Note: Static IP addresses have no cost when they are used by a loadbalancer. If you reserve a static IP address and don't use it, you arecharged perunused IP address pricing.To create a global static IP address namedhelloweb-ip:
gcloud
gcloudcomputeaddressescreatehelloweb-ip--globalFind the static IP address that you created:
gcloudcomputeaddressesdescribehelloweb-ip--globalThe output is similar to the following:
...address: 203.0.113.32...Config Connector
Note: This step requiresConfig Connector. Follow theinstallation instructions to install Config Connector on your cluster.
apiVersion:compute.cnrm.cloud.google.com/v1beta1kind:ComputeAddressmetadata:name:helloweb-ipspec:location:globalSave the manifest ascompute-address-global.yaml.
Apply the manifest to your cluster:
kubectlapply-fcompute-address-global.yamlThe following manifest describes an Ingress that exposes a web application ona static IP with two resources:
- A
Servicewithtype:NodePort - An
Ingressconfigured with the service name and static IP annotation
apiVersion:networking.k8s.io/v1kind:Ingressmetadata:name:hellowebannotations:kubernetes.io/ingress.global-static-ip-name:helloweb-iplabels:app:hellospec:defaultBackend:service:name:helloweb-backendport:number:8080---apiVersion:v1kind:Servicemetadata:name:helloweb-backendlabels:app:hellospec:type:NodePortselector:app:hellotier:webports:-port:8080targetPort:8080Thekubernetes.io/ingress.global-static-ip-name annotation specifies the nameof the global IP address resource to be associated with theload balancer.
Apply the manifest to your cluster:
kubectlapply-fhelloweb-ingress-static-ip.yamlView the IP address associated with the load balancer:
kubectlgetingressThe output is similar to the following
NAME HOSTS ADDRESS PORTS AGEhelloweb * 203.0.113.32 80 4mView your reserved static IP address
To verify that the load balancer is configured correctly, you can either use aweb browser to visit the IP address or usecurl:
curlhttp://203.0.113.32/The output is similar to the following:
Hello, world!Hostname: helloweb-3766687455-8lvqvConfigure your domain name records
To have browsers querying your domain name, such asexample.com, or subdomainname, such asblog.example.com, point to the static IP address you reserved,you must update the DNS (Domain Name Server) records of your domain name.
You must create anA (Address) type DNS record for your domain or subdomainname and have its value configured with the reserved IP address
DNS records of your domain are managed by your name server. Your name server mightbe the "registrar" where you registered your domain, a DNS servicesuch asCloud DNS, or another third-partyprovider.
If your nameserver is Cloud DNS: FollowCloud DNS Quickstartguide to configure DNS A record for yourdomain name with the reserved IP address of your application.
If your nameserver is another provider: Refer to your DNSproviders documentation on setting DNS A records to configure your domain name. Ifyou choose to use Cloud DNS instead, refer toMigrating to Cloud DNS.
Visit your domain name
To verify that your domain name's DNS A records resolve to the IP address youreserved, visit your domain name.
Note: It can take a few hours for DNS records to propagate. This time might dependon your name servers, local internet service provider (ISP), and many otherfactors.To make a DNS query for your domain name's A record, run thehostcommand:
hostexample.comThe output is similar to the following:
example.com has address 203.0.113.32You can now point your web browser to your domain name and visit yourwebsite.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
Delete the Service and Ingress:
kubectldeleteingress,service-lapp=helloRelease the reserved static IP. After the load balancer is deleted, theunused but reserved IP address is billed per unused IP address pricing.
If you used a Service:
gcloudcomputeaddressesdeletehelloweb-ip--regionus-central1If you used an Ingress:
gcloudcomputeaddressesdeletehelloweb-ip--global
Delete the sample application:
kubectldelete-fhelloweb-deployment.yamlDelete the cluster:
gcloudcontainerclustersdeletedomain-test
What's next
- Explore otherKubernetes Engine tutorials.
- Explore reference architectures, diagrams, and best practices about Google Cloud.Take a look at ourCloud Architecture Center.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.