codeaprendiz.github.io

DevOps Essentials

View on GitHub

Configuring Domain Names with Static IP Addresses

configuring-domain-name-static-ip

This tutorial demonstrates the following steps:

Step 0:

GKE Cluster created us-central1-c

Step 1:

Deploy your web application

$ kubectl apply -f helloweb-deployment.yaml
deployment.apps/helloweb created

Step 2:

Expose your application

Use a Service

$ gcloud compute addresses create helloweb-ip --region us-central1
Created [https://www.googleapis.com/compute/v1/projects/gcloud-262311/regions/us-central1/addresses/helloweb-ip].
$ gcloud compute addresses describe helloweb-ip --region us-central1
address: 34.67.51.160
addressType: EXTERNAL
creationTimestamp: '2020-04-13T15:17:53.083-07:00'
description: ''
id: '1347105937512029182'
kind: compute#address
name: helloweb-ip
networkTier: PREMIUM
region: https://www.googleapis.com/compute/v1/projects/gcloud-262311/regions/us-central1
selfLink: https://www.googleapis.com/compute/v1/projects/gcloud-262311/regions/us-central1/addresses/helloweb-ip
status: RESERVED
$ kubectl apply -f helloweb-service.yaml
service/helloweb created
$ kubectl get service
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
helloweb     LoadBalancer   10.127.11.151   <pending>     80:30354/TCP   36s
kubernetes   ClusterIP      10.127.0.1      <none>        443/TCP        73m

$ kubectl get service
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)        AGE
helloweb     LoadBalancer   10.127.11.151   34.67.51.160   80:30354/TCP   99s
kubernetes   ClusterIP      10.127.0.1      <none>         443/TCP        74m

Step 3:

Visit your reserved static IP address

$ curl http://34.67.51.160           
Hello, world!
Version: 1.0.0
Hostname: helloweb-7f7f7474fc-ghncd

Step 4:

Configure your domain name records

$ nslookup testservicek8s.gotdns.ch                       
Server:         192.168.1.1
Address:        192.168.1.1#53

Non-authoritative answer:
Name:   testservicek8s.gotdns.ch
Address: 34.67.51.160

Step 5:

Visit the domain

$ curl http://testservicek8s.gotdns.ch                       
Hello, world!
Version: 1.0.0
Hostname: helloweb-7f7f7474fc-ghncd

Cleaning up

$ kubectl delete ingress,service -l app=hello
service "helloweb" deleted
$ gcloud compute addresses delete helloweb-ip --region us-central1
The following addresses will be deleted:
 - [helloweb-ip] in [us-central1]

Do you want to continue (Y/n)?  Y

Deleted [https://www.googleapis.com/compute/v1/projects/gcloud-262311/regions/us-central1/addresses/helloweb-ip].
$ kubectl delete -f helloweb-deployment.yaml
deployment.apps "helloweb" deleted