How to expose services in kubernetes to a single internal loadbalancer in GCP/GKE

11/15/2018

I have create a 2 services in Kubernetes with 2 internal loadbalancer in GCP. Things are working fine.

How can I point the 2 services to the same loadbalancer?

I have used the below yml file, the service is not working.

apiVersion: v1
kind: Service
metadata:
  name: sample-app
  labels:
    name: sample-app
    app: sample-app
spec:
  ports:
  - name: sampleapp
    protocol: TCP
    port: 8080
    targetPort: 8080
  selector:
    name: sample-app
    app: sample-app
  type: "LoadBalancer"
  loadBalancerIP: XX.XX.XX.XX

The loadBalancerIP, expects the actual loadbalancer IP.

Error creating load balancer (will retry): failed to ensure load balancer for service default/sampleapp: requested ip "XX.XX.XX.XX" is neither static nor assigned to the LB

-- Sunil Gajula
google-cloud-platform
google-kubernetes-engine
kubernetes

1 Answer

11/21/2018

I was able to create the NGINX ingress controller by Kubernetes using the below blogs.

http://rahmonov.me/posts/nginx-ingress-controller/? https://imti.co/web-cluster-ingress/

And created an Ingress to point to my endpoints.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
  ingress.kubernetes.io/rewrite-target: /
  name: cobalt-app
  namespace: default
  spec:
    rules:
    - http:
      paths:
    - backend:
      serviceName: sampleapp
      servicePort: 8080
      path: /greeting
   - backend:
      serviceName: echoserver
      servicePort: 8080
    path: /echo
-- Sunil Gajula
Source: StackOverflow