Reputation: 2920
I have allocated a static IP on my GCP account. Then, I updated my application's service definition to use this in a load balancer, like so:
kind: Service
apiVersion: v1
metadata:
# Unique key of the Service instance
name: my-app-service
spec:
ports:
# Accept traffic sent to port 80
- name: http
port: 80
targetPort: 5000
selector:
# Loadbalance traffic across Pods matching
# this label selector
app: web
# Create an HA proxy in the cloud provider
# with an External IP address - *Only supported
# by some cloud providers*
type: LoadBalancer
# Use the static IP allocated
loadBalancerIP: 35.186.xxx.xxx
If I comment out the last line and let GKE allocate an ephemeral public IP, the service comes up just fine. Any ideas what I am doing wrong?
Based on advise in an answer, I created an Ingress
as follows:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: myapp
annotations:
kubernetes.io/ingress.global-static-ip-name: "myapp"
spec:
backend:
serviceName: my-app-service
servicePort: 80
Now, I see the Ingress
getting assigned the right static IP. However, my Service
also gets assigned a (different) public IP. The Ingress
and Service
are not connected. If I comment out the type: LoadBalancer
line, the Service
is not assigned a public IP, but Ingress
still does not connect. I get a default backend - 404
response when hitting the static IP. I have tried creating the service and ingress in different orders and that has not helped either.
If I leave this up long enough, the static IP routes traffic to my service, but the service itself stays stuck in external IP assignment:
$ kubectl get service my-app-service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-app-service 10.x.x.x <pending> 80:31432/TCP 12m
Upvotes: 1
Views: 1789
Reputation: 45312
You need to create an Ingress
and use the kubernetes.io/ingress.global-static-ip-name: "name-of-your-ip"
annotation on the Ingress for Kubernetes to be able to find it.
You can find a tutorial here: https://github.com/kelseyhightower/ingress-with-static-ip#tutorial
Upvotes: 1