Configure domain names with static IP addresses

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.

Note: This tutorial uses the built-inGKE Ingress Controllerand does not apply to theNGINX Ingress Controller.

Objectives

This tutorial demonstrates the following steps:

  • Reserve a static external IP address for your application
  • Configure eitherService orIngress resources to use thestatic IP address
  • Update DNS records of your domain name to point to your application

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.

New Google Cloud users might be eligible for afree trial.

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:
  1. Visit the Kubernetes Engine page in the Google Cloud console.
  2. Create or select a project.
  3. Wait for the API and related services to be enabled. This can take several minutes.
  4. Verify that billing is enabled for your Google Cloud project.

Install the following command-line tools used in this tutorial:

  • gcloud is used to create and delete Kubernetes Engine clusters.gcloud is included in thegcloud CLI.
  • kubectl is used to manage Kubernetes, the cluster orchestration system used by Kubernetes Engine. You can installkubectl usinggcloud:
    gcloud components install kubectl

Clone the sample code from GitHub:

gitclonehttps://github.com/GoogleCloudPlatform/kubernetes-engine-samplescdkubernetes-engine-samples/quickstarts/hello-app/manifests

Set 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-test

Deploy 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:200m

Create the Deployment:

kubectlapply-fhelloweb-deployment.yaml

Expose your application

You can expose your application on GKE using either of thefollowing methods:

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-central1

Find the static IP address that you created:

gcloudcomputeaddressesdescribehelloweb-ip--regionus-central1

The 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-central1

Save the manifest ascompute-address-regional.yaml.

Apply the manifest to your cluster:

kubectlapply-fcompute-address-regional.yaml

Find 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:LoadBalancer

Create the Service:

kubectlapply-fhelloweb-service-static-ip.yaml

View the reserved IP address associated with the load balancer:

kubectlgetservice

The 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     54s
Note: Provisioning and configuring the load balancer might take a few minutes.

Use 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--global

Find the static IP address that you created:

gcloudcomputeaddressesdescribehelloweb-ip--global

The 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:global

Save the manifest ascompute-address-global.yaml.

Apply the manifest to your cluster:

kubectlapply-fcompute-address-global.yaml

The following manifest describes an Ingress that exposes a web application ona static IP with two resources:

  • AService withtype:NodePort
  • AnIngress configured 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:8080

Thekubernetes.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.yaml

View the IP address associated with the load balancer:

kubectlgetingress

The output is similar to the following

NAME       HOSTS     ADDRESS          PORTS     AGEhelloweb   *         203.0.113.32     80        4m
Note: Provisioning and configuring the load balancer might take a fewminutes.

View 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-8lvqv
Note: You might get HTTP 404 and HTTP 500 errors for a few minutes if you used an Ingress to configure a load balancer. It takes time for configurationchanges to propagate to regions across the globe.

Configure 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.com

The output is similar to the following:

example.com has address 203.0.113.32

You 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.

  1. Delete the Service and Ingress:

    kubectldeleteingress,service-lapp=hello
  2. Release the reserved static IP. After the load balancer is deleted, theunused but reserved IP address is billed per unused IP address pricing.

  3. Delete the sample application:

    kubectldelete-fhelloweb-deployment.yaml
  4. Delete the cluster:

    gcloudcontainerclustersdeletedomain-test

What's next

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.