I am trying to host a wordpress website on GKE and then create a ELB with a pre-existing static IP to expose wordpress. I did the following things:
Contents of my yaml:
kind: Service
metadata:
labels:
app: wordpress
name: wordpress
spec:
type: LoadBalancer
loadBalancerIP: "x.x.x.x"
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: wordpres
When I run the following command - kubectl get svc -l app=wordpress --watch
, I get:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer x.x.x.x <pending> 80:32590/TCP 6m7s
Any clues why this is not working and giving me the external ip address?
Your service spec looks wrong. The spec.loadBalancerIP
field should specify the "external" IP that you want assigned to the LB front end (note that external here means external to the cluster, this IP should belong to your VPC or be a public IP).
In your case, the IP you assigned (192.168.0.1
) is actually your clusterIP (which makes sense due to how Google assigns IPs in VPCs, that IP would normally be assigned to a gateway). Whatever your static IP is (let's say 35.35.35.35
), that should be specified in the proper field as spec.loadBalancerIP: 35.35.35.35
. The 192.168.0.1
would be defined in the spec.clusterIP
field if that was necessary at all.
When we expose a Service, it creates a TCP Network Load Balancer that works with Regional IP addresses only. Global IP addresses only work with Ingress resource type. I would recommend you using a Regional static IP address, instead of Global. Here is the link that gives a brief description of Load Balancers in GCP:1 I tried replicating this scenario on my end, and it worked for me with a Regional IP address immediately and did not work the Global IP address at all.