I am new at google kubernetes engine. So I am createing a new cluster. And deploying a sample application on this cluster. And I can access it using an ip address like 30.31.32.33/api
So I want to use my domain name (mydomain.com or subdomain products.mydomain.com
) for this app
30.31.32.33/api
. Dose this ip address change if recreate the cluster?You'll want to use a static IP in order to ensure that the IP does not change. There is a good tutorial on this here.
The high level steps:
Reserve a global static external IP address
gcloud compute addresses create $ADDRESS_NAME \
--global \
--ip-version IPV4
Create the DNS A record mapping your FQDN to that IP address
Use the kubernetes.io/ingress.global-static-ip-name
annotation in your Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp
annotations:
kubernetes.io/ingress.global-static-ip-name: $ADDRESS_NAME
labels:
app: myapp
spec:
rules:
- host: "products.mydomain.com"
http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: products-service
port:
number: 8080
If you want to publish more apps, if they are in separate namespace then just repeat steps 1-3 above for each app. If you deploy all of the apps in the same namespace, then you can create additional DNS A records for each app and point them to the same IP created in step 1 and then modify the Ingress in step 3 above:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp
annotations:
kubernetes.io/ingress.global-static-ip-name: $ADDRESS_NAME
labels:
app: myapp
spec:
rules:
- host: "products.mydomain.com"
http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: products-service
port:
number: 8080
- host: "app2.mydomain.com"
http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: app2-service
port:
number: 8080