Creating a Kubernetes Ingress Resource with a Static IP Address on GCP or GKE
Static IPs for Cloud-Native Applications like XtremeCloud Applications
Introduction
This tutorial will walk you through creating a NGINX deployment and expose it using a Kubernetes Ingress Resource associated with a static IP address on GKE. The use cases for doing this are:
-
We are exposing you to the same technique we use to deploy and manage our cloud-native XtremeCloud SSO and XtremeCloud Data Grid-web applications.
-
You want to configure DNS before exposing your application to the outside world.
Note: This tutorial only works on GCP or GKE. We also have a similar tutorial for Microsoft Azure/AKS.
The Basics
As you will see in the XtremeCloud Single Sign-On (SSO) Quick Start Guide, these types of manual steps are not necessary since you will be using Eupraxia Labs Helm Charts. This will make it it easier to rapidly deploy XtremeCloud SSO and promote it to other environments. We take the same approach with XtremeCloud Data Grid-web.
Set the kubernetes.io/ingress.global-static-ip-name annotation on the Ingress configuration to the name of a Google Cloud Platform (GCP) global IP address as created with the gcloud compute addresses create command.
Example:
Check your version of gcloud on your workstation/controller:
[centos@vm-controller ~]$ gcloud version
Google Cloud SDK 252.0.0
alpha 2019.06.21
beta 2019.06.21
bq 2.0.43
core 2019.06.21
gsutil 4.39
kubectl 2019.06.21
Create a global IP address:
gcloud compute addresses create xcsso-staging-ip --global
Set the kubernetes.io/ingress.global-static-ip-name
annotation on the Ingress configuration:
kind: Ingress
metadata:
name: nginx
annotations:
kubernetes.io/ingress.global-static-ip-name: "xcsso-staging-ip"
spec:
backend:
serviceName: nginx
servicePort: 80
Reminder: The kubernetes.io/ingress.global-static-ip-name only works on GCP or GKE.
Try this Tutorial
Create a global IP address named xcsso-staging-ip:
gcloud compute addresses create xcsso-staging-ip --global
Create the nginx
deployment:
kubectl run nginx --image nginx:1.11 --port 80 --replicas=3
Expose the nginx
deployment using a NodePort service:
kubectl expose deployment nginx --type NodePort
The service must be type NodePort to ensure the Ingress can perform health checks on the Pod.
Create the nginx
ingress resource. Save the nginx
ingress config to a file named nginx-ingress.yaml
:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.global-static-ip-name: xcsso-staging-ip
name: nginx
spec:
backend:
name: nginx
port: 80
cat > nginx-ingress.yaml << EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx
annotations:
kubernetes.io/ingress.global-static-ip-name: "xcsso-staging-ip"
spec:
backend:
name: nginx
port: 80
EOF
Create the nginx
ingress resource:
kubectl create -f nginx-ingress.yaml
After about one (1) minute or so, the nginx
ingress resource will be ready for use and associated with the xcsso-staging-ip
global IP address created earlier. View the details of the nginx
ingress resource:
kubectl get ing nginx
NAME HOSTS ADDRESS PORTS AGE
nginx * 130.210.105.XXX 80 55s
The nginx
ingress address will match the xcsso-staging-ip
global IP address. Get the kubernetes-ingress
IP address and compare it with the nginx
ingress IP:
gcloud compute addresses \
describe xcsso-staging-ip --global \
--format='value(address)'
130.210.105.XXX
At this point you will be able to hit one of the nginx
Pods via the xcsso-staging-ip
IP address. Store the xcsso-staging-ip
IP address in an environment variable:
export INGRESS_IP_ADDRESS=$(gcloud compute addresses \
describe xcsso-staging-ip --global \
--format='value(address)')
Visit the http://${INGRESS_IP_ADDRESS}
url:
curl http://${INGRESS_IP_ADDRESS}
HTTP Response:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>